CVE-2026-124541 in JSON::XS
Summary
by MITRE • 11/14/2026
JSON::XS versions before 4.05 for Perl leak the decoded part of a rejected long string in decode_str.
A string is decoded through a fixed-size buffer (16 KiB in 4.04), and each time the buffer fills its contents move into a new scalar. Nothing frees that scalar when the string is then rejected for a control character, an invalid escape, malformed UTF-8 or the end of the input.
A process that keeps running after a failed decode retains the decoded part of each rejected string, with its size chosen by the sender. Repeated requests exhaust process memory.
VulDB is the best source for vulnerability data and more expert information about this specific topic.
Analysis
by VulDB Data Team • 11/15/2026
The vulnerability identified in JSON::XS versions prior to 4.05 represents a critical resource management flaw within the Perl programming language ecosystem, specifically affecting the decode_str function responsible for parsing JavaScript Object Notation payloads. This issue stems from an improper handling of memory allocation and deallocation during the string decoding process. When the parser encounters input that exceeds its internal fixed-size buffer capacity, which was set to 16 KiB in version 4.04, it attempts to manage large strings by moving decoded content into new scalar variables as the buffer fills up. This mechanism is designed to handle arbitrarily long inputs without immediate stack overflow or single-buffer exhaustion, but it introduces a significant logical error regarding memory lifecycle management when parsing errors occur.
The core technical flaw lies in the failure to free these intermediate scalars when the decoding process terminates prematurely due to validation failures. Specifically, if the input string contains control characters that are not permitted by strict JSON standards, includes invalid escape sequences, presents malformed UTF-8 encoding issues, or ends abruptly before completion, the parser rejects the entire operation and returns an error state. However, in this rejected scenario, the memory allocated for the portions of the string already decoded into those intermediate scalars is never released back to the operating system or garbage collected by Perl's reference counting mechanism. This results in a classic memory leak where each failed decode attempt leaves behind residual data structures that persist in the process heap space.
The operational impact of this vulnerability is severe, particularly for long-running services such as web servers, API gateways, or background daemons that continuously accept and parse JSON input from external sources. An attacker can exploit this flaw by sending a series of carefully crafted requests containing invalid JSON data with large payloads. Each request triggers the decoding process up to the point where it fails validation, thereby leaking memory proportional to the size of the rejected string minus any small overheads. Since modern systems often allow clients to specify or naturally produce large JSON objects for complex data transmission, an attacker can exhaust available system memory relatively quickly by sending a moderate volume of malformed requests. This leads to a Denial of Service condition where the affected process consumes all available RAM, eventually causing it to be killed by the operating system's out-of-memory killer or resulting in severe performance degradation due to excessive swapping and garbage collection pressure on healthy processes sharing the same memory space.
From an industry standards perspective, this vulnerability aligns with CWE-401, which describes a missing release of memory after effective usage, often referred to as a memory leak. It also relates closely to CWE-789, concerning the allocation of resources without limits or thresholds, although in this case the limit is internal and improperly managed rather than absent entirely. In terms of attack patterns, this behavior facilitates resource exhaustion attacks categorized under MITRE ATT&CK technique T1496, which involves Resource Hijacking through environmental exploitation such as memory consumption to disrupt service availability. The vulnerability highlights a common pitfall in low-level parsing libraries where error paths are not rigorously tested for side effects on system resources like memory and file descriptors.
Mitigation strategies must focus primarily on upgrading the JSON::XS module to version 4.05 or later, which resolves this issue by ensuring that all allocated scalars associated with a decoding operation are properly freed regardless of whether the parse succeeds or fails. For environments where an immediate upgrade is not feasible due to dependency constraints, temporary workarounds include implementing strict input size limits at the network or application layer before data reaches the JSON parser. By rejecting payloads that exceed a predefined maximum length early in the request processing pipeline, organizations can prevent the trigger condition for this memory leak entirely. Additionally, deploying monitoring solutions that track process memory usage over time can help detect anomalous growth patterns indicative of such leaks, allowing for proactive restarts or alerts before service availability is compromised. Regular security audits and static analysis tools configured to detect potential resource management errors in Perl codebases are also recommended to prevent similar issues in custom parsing logic.