Skip to content

[Security] Fix CodeQL alert #27: XML external entity expansion#85

Open
colin-d-fried wants to merge 1 commit into
mainfrom
security/codeql-27-xxe-fix
Open

[Security] Fix CodeQL alert #27: XML external entity expansion#85
colin-d-fried wants to merge 1 commit into
mainfrom
security/codeql-27-xxe-fix

Conversation

@colin-d-fried
Copy link
Copy Markdown
Owner

@colin-d-fried colin-d-fried commented Mar 26, 2026

Summary

Fixes CodeQL alert #27: XML external entity expansion

Field Value
Severity critical
File vulnerable_xxe.py
CWE CWE-611
Alert CodeQL Alert #27

Fix Applied

See the diff for the specific secure coding change applied.

Fixes #29


Open with Devin

Note

Medium Risk
Changes XML parsing for the /process_xml endpoint to use defusedxml, 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_xml handler from lxml.etree.XMLParser + etree.fromstring to defusedxml.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.

Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread vulnerable_xxe.py
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CodeQL #27] XML external entity expansion

1 participant