/

CVE-2026-34480

Severity:

HIGH RISK

(7.5)

Improper Output Encoding in Apache Log4j XmlLayout

CVE-2026-34480

Analyzed

Vulnerability type

Category:

Improper Output Encoding

CWE:

CWE-116

Impact:

Log Integrity and Availability Loss

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Apache Log4j Core's XmlLayout fails to sanitize characters forbidden by the XML 1.0 specification, leading to malformed XML whenever log messages or MDC values contain such characters.

Depending on the StAX implementation, this can cause downstream XML parsers to reject log documents or throw exceptions, resulting in dropped or undelivered log events.

Affected context

This vulnerability affects applications that:

  • Use Apache Log4j Core up to and including 2.25.3
  • Configure XmlLayout for log output (e.g., XML log files, XML over streams)
  • Rely on StAX-based XML processing—either the JRE built-in implementation or alternatives like Woodstox

The issue manifests when log messages, parameters, or mapped diagnostic context (MDC) values contain characters forbidden by the XML 1.0 specification, which are then written directly into the XML output without sanitization.

Exploit preconditions

  • Attack surface: Any code path that logs attacker-controlled or untrusted data using XmlLayout.
  • Required access: Ability to influence log content (e.g., user input, headers, message bodies, or MDC values that are recorded in logs).
  • Trigger point: A logging call that formats output using XmlLayout while containing XML 1.0 forbidden characters.
  • Why exploitation is possible: XmlLayout does not sanitize or filter forbidden XML characters before emitting them, relying on StAX output; depending on the StAX implementation, this can silently produce malformed XML or raise exceptions during logging, causing log records to be dropped.

Why this happens

The root cause lies in improper output encoding and validation when generating XML logs.

XmlLayout assumes that escaping common XML metacharacters is sufficient but does not enforce the XML 1.0 character set rules, allowing forbidden control characters and other invalid code points to pass through.

This behavior maps to CWE-116: Improper Encoding or Escaping of Output, where data is emitted into a structured output format (XML) without ensuring it conforms to the specification, causing downstream consumers to fail when processing the malformed documents.

Potential impact

  • Log entries may be malformed, causing XML parsers to reject entire documents.
  • Downstream log-processing, auditing, or SIEM systems can drop affected records, reducing observability.
  • Logging calls may fail with exceptions (depending on the StAX implementation), preventing events from reaching their intended appenders.
  • Critical security or operational events can be missing from primary logs, complicating incident response and compliance reporting.
  • Internal status logs might contain partial information, leading to divergent logging views between operational logs and internal diagnostics.

General mitigation guidance

Mitigation typically focuses on enforcing XML-safe output and limiting trust in log input sources.

Common defensive patterns include:

  • Applying strict character filtering or normalization before writing to XML-based layouts, ensuring conformance with XML 1.0 character rules.
  • Encapsulating XmlLayout usage with a sanitation layer that rejects or replaces forbidden characters in log messages and MDC values.
  • Segregating untrusted or high-variance input into non-XML log channels, reserving XML layouts for structured, validated data.
  • Implementing robust error-handling around logging logic to prevent dropped events when output failures occur, such as fallbacks to plain-text appenders.
  • Minimizing direct logging of raw user-controlled content and, where necessary, constraining its form (e.g., whitelisting expected character ranges for identifiers or tokens).

How teams detect issues like this

Organizations can detect this class of issue through:

  • Static analysis rules that flag XML emitters and layout implementations that do not explicitly validate against XML 1.0 character sets.
  • Code review checklists that require verification of encoding and character-set handling whenever logs are written in structured formats (XML, JSON).
  • Runtime monitoring for logging-related exceptions, particularly in environments using alternative StAX implementations such as Woodstox, and correlating these with missing events in primary logs.
  • Log processing pipeline health checks that alert on malformed XML documents, parser failures, or unexpected drops in ingest volume for XML-based log streams.
  • Policy enforcement in CI/CD that discourages or gates the introduction of new XML-based log outputs without explicit conformance tests.

Sources

SourceLink
github.comgithub.com/apache/logging-log4j2/pull/4077
lists.apache.orglists.apache.org/thread/5x0hcnng0chhghp6jgjdp3qmbbhfjzhb
logging.apache.orglogging.apache.org/cyclonedx/vdr.xml
logging.apache.orglogging.apache.org/log4j/2.x/manual/layouts.html#XmlLayout
logging.apache.orglogging.apache.org/security.html#CVE-2026-34480
openwall.comopenwall.com/lists/oss-security/2026/04/10/9

Frequently asked

questions

It can be influenced remotely if your application logs data derived from network or user inputs. An attacker who can supply values that end up in XML logs (for example via HTTP parameters or headers) may cause malformed XML or logging failures, though this does not directly provide code execution.

The attacker needs the ability to control or significantly influence log content—such as user-submitted fields, identifiers, or MDC values—that are captured by XmlLayout. No direct access to the logging infrastructure is required beyond causing the application to log crafted data.

The safest pattern is to ensure all XML log output passes through a strict encoding and validation layer that enforces XML 1.0 character rules before emission. This typically involves sanitizing or rejecting forbidden characters and treating XML logging as a structured data serialization step rather than a simple string write.

To prevent similar problems, standardize on robust output-encoding practices for all structured logging formats, enforce character-set conformance tests in your logging libraries, and integrate checks into code review and automated testing. Additionally, reduce reliance on XML logging for arbitrary user-controlled content and prefer formats or pipelines that explicitly validate and sanitize input before output.

Find out what's already
exploitable in your codebase.