Summary
The Apache Log4j 1-to-Log4j 2 bridge's Log4j1XmlLayout fails to escape characters that are forbidden in XML 1.0, resulting in malformed XML log output.
When such logs are consumed by standards-compliant XML parsers, downstream log processing systems may reject or drop affected records, leading to gaps in logging, monitoring, and security visibility.
Affected context
This vulnerability appears in environments that use the Apache Log4j 1-to-Log4j 2 bridge and rely on XML-formatted logs for downstream processing.
It primarily affects:
- Systems that configure
Log4j1XmlLayoutdirectly in Log4j Core 2. - Deployments using the Log4j 1 configuration compatibility layer with
org.apache.log4j.xml.XMLLayoutas the layout class.
The issue becomes relevant when logs are consumed by XML 1.0–compliant parsers (e.g., log aggregators, SIEMs, or indexing pipelines) that strictly enforce XML well-formedness. In such setups, specific control characters or invalid code points in the log output can cause the entire document or record to be rejected.
Exploit preconditions
- Attack surface: Log ingestion and processing pipeline that consumes Log4j XML logs.
- Required access: Ability to influence log contents (e.g., by supplying user input that is logged).
- Trigger point: Logging of values containing XML 1.0–forbidden characters (such as certain control characters) using the vulnerable XML layout.
- Why exploitation is possible: The XML layout does not properly sanitize or escape disallowed characters before emitting XML, violating the XML 1.0 specification. Standards-compliant parsers must treat these documents as fatal errors and abort processing, which can be triggered by crafted or unexpected input flowing into logs.
Why this happens
The underlying issue is an improper output encoding/escaping flaw consistent with CWE-116.
XML log layouts are expected to produce well-formed XML, which includes escaping reserved characters and preventing the inclusion of forbidden code points. The Log4j1XmlLayout in the Log4j 1-to-2 bridge emits raw character data into XML elements or attributes without enforcing XML 1.0 character constraints.
As a result, when log messages, parameters, or contextual data contain characters disallowed by the XML standard, the generated XML becomes malformed. Downstream consumers that rely on strict XML parsing semantics encounter fatal parse errors and must reject the affected records, breaking assumptions about reliable, machine-readable logging.
Potential impact
- Loss of specific log entries when downstream XML parsers reject malformed records.
- Gaps in audit trails, monitoring, and forensic evidence that may hinder incident response.
- Partial or complete failure of log indexing pipelines, leading to reduced searchability or delayed processing.
- Potential evasion of detection by security monitoring systems that rely on complete, parseable logs.
- Increased operational complexity due to intermittent log processing errors that are difficult to correlate with specific inputs.
General mitigation guidance
Mitigation revolves around ensuring that log output is well-formed XML and that layouts do not emit disallowed characters:
- Prefer logging layouts that strictly conform to XML 1.0 and apply proper character escaping and filtering before output.
- Introduce input normalization or sanitization for log fields that may contain control characters or untrusted data, reducing the chance of forbidden characters reaching the XML layout.
- Configure logging to use alternative formats (e.g., JSON or plain text) when XML is not strictly required, especially for logs that incorporate untrusted or high-entropy data.
- Enforce a separation between internal structured logging and user-facing or untrusted inputs, minimizing direct injection of raw input into structured log formats.
- Apply least-privilege principles to log processing infrastructure, so that failures in parsing or indexing do not cascade into larger service disruptions.
These patterns help make log pipelines more resilient to malformed data, whether caused by implementation bugs or unexpected inputs.
How teams detect issues like this
Detecting this type of vulnerability and its effects can be approached from both code and operational perspectives:
- Static analysis and configuration review:
- Flag usages of
Log4j1XmlLayoutororg.apache.log4j.xml.XMLLayoutin Log4j 2 configurations, especially in pipelines that consume logs as XML. - Review custom layouts or appenders for manual string concatenation or raw insertion of text into XML elements without centralized escaping routines.
- Runtime monitoring and log pipeline diagnostics:
- Monitor log aggregation and indexing systems for XML parsing errors, fatal parse exceptions, or sudden drops in ingest rates correlated with specific sources.
- Implement validation checks at pipeline boundaries that detect malformed XML and record meta-events (e.g., "dropped malformed log record from host X") for troubleshooting.
- Policy and CI/CD enforcement:
- Use automated configuration linting or security policy checks in CI pipelines to prevent introduction of deprecated or unsafe layout classes.
- Optionally leverage SAST/linters that understand logging frameworks to highlight risky logging patterns that directly embed untrusted values into structured formats like XML.

