CVE-2026-40021
XML Injection in Apache Log4net XmlLayout Causes Log Suppression
Publication date: 2026-04-10
Last updated on: 2026-04-22
Assigner: Apache Software Foundation
Description
Description
CVSS Scores
EPSS Scores
| Probability: | |
| Percentile: |
Meta Information
Affected Vendors & Products
| Vendor | Product | Version / Range |
|---|---|---|
| apache | log4net | to 3.3.0 (exc) |
Helpful Resources
Exploitability
| CWE ID | Description |
|---|---|
| CWE-116 | The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. |
Attack-Flow Graph
AI Powered Q&A
How does this vulnerability affect compliance with common standards and regulations (like GDPR, HIPAA)?:
This vulnerability allows an attacker to suppress individual log records by causing exceptions during log serialization, leading to silent loss of affected log events.
Such suppression of log records impairs audit trails and hinders the detection of malicious activity.
Since maintaining accurate and complete audit logs is a critical requirement for compliance with standards and regulations like GDPR and HIPAA, this vulnerability can negatively impact compliance by undermining the integrity and reliability of logging data.
Users are advised to upgrade to Apache Log4net 3.3.0, which fixes this issue and helps restore proper logging and audit trail integrity.
Can you explain this vulnerability to me?
This vulnerability affects Apache Log4net versions before 3.3.0 in its XmlLayout and XmlLayoutSchemaLog4J components. These components fail to sanitize characters that are forbidden by the XML 1.0 specification in certain fields such as MDC property keys, values, and the identity field, which can be influenced by an attacker.
Because of this failure to sanitize invalid XML characters, an exception occurs during the serialization of log events, causing the affected log event to be silently lost.
An attacker who can control these fields can exploit this to suppress individual log records, which impairs audit trails and the detection of malicious activity.
The issue was fixed in Apache Log4net version 3.3.0 by hardening the processing of invalid XML characters to prevent malformed XML logs.
How can this vulnerability impact me? :
This vulnerability can impact you by allowing an attacker to suppress specific log records by injecting forbidden XML characters into log fields.
The suppression of log events means that important audit trail information can be lost silently, making it harder to detect malicious activities or security incidents.
As a result, your ability to monitor, audit, and respond to security events is impaired, potentially increasing the risk of undetected attacks or unauthorized actions.
How can this vulnerability be detected on my network or system? Can you suggest some commands?
This vulnerability involves the failure of Apache log4net XmlLayout and XmlLayoutSchemaLog4J to sanitize forbidden XML characters in MDC property keys, values, and identity fields, causing exceptions and silent loss of log events.
To detect this vulnerability on your system, you should monitor your log files for missing or suppressed log entries that could indicate serialization exceptions due to invalid XML characters.
Since the issue relates to XML serialization errors in log events, you can search your log files for error messages or exceptions related to XML parsing or serialization failures.
Commands to help detect this might include using grep or similar tools to find XML serialization errors in your log files, for example:
- grep -i 'xml serialization error' /path/to/logfile.log
- grep -i 'exception' /path/to/logfile.log | grep -i 'xml'
- Review logs for unexpected missing entries or gaps that could indicate suppressed log events.
Additionally, reviewing the configuration of log4net layouts to confirm usage of XmlLayout or XmlLayoutSchemaLog4J can help identify if your system is potentially affected.
What immediate steps should I take to mitigate this vulnerability?
The primary and recommended mitigation step is to upgrade Apache log4net to version 3.3.0 or later, where this vulnerability has been fixed by properly sanitizing forbidden XML characters.
Until the upgrade can be applied, consider reviewing and restricting any input or data that can influence MDC property keys, values, or identity fields to prevent injection of invalid XML characters.
Also, monitor your logging system for serialization exceptions or missing log events to detect exploitation attempts.