Log4Shell: a logging library that could run remote code
Log4Shell is the name given to CVE-2021-44228, a critical flaw in the Apache Log4j 2 logging library. A string that an application merely wrote to its log could make the server fetch and run code from somewhere else. It turned a library most teams never think about into a remote code execution hole in thousands of products, and it is the standard example of why a dependency inventory matters.
Quick facts
- Identifier
- CVE-2021-44228, nicknamed Log4Shell
- Product
- Apache Log4j 2, the
log4j-coreartifact only (Apache Logging Services security page) - NVD publication
- 10 December 2021 (NVD)
- Severity
- CVSS v3.1 base score 10.0, network vector, no privileges, no user interaction (NVD)
- Weaknesses
- CWE-20, CWE-400, CWE-502 and CWE-917, as listed by NVD
- Exploited in the wild
- Listed in the CISA Known Exploited Vulnerabilities catalog; NVD records the add date as 10 December 2021
- OWASP category
- A03:2025 Software Supply Chain Failures
- Main fix
- Upgrade
log4j-coreto a release Apache lists as fixed for your Java version, and find every copy of it
Dates, scores and version ranges on this page come from NVD, the Apache Logging Services security page and the CISA guidance. Where those sources disagree with an older article, they win.
What Log4Shell is
Log4j is a Java library that applications use to write log messages. Version 2 could do more than copy text into a file: it could look values up while formatting a message, and one of those lookups used JNDI, the Java Naming and Directory Interface, to ask a directory service for an object. The NVD description says that an attacker who can control log messages or log message parameters can execute arbitrary code loaded from LDAP servers when message lookup substitution is enabled. Its identifier is explained under CVE and the scoring under CVSS.
The Apache page puts the cause plainly: the JNDI features in these versions "do not protect against attacker-controlled LDAP and other JNDI related endpoints", so the library would follow a reference chosen by whoever supplied the text.
What made this unusual is where the attacker's text could come from. Applications log things they receive: the User-Agent header, a username on a failed sign-in, a search term, an API parameter. Any of them, once logged, could carry the lookup. The attacker did not need an account or a bug in the application's own code. The vulnerable behaviour sat in the logger, one step after the request had already been accepted.
The flaw was reported to Apache by Chen Zhaojun of the Alibaba Cloud Security Team, as credited on the Apache page.
Why it spread so widely
Three properties combined. The severity is the top of the scale: CVSS 10.0, reachable over the network, needing no privileges and no click. The library is everywhere; CISA describes Log4j as "very broadly used in a variety of consumer and enterprise services, websites, and applications." And it is rarely a direct choice. Many teams never added Log4j themselves. It arrived inside a framework, a vendor appliance or an application server, and was bundled in a form no package manager reported.
That last point is the software supply chain lesson. You cannot patch what you do not know you run. CISA's guidance asks organisations to find affected instances, including internally developed software, systems that are not internet-facing, and SaaS or cloud services, before anything else.
It also shows how a zero-day behaves once public. Until a fix exists, defenders have only mitigations. After it exists, the work becomes a race between patch rollout and scanning, and the long tail is made of products nobody updates.
Affected and fixed versions
For CVE-2021-44228 the Apache Logging Services security page lists log4j-core in these ranges as affected: from 2.0-beta9 up to but not including 2.3.1, from 2.4 up to but not including 2.12.2, and from 2.13.0 up to but not including 2.15.0. The fixed releases it names depend on the Java version in use.
- Java 8 and later: 2.15.0 was the first fixed release for this CVE.
- Java 7: 2.12.2.
- Java 6: 2.3.1.
Only log4j-core is affected. An application that includes only log4j-api is not. Log4j 1.x is a different codebase and end of life; the Apache page tells owners to audit its configuration for JMSAppender, which is tracked as a separate CVE (CVE-2021-4104).
Treat 2.15.0 as a floor for history, not a target. The NVD description says the behaviour was fixed in 2.16.0 by removing the functionality, and later advisories moved the recommended release higher still, as the next section explains.
The follow-up advisories
Fixing the original flaw did not end the story. The Apache Logging Services security page lists three further CVEs in the same library:
- CVE-2021-45046, CVSS 9.0: the fix for CVE-2021-44228 was incomplete in certain non-default configurations involving the Thread Context Lookup. Fixed in 2.16.0 (Java 8 and later), 2.12.3 (Java 7) and 2.3.1 (Java 6).
- CVE-2021-45105, CVSS 5.9: uncontrolled recursion during lookup evaluation could cause a denial of service. Fixed in 2.17.0, 2.12.3 and 2.3.1.
- CVE-2021-44832, CVSS 6.6: a JDBC Appender configured with a non-
javadata source protocol. It is fixed by limiting JNDI data source names to thejavaprotocol, in 2.17.0, 2.12.3 and 2.3.1.
The CISA guidance of 28 December 2021 kept raising the version it recommended as later flaws were found. The practical reading: do not stop at the first version that closes the headline CVE. Move to the newest release in your Java line, and re-read the Apache page when you plan the upgrade.
How to respond
The order below follows CISA's guidance, with the detail left to the vendor pages.
- Inventory first. Find every deployment of
log4j-core, including copies bundled inside other products and internal services behind the edge. CISA advises scanning networks and hosts and checking vendor lists. - Patch the exposed systems first. CISA: "Apply available patches immediately", starting with mission-critical and internet-facing systems.
- Mitigate where you cannot patch. The Apache page lists configuration mitigations for some releases, and CISA's alert AA21-356A lists temporary measures. CISA prefers patching because tracking mitigations is overhead, and says an asset that can be neither patched nor mitigated should be considered for removal from the network.
- Look for compromise. Logs from services running affected versions contain user-controlled strings, so review them. A patched server may already have been used.
- Ask your vendors. Products that embed Log4j need the vendor's update, not yours.
CISA issued Emergency Directive 22-02 on 17 December 2021, requiring federal civilian agencies to patch internet-facing assets immediately. For a private company, nothing in the directive is binding; it is useful as an indication of how the agency ranked the urgency. The NVD record shows an action due date of 24 December 2021 for agencies under the Known Exploited Vulnerabilities catalog.
Where a WAF helps and where it does not
A web application firewall reads requests. Log4Shell arrived in requests, usually in headers and parameters, so a filter can recognise the lookup syntax inside those fields and refuse or record the request. That is a reasonable stopgap while a patch is tested. It is the use case behind virtual patching, and virtual patching buys time; it does not repair anything.
The limits are real, and they are the reason the fix is in the dependency:
- A filter sees the request, not the library. The vulnerable code stays in your application and runs again the next time any path reaches the logger.
- Pattern matching on a string that can be written in several ways is a contest. A match that works today may miss an obfuscated variant, and a rule loose enough to catch variants can flag legitimate traffic.
- Input does not always cross your edge. A message that comes from a queue, an internal service, a log shipper or a partner system never touches the filter.
- A filter does not stop the outbound step. If code does run, what the server then fetches depends on your network egress rules, not on the request filter.
Bridge WAF has three modes: off, monitor and block. For a vulnerability like this, start in monitor. Matches are recorded and every request is still served, so the activity log shows what a rule would refuse, and you can check for false positives before you switch to block. That helps with exposure and with scoping: log entries with the pattern tell you which parts of the site were probed. It does not substitute for the upgrade, and it does not inspect traffic that never reaches the edge.
Lookup-style strings in headers also overlap with other injection classes, such as server-side template injection, where untrusted input is evaluated as an expression by the application.
Questions
What is Log4Shell?
Log4Shell is the name for CVE-2021-44228, a flaw in Apache Log4j 2 that let a remote, unauthenticated attacker make a server run code by getting a crafted string into something the application logged. NVD rates it 10.0 out of 10.
Which Log4j versions are affected by CVE-2021-44228?
The Apache security page lists log4j-core from 2.0-beta9 up to but not including 2.15.0, with the older 2.3.x and 2.12.x branches fixed in 2.3.1 and 2.12.2. Only log4j-core is affected, not log4j-api alone. Later advisories raised the recommended minimum, so check the current Apache page.
How do you fix Log4Shell?
Upgrade log4j-core to a release that Apache lists as fixed for your Java version, then check for copies of the library bundled inside other products. Mitigations exist for cases where patching is not yet possible, but CISA prefers patching because mitigations have to be tracked.
Can a WAF stop Log4Shell?
A WAF can flag and refuse requests whose headers or parameters contain the lookup pattern, which lowers exposure while you patch. It does not remove the vulnerable library, and it cannot see input that reaches the logger by a path that does not cross the filter. Patching is the fix.
Is Log4Shell still relevant?
Yes. The flaw is in software that has to be found and updated one deployment at a time, and CISA's guidance covers internal, non-internet-facing and vendor-supplied systems as well as public ones. NVD lists the CVE in CISA's Known Exploited Vulnerabilities catalog.