[Security] Fix CodeQL alert #27: XML external entity expansion#85
[Security] Fix CodeQL alert #27: XML external entity expansion#85colin-d-fried wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| import xml.etree.ElementTree as ET | ||
| from flask import Flask, request | ||
| from lxml import etree | ||
| import defusedxml.lxml as defused_lxml |
There was a problem hiding this comment.
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.


Summary
Fixes CodeQL alert #27: XML external entity expansion
vulnerable_xxe.pyFix Applied
See the diff for the specific secure coding change applied.
Fixes #29
Note
Medium Risk
Changes XML parsing for the
/process_xmlendpoint to usedefusedxml, which may reject previously accepted XML (e.g., DTD/entity usage) but reduces XXE risk in a request-handling path.Overview
Mitigates the CodeQL XXE finding by switching the
/process_xmlhandler fromlxml.etree.XMLParser+etree.fromstringtodefusedxml.lxml.fromstring, and adds the corresponding import.This makes XML parsing safer by default and may change behavior for inputs that rely on external entities/DTDs.
Written by Cursor Bugbot for commit e99d156. This will update automatically on new commits. Configure here.