Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vulnerable_xxe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import xml.etree.ElementTree as ET
from flask import Flask, request
from lxml import etree
import defusedxml.lxml as defused_lxml
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix uses deprecated module marked for removal

Medium Severity

The defusedxml.lxml module is officially deprecated by its maintainer and marked for removal in a future release. Importing it emits a DeprecationWarning at runtime. The maintainer notes it was only "example code" and explicitly states it has "NO protection against decompression bombs." Since lxml itself now includes built-in mitigations (disabled network access, billion-laughs protection), the recommended approach is to configure etree.XMLParser directly with safe settings like resolve_entities=False and no_network=True.

Additional Locations (1)
Fix in Cursor Fix in Web

import xml.sax

app = Flask(__name__)
Expand All @@ -17,8 +18,7 @@ def parse_xml():
def process_xml():
xml_content = request.data.decode()

parser = etree.XMLParser()
doc = etree.fromstring(xml_content.encode(), parser)
doc = defused_lxml.fromstring(xml_content.encode())

return etree.tostring(doc).decode()

Expand Down
Loading