harden: disable external XML entity processing in formatxml.py... - #720
harden: disable external XML entity processing in formatxml.py...#720anupamme wants to merge 2 commits into
Conversation
…B408.B409.B410 security vulnerability Automated security fix generated by OrbisAI Security
|
I have look a bit at the status of See the discussion of the removal here: It is mainly because the library last updated was in 2021 and modern Python XML stdlib (since Python 3.11) already handle XML security issues of concerns. spdx-online-tools has recently up the floor for Python to 3.12, so I think it is not necessary to introduce to new dependency. |
defusedxml adds no protection here: the project targets Python 3.12, whose bundled expat (>=2.4.0) enables billion-laughs / entity-expansion protection by default, and xml.etree.ElementTree does not resolve external entities (no XXE). defusedxml was deprecated / unrecommended by the Python docs in Jan 2026 and is unmaintained (last release 2021). Revert the formatxml.py import to the stdlib with a justification comment and inline nosec annotations (B405/B314), and remove defusedxml from requirements. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Good catch. I've reverted the defusedxml change (see 43386a4). Introducing it isn't warranted here:
So the change was a no-op for security while adding an unmaintained dependency. I've reverted to |
Summary
Harden input handling in
src/app/formatxml.py(flagged by semgrep).Vulnerability
gitlab.bandit.B313.B314.B315.B316.B318.B319.B320.B405.B406.B407.B408.B409.B410src/app/formatxml.py:87Description: Found use of the native Python XML libraries, which is vulnerable to XML external entity (XXE)
attacks. The Python documentation recommends the 'defusedxml' library instead. Use 'defusedxml'.
See https://github.com/tiran/defusedxml for more information.
Threat Model Context
This is a web service - vulnerabilities in request handlers are directly exploitable by remote attackers.
Changes
src/app/formatxml.pyrequirements.txtBehavior Preservation
The change is scoped to 2 files on the vulnerable path; it only tightens handling of untrusted input and leaves valid inputs unaffected.
This patch removes an exploit primitive — a code pattern that, while not independently exploitable today, could be chained with other weaknesses by automated exploit-development tooling. Proactive removal of such primitives raises the bar against increasingly capable automated attack tools.
Automated security fix by OrbisAI Security