Repository navigation
Description
Log4j contains a minimal JSON parser, JsonReader, used to parse Log4j's own configuration: JSON configuration files, the MutableThreadContextMapFilter configuration, property mappings, and JSON Template Layout templates and resolver configuration. In 2.x it lives in org.apache.logging.log4j.layout.template.json.util; in 3.x in org.apache.logging.log4j.kit.json, which log4j-kit exports (OSGi @Export, version 3.0.0) under the module description "Helpers to implement Log4j 2.x API".
The parser recurses through readToken(), readArray() and readObject() without a depth limit, so a deeply nested document (a few thousand levels with the default thread stack) ends in a StackOverflowError instead of the IllegalArgumentException thrown for other malformed input. JsonTemplateLayoutCodecFuzzer currently works around this by bounding the length of its input (see OSS-Fuzz issue 370272570). Moreover, nothing in the Javadoc says that the parser is meant only for Log4j's own, operator-supplied input, and the exported 3.x package can give the impression that it is a general-purpose JSON parser.
Proposal:
- Add a nesting-depth counter to
JsonReader, incremented on entry toreadArray()andreadObject(), and throw anIllegalArgumentExceptiononce it exceeds a fixed limit (e.g. 128, far above the nesting of any real configuration file), in both 2.x and 3.x. Add a test parsing a document one level above the limit. - Relax the input length bound of
JsonTemplateLayoutCodecFuzzerand remove its comment about expected stack overflows. - State in the Javadoc of
JsonReaderand of its package that it is an internal component intended only for trusted input. Before 3.0.0 GA, consider moving the 3.x class to a non-exported (internal) package.
This issue originates from a private security report classified as a hardening.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTo triage
Activity