# CVE-2026-40021: Apache Log4net: Silent log event loss in XmlLayout and XmlLayoutSchemaLog4J due to unescaped XML 1.0 forbidden characters

> Attackers can suppress log records by injecting forbidden XML characters, impairing audit trails and detection in applications using Apache Log4net.

- **Severity:** Medium 6.3 (`CVSS:4.0/AV:N/AC:H/AT:N/PR:N/UI:N/VC:N/VI:N/VA:N/SC:N/SI:L/SA:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 10 Apr 2026
- **Updated:** 10 Apr 2026
- **Also known as:** DEBIAN-CVE-2026-40021, ECHO-b32c-0992-129e, GHSA-4f7c-pmjv-c25w, UBUNTU-CVE-2026-40021

## What is CVE-2026-40021?

CVE-2026-40021 is a medium-severity vulnerability in Apache Log4net, published on 10 Apr 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Apache Log4net's  XmlLayout https://logging.apache.org/log4net/manual/configuration/layouts.html#layout-list  and  XmlLayoutSchemaLog4J https://logging.apache.org/log4net/manual/configuration/layouts.html#layout-list , in versions before 3.3.0, fail to sanitize characters forbidden by the  XML 1.0 specification https://www.w3.org/TR/xml/#charsets  in MDC property keys and values, as well as the identity field that may carry attacker-influenced data. This causes an exception during serialization and the silent loss of the affected log event.

An attacker who can influence any of these fields can exploit this to suppress individual log records, impairing audit trails and detection of malicious activity.

Users are advised to upgrade to Apache Log4net 3.3.0, which fixes this issue.

Weakness: CWE-116 (Improper Encoding or Escaping of Output)

## Which versions are affected by CVE-2026-40021?

2 open source packages ship an affected version, including log4net. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `log4net` | NuGet | All versions | 3.3.0 |
| `log4net` | NuGet | All versions | 3.3.0 |

Products: Apache Log4net.

## How do I fix CVE-2026-40021?

Upgrade log4net to 3.3.0 or later.

## Is CVE-2026-40021 being exploited?

There is no known exploitation of CVE-2026-40021 in the wild and no public exploit code.

## Other vulnerabilities in Apache Log4net

- [CVE-2018-1285](https://insights.sbomify.com/CVE-2018-1285/): XML External Entity attack in log4net (critical 9.8)
- [CVE-2026-105239](https://insights.sbomify.com/CVE-2026-105239/): Apache log4net: NUL character truncates EventLogAppender records (medium 5.3)
- [CVE-2026-105240](https://insights.sbomify.com/CVE-2026-105240/): Apache log4net: NUL character truncates OutputDebugStringAppender records (medium 5.3)
- [CVE-2026-105241](https://insights.sbomify.com/CVE-2026-105241/): Apache log4net: Unencodable content discards a whole SmtpPickupDirAppender batch (medium 5.3)
- [CVE-2026-105242](https://insights.sbomify.com/CVE-2026-105242/): Apache log4net: Request validation failure drops the event in the aspnet-request converter (medium 5.3)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2026-40021 and fix it if it is affected.

What it is: CVE-2026-40021 is a medium-severity vulnerability in Apache Log4net, published on 10 Apr 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2026-40021 in the wild and no public exploit code.

Affected packages and fixed versions:
- log4net (NuGet): affected all versions; fixed in 3.3.0
- log4net (NuGet): affected all versions; fixed in 3.3.0

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2026-40021/ (Markdown: https://insights.sbomify.com/CVE-2026-40021/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2026-40021
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2026-40021
- OSV: https://osv.dev/vulnerability/CVE-2026-40021

---
From sbomify Insights: https://insights.sbomify.com/CVE-2026-40021/
Summaries are generated and may contain mistakes; the official description above is the record.
