Repository navigation
Scan XML bodies from all Python XML parsers - #754
Open
iacobdaniel wants to merge 8 commits into
Open
iacobdaniel wants to merge 8 commits into
iacobdaniel wants to merge 8 commits into
Conversation
| for element in elements: | ||
| if isinstance(element.tag, str): | ||
| tag = element.tag | ||
| texts = (element.text, element.tail) |
Contributor
There was a problem hiding this comment.
🟠 High - Split lxml text is not scanned as the value the app consumes
An attacker sends an XML body whose lxml text value is split around a child or comment, while the application builds a query from the element's composed itertext() value. The new walker stores only element.text and element.tail as separate fragments and never stores the composed text, so the SQL-injection sink scans different values from the one used by the application and a payload can reach the sink without detection.
Suggested change
| texts = (element.text, element.tail) | |
| texts = (element.text, element.tail, "".join(element.itertext())) |
More info - Reply on this comment to give feedback or ignore the issue.
Contributor
Author
There was a problem hiding this comment.
Not a regression. It will be handled in a separate PR.
This branch has not been deployed
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.
Apps that parse the XML request body with minidom, sax, pulldom, xmltodict or defusedxml (which Django REST framework's XML parser uses) were not protected: the values never reached the injection checks, so an attack in the XML body went through. Instead of hooking each of these libraries one by one, this hooks the single place they all go through to read XML, the creation of Python's built-in expat parser, so one hook covers all of them and any other library built on expat. ElementTree and lxml don't use that parser, so their existing hooks are extended from fromstring to XML, parse and iterparse. Only XML that is the request body is collected, and values are collected as they are parsed, so a query run inside a sax callback or an iterparse loop is checked too.