XML is parsed with lxml in a way that expands entities from the document

tx0/python:lxml-entity-expansionrecommendedwarningsecurity, cwe-611

What it finds

lxml resolves the entities a document declares unless its parser is made with resolve_entities=False. A document from outside can then make the parser read local files into the result, or expand nested entities until memory runs out. Reported are lxml.etree.XMLParser(...) calls without resolve_entities=False, and parse, fromstring and XML from lxml.etree called without a parser.

From the rule's source, lxml_entity_expansion.rs.

Example from the rule's tests
from lxml import etree parser = etree.XMLParser()tx0 reports: this parser expands the entities a document declaressafe = etree.XMLParser(resolve_entities=False)tree = etree.parse(path)tx0 reports: the default parser of lxml expands the entitiesroot = etree.fromstring(data, safe)other = etree.fromstring(data, parser=safe)
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:lxml-entity-expansion" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:lxml-entity-expansion] reason="..."

tx0 explain tx0/python:lxml-entity-expansion shows the same in the terminal. Found a false positive? Report it.