XML is parsed with lxml in a way that expands entities from the document
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.
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) 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:
[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.