flawopen.com/Incidents/log4shell-jndi-injection-december-2021
Log4Shell (CVE-2021-44228): Cause and Fix
CVE-2021-44228 let logged data trigger Log4j 2 lookups and JNDI class loading. Update Log4j and inventory every embedded copy.[1], [2], [4]
An office has a clerk whose only job is to write down what visitors say. Someone discovers that if a visitor speaks a particular phrase, the clerk stops writing, goes to an address named in the phrase, collects a sealed envelope from a stranger and follows the instructions inside. The clerk was only ever supposed to write things down.[1]
Core Concepts & Subsystem Terms
Message lookups- A Log4j 2 feature that replaced ${...} expressions inside log messages with values at logging time. Before 2.15.0 this also applied to data inside the message, not just the configured pattern.[1]
JNDI- Java Naming and Directory Interface, an API for looking up objects in directory services such as LDAP. A JNDI lookup to a remote server could return a class for the JVM to load.[1]
Expression injection (CWE-917)- Untrusted data reaches an evaluator of expressions, so text supplied as data is executed as an instruction.[1]
Transitive dependency- A library your application includes only because another library depends on it. Many Log4Shell exposures came from copies of Log4j nobody had listed.[4]
Framework mappings
- CWE reference for the weakness described in this guide: CWE-20 CWE-502 CWE-917
- D3-OTF Outbound Traffic Filtering — This guide's outbound network restriction limits which destinations the service or host can reach.
- CISA KEV — added 2021-12-10 — CVE-2021-44228
Incident Timeline
Chen Zhaojun of Alibaba Cloud Security reports the flaw privately to Apache.[1]
CISA issues Emergency Directive 22-02 requiring US federal agencies to find and mitigate Log4j.[3]
Log4j 2.17.1 fixes CVE-2021-44832, the last of three follow-up CVEs after 2.15.0 (CVE-2021-45046 and CVE-2021-45105).[1]
Step-by-Step Attack Flow
Attacker text reaches a log call
Any value an application logs, such as a username, a header or a search term, can carry a lookup expression chosen by the attacker.[1]
Source Code: Flaw vs. Secure Implementation
Illustrative Maven configuration. Importing log4j-bom makes every Log4j module, including copies pulled in by other libraries, resolve to one current version. The enforcer rule then fails the build if any log4j-core older than 2.17.1 is still reachable, including transitively, so a new dependency cannot quietly reintroduce the vulnerable code. Upgrading is the actual fix; blocking outbound LDAP and RMI from application servers is the defence in depth that broke exploitation even where patching lagged.
<!-- pom.xml: a direct dependency pinned to a vulnerable release -->
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
</dependency>
</dependencies>
<!-- Nothing stops another library from pulling in an older log4j-core transitively. -->
<!-- pom.xml: one version for every Log4j module, and a build that fails on old ones -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-bom</artifactId>
<version>2.24.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<id>ban-vulnerable-log4j</id>
<goals><goal>enforce</goal></goals>
<configuration>
<rules>
<bannedDependencies>
<searchTransitive>true</searchTransitive>
<excludes>
<exclude>org.apache.logging.log4j:log4j-core:[2.0-beta9,2.17.1)</exclude>
</excludes>
</bannedDependencies>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Engineering & System Hardening Checklist
- ✓Upgrade log4j-core to 2.17.1 or later (2.12.4 on Java 7, 2.3.2 on Java 6), and fail builds that resolve an older version anywhere in the dependency tree.[1]
- ✓Generate an SBOM for every build and store it with the artefact, so a future advisory can be matched to affected services in minutes.[4], [3]
- ✓Scan deployed artefacts, not just source repositories: shaded and bundled JARs hid Log4j from dependency manifests in many products.[4]
- ✓Apply default-deny egress to application servers; outbound LDAP, RMI and DNS to arbitrary hosts were required for exploitation.[4], [3]
- ✓When a structural flaw is fixed, expect follow-up CVEs and keep the incident open until the vendor's fixes settle.[1]
Sources
- Apache Log4j — security vulnerabilities (CVE-2021-44228 and follow-ups)
- CVE-2021-44228 — CVE record
- CISA — Emergency Directive 22-02: Mitigate Apache Log4j Vulnerability
- CISA — Apache Log4j vulnerability guidance
- Is Java's ObjectInputStream safe to use on untrusted data?
- Command Injection — full class reference