fix: [import_mod/lib] use defusedxml for GoAML and ODT parsing - #871
Open
elhoim wants to merge 1 commit into
Open
fix: [import_mod/lib] use defusedxml for GoAML and ODT parsing#871elhoim wants to merge 1 commit into
elhoim wants to merge 1 commit into
Conversation
goamlimport.py and lib/ODTReader/odtreader.py both parse attacker-supplied files with the stdlib xml.etree.ElementTree.fromstring, which is not hardened against XML entity-expansion attacks such as billion-laughs. A crafted GoAML XML report or .odt document submitted for import can exhaust memory or CPU on the MISP server through nested entity expansion, turning a routine import into a denial of service. defusedxml is already pulled in via the sigmf dependency in poetry.lock, so swap both fromstring calls to use defusedxml.ElementTree instead of the stdlib module. Verified with flake8 on goamlimport.py and py_compile on odtreader.py (both clean), and the full pytest suite against a live modules server on port 6761: 161 passed, 4 skipped, 5 subtests passed, matching baseline. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The defect
Both
goamlimport.pyandodtreader.pyparse attacker-supplied XML with the standard library'sxml.etree.ElementTree, which is not hardened against XML entity-expansion attacks:xml.etree.ElementTree.fromstringwill happily expand nested internal entities (e.g. "billion laughs") or resolve external entities, so a crafted GoAML report or a craftedcontent.xmlinside an.odtfile can exhaust memory/CPU on the misp-modules worker.Impact
A MISP user importing a malicious GoAML report or a malicious
.odtfile (both are user-supplied import inputs) can cause a denial-of-service against the misp-modules server process handling the import — no authentication beyond "can submit an import" is required.Fix
Swap the import to
defusedxml.ElementTree, which rejects entity expansion and external entity resolution while preserving the samefromstringAPI used at both call sites (ET.fromstringonly — no otherET.*attributes are used in either file, so this is a drop-in replacement here). No behaviour change for well-formed, non-malicious input.defusedxml(0.7.1) is already present inpoetry.lockas a transitive dependency ofsigmf, so no new dependency is introduced by this change — only the import is swapped. It is not currently declared as a direct dependency inpyproject.toml; maintainers may want to promote it to a direct dependency now that the code relies on it explicitly rather than transitively.Verification
flake8clean ongoamlimport.py;py_compileclean onodtreader.py.161 passed, 4 skipped, 5 subtests passed in 24.63s.ET.fromstring(grep -n 'ET\.' ...), whichdefusedxml.ElementTreesupports directly.Found during a review of the repository; other findings are being submitted as separate PRs.
🤖 Generated with Claude Code
https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8