Summary
A default configuration issue in the Python lxml XML/HTML parsers can allow untrusted XML input to access local files via external entity resolution.
When applications parse attacker-controlled XML without disabling entity resolution, the parser may expose sensitive file contents from the host system.
Affected context
This vulnerability affects Python applications that use lxml to parse XML or HTML with its default parser configuration, where resolve_entities=True.
It becomes relevant when:
- XML/HTML content is derived from untrusted or partially trusted sources (e.g., HTTP requests, uploaded files, third‑party integrations), and
- The application does not explicitly restrict entity resolution (e.g.,
resolve_entities='internal'orresolve_entities=False), and - The environment hosts sensitive files accessible to the lxml process (keys, configuration, tokens, etc.).
Exploit preconditions
- Attack surface: Any lxml-based XML/HTML parsing endpoint or feature that accepts user-supplied or externally sourced XML.
- Required access: Ability to submit or influence XML content processed by lxml (e.g., request body, uploaded file, message queue payload).
- Trigger point: XML parsing performed with lxml's default parsers where
resolve_entities=True. - Why exploitation is possible: Entity resolution is enabled by default, allowing external or local entity references in XML to be expanded and read by the parser, violating the intended isolation between XML content and host resources.
Why this happens
The underlying problem is an unsafe XML parsing configuration that permits unrestricted entity resolution when handling untrusted data.
With resolve_entities=True, lxml allows XML documents to define and expand entities that reference local files or external resources.
This maps to CWE-611: Improper Restriction of XML External Entity Reference, where the XML parser is not hardened against malicious entity declarations and treats attacker-controlled XML as trustworthy enough to access local resources.
Potential impact
- Exposure of sensitive local files, such as application configuration, credentials, or secret keys.
- Disclosure of system information that can aid further attacks (e.g., file paths, environment details).
- Access to logs or internal data files that may contain user information or operational metadata.
- Facilitation of chained attacks, where leaked secrets enable lateral movement or privilege escalation in the broader environment.
General mitigation guidance
Effective mitigation focuses on hardening XML parsing behavior and tightening trust boundaries around input:
- Configure lxml parsers to disable or strictly restrict entity resolution, for example by setting
resolve_entities=Falseor using an equivalent internal-only mode where appropriate. - Prefer parser configurations and APIs that are secure by default for untrusted XML, avoiding generic "full-featured" parsers on external input.
- Limit the exposure of sensitive files and credentials on systems that handle untrusted parsing workloads; apply least-privilege file and process permissions.
- Where possible, avoid XML features that rely on custom entities for untrusted content, and use simpler data formats (e.g., JSON) for external interactions.
How teams detect issues like this
Organizations can identify and monitor for this class of issue through a combination of review and analysis:
- Static analysis & configuration review: Search for lxml parser usage where
resolve_entitiesis left default or explicitly set to a permissive mode when handling untrusted input. - Code review signals: XML parsing logic that directly processes request bodies, uploaded files, or third-party XML without a hardened parser configuration should be flagged for security review.
- Policy enforcement: Introduce coding guidelines and CI checks that require secure XML parsing settings for all XML-handling components.
- Runtime monitoring: Where feasible, monitor application behavior for unusual file access patterns correlated with XML parsing operations.

