/

CVE-2026-34481

Severity:

HIGH RISK

(7.5)

Output Encoding and Data Representation in Apache Log4j

CVE-2026-34481

Modified

Vulnerability type

Category:

Output Encoding and Data Representation

CWE:

CWE-116

Impact:

Log Integrity and Availability Disruption

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's JsonTemplateLayout up to and including version 2.25.3 may emit invalid JSON when log events contain non-finite floating-point values such as NaN, Infinity, or -Infinity.

If an attacker can inject such values into MapMessage fields that are logged via JsonTemplateLayout, downstream log processing or indexing systems can reject or drop those records, impacting log integrity and observability.

Affected context

This vulnerability arises in Java applications that:

  • Use Apache Log4j 2 with JsonTemplateLayout for structured JSON logging, and
  • Log MapMessage instances whose values may be influenced by external or attacker-controlled input, and
  • Rely on downstream systems (e.g., log shippers, SIEMs, analytics platforms, or search indexes) that strictly enforce RFC 8259-compliant JSON.

In these conditions, the presence of non-finite floating-point values in log data can cause the emitted JSON to be syntactically invalid for standards-compliant JSON parsers.

Exploit preconditions

  • Attack surface: Application logging pathway where user-controlled data is incorporated into MapMessage fields that are serialized with JsonTemplateLayout.
  • Required access: Ability to supply or influence floating-point values that the application logs in a MapMessage; this typically means access to an API, form, protocol message, or other input source whose values are logged without sufficient sanitization.
  • Trigger point: Emission of a log event that includes a non-finite floating-point value (NaN, Infinity, or -Infinity) within a MapMessage processed by JsonTemplateLayout.
  • Why exploitation is possible: JsonTemplateLayout in affected versions does not normalize or encode non-finite floating-point values into RFC 8259–compliant representations, emitting them directly and thus producing invalid JSON that strict parsers reject.

Why this happens

The root cause is improper output encoding and data representation when serializing floating-point values into JSON.

JsonTemplateLayout assumes that all Java floating-point values can be emitted directly into JSON without additional transformation, but JSON as defined by RFC 8259 does not permit non-finite numeric values such as NaN, Infinity, and -Infinity.

This mismatch between internal numeric representation and the JSON standard maps to CWE-116: Improper Encoding or Escaping of Output, where data is rendered into a format without conforming to that format's syntax rules.

As a result, certain valid in-memory values become invalid when serialized, breaking downstream processing that expects standards-compliant JSON.

Potential impact

  • Downstream log processing pipelines (e.g., log collectors, shippers, or brokers) may reject entire records containing non-finite floating-point values.
  • Log indexing and search systems (e.g., Elasticsearch, OpenSearch, or SIEM platforms) could fail to index affected events, reducing the completeness and reliability of security and operational telemetry.
  • Monitoring, alerting, and forensic investigations may be impaired due to missing or malformed log entries.
  • Automated workflows that depend on parsing these JSON logs (e.g., ETL jobs, anomaly detection, or compliance reporting) can encounter parse errors or partial data, leading to degraded functionality or false assumptions about system behavior.

General mitigation guidance

Mitigation generally revolves around enforcing standards-compliant output encoding and constraining how untrusted numeric data is logged:

  • Normalize or sanitize floating-point values before logging, converting NaN and infinities to well-defined string tokens or null values that conform to JSON syntax.
  • Introduce application-level logging wrappers that validate or transform MapMessage contents, ensuring that all values are representable in RFC 8259–compliant JSON.
  • Treat log fields derived from external input as untrusted data, and apply validation rules that reject or rewrite non-finite values before they reach the logger.
  • Prefer logging patterns and layouts that have explicit handling for special numeric values and are designed to produce strict, standards-compliant JSON by default.
  • Apply least-privilege principles to logging infrastructure, minimizing the blast radius if segments of the pipeline fail or drop records due to unexpected formats.

How teams detect issues like this

Detecting this issue typically involves combining configuration inspection with runtime validation:

  • Configuration review: Scan Log4j configurations for usages of JsonTemplateLayout, especially where MapMessage is used to log data derived from untrusted inputs.
  • Static analysis: Use code scanning to identify logging call sites where external or user-controlled floating-point values are placed into MapMessage structures without validation or normalization.
  • Log pipeline monitoring: Implement health checks and alerts on log collectors, parsers, and indexers to detect JSON parse failures, rejected records, or indexing errors correlated with logs from affected services.
  • Schema and contract enforcement: Employ log schemas or contracts that validate numeric fields during ingestion, surfacing non-finite values as violations to be investigated.
  • Automated review tools and CI checks can be configured to flag logging patterns that serialize floating-point values without handling special cases like NaN or infinities.

Sources

SourceLink
github.comgithub.com/apache/logging-log4j2/pull/4080
lists.apache.orglists.apache.org/thread/n34zdv00gbkdbzt2rx9rf5mqz6lhopcv
logging.apache.orglogging.apache.org/cyclonedx/vdr.xml
logging.apache.orglogging.apache.org/log4j/2.x/manual/json-template-layout.html
logging.apache.orglogging.apache.org/security.html#CVE-2026-34481
openwall.comopenwall.com/lists/oss-security/2026/04/10/10

Frequently asked

questions

It can be influenced remotely if an attacker can supply floating-point values through an interface that the application logs via MapMessage and JsonTemplateLayout. The attacker does not exploit code execution, but can impact log integrity and downstream observability.

The attacker needs the ability to control or significantly influence numeric data that the application logs as part of a MapMessage. This typically corresponds to regular user-level access to an API, request parameter, or message payload that is logged without sufficient validation.

The safest pattern is to ensure that all log output conforms to JSON standards by normalizing special floating-point values before serialization and using logging components that explicitly handle NaN and infinities. Centralizing this logic in a shared logging utility helps ensure consistent behavior across the codebase.

Adopt a practice of treating logs as structured, schema-bound data rather than arbitrary strings, and enforce format compliance at the logging boundary. During design and review, verify that serialization libraries are standards-compliant, validate untrusted data before logging, and include log format checks and parsing tests in your CI/CD pipelines.

Find out what's already
exploitable in your codebase.