CVE-2022-31116: CWE-670: Always-Incorrect Control Flow Implementation in ultrajson ultrajson
UltraJSON is a fast JSON encoder and decoder written in pure C with bindings for Python 3.7+. Affected versions were found to improperly decode certain characters. JSON strings that contain escaped surrogate characters not part of a proper surrogate pair were decoded incorrectly. Besides corrupting strings, this allowed for potential key confusion and value overwriting in dictionaries. All users parsing JSON from untrusted sources are vulnerable. From version 5.4.0, UltraJSON decodes lone surrogates in the same way as the standard library's `json` module does, preserving them in the parsed output. Users are advised to upgrade. There are no known workarounds for this issue.
AI Analysis
Technical Summary
CVE-2022-31116 is a vulnerability in UltraJSON (ujson), a high-performance JSON encoder and decoder implemented in pure C with Python bindings for versions 3.7 and above. The affected versions prior to 5.4.0 improperly handle JSON strings containing escaped surrogate characters that are not part of valid surrogate pairs. In Unicode, surrogate pairs are used to encode characters outside the Basic Multilingual Plane, and improper handling of lone surrogates can lead to incorrect decoding results. Specifically, ujson versions before 5.4.0 decode these lone surrogates incorrectly, which can corrupt string data and cause key confusion and value overwriting in Python dictionaries. This means that when JSON data from untrusted sources contains such malformed surrogate sequences, the resulting Python dictionary objects may have overwritten or misrepresented keys and values, potentially leading to logic errors, data integrity issues, or security flaws in applications relying on this data. From version 5.4.0 onward, UltraJSON aligns its decoding behavior with Python's standard json module by preserving lone surrogates in the parsed output, mitigating the issue. There are no known workarounds aside from upgrading to the fixed version. The vulnerability is classified under CWE-670, which relates to always-incorrect control flow implementation, indicating a fundamental flaw in how the decoder processes certain input sequences. Although no exploits are currently known in the wild, all users parsing JSON from untrusted sources with affected versions are at risk of data corruption and potential downstream impacts due to this flaw.
Potential Impact
For European organizations, the impact of this vulnerability primarily revolves around data integrity and application reliability. Organizations that utilize UltraJSON for parsing JSON data from external or untrusted sources risk corrupted data structures, which can lead to incorrect application behavior, logic errors, or security issues such as unauthorized data manipulation or denial of service through malformed inputs. This is particularly critical for sectors handling sensitive or regulated data, such as financial services, healthcare, and government agencies, where data integrity is paramount. Additionally, applications that rely on JSON for configuration, inter-service communication, or API responses could experience subtle bugs or failures that are difficult to diagnose. While this vulnerability does not directly lead to remote code execution or privilege escalation, the potential for key confusion and value overwriting could be exploited in complex attack chains or to bypass certain application-level security controls. The lack of known exploits suggests a low immediate threat, but the widespread use of UltraJSON in Python environments means that many European organizations could be affected if they have not updated to the patched version. The vulnerability's medium severity reflects the moderate risk posed by data corruption and the potential for indirect security consequences.
Mitigation Recommendations
The primary and most effective mitigation is to upgrade UltraJSON to version 5.4.0 or later, where the decoding behavior has been corrected to handle lone surrogates safely and consistently with the Python standard library. Organizations should audit their software dependencies to identify usage of UltraJSON versions below 5.4.0, especially in environments processing JSON from untrusted or external sources. For environments where immediate upgrading is not feasible, consider implementing input validation or sanitization layers that detect and reject JSON inputs containing malformed surrogate pairs before they reach the UltraJSON parser. Additionally, developers should review application logic that depends on JSON key uniqueness and integrity to detect anomalies that might arise from corrupted parsing results. Monitoring and logging JSON parsing errors or unexpected dictionary behaviors can help identify exploitation attempts or data corruption. Finally, organizations should incorporate this vulnerability into their software supply chain risk management and vulnerability scanning processes to ensure timely detection and remediation.
Affected Countries
Germany, France, United Kingdom, Netherlands, Italy, Spain, Sweden, Poland, Belgium, Finland
CVE-2022-31116: CWE-670: Always-Incorrect Control Flow Implementation in ultrajson ultrajson
Description
UltraJSON is a fast JSON encoder and decoder written in pure C with bindings for Python 3.7+. Affected versions were found to improperly decode certain characters. JSON strings that contain escaped surrogate characters not part of a proper surrogate pair were decoded incorrectly. Besides corrupting strings, this allowed for potential key confusion and value overwriting in dictionaries. All users parsing JSON from untrusted sources are vulnerable. From version 5.4.0, UltraJSON decodes lone surrogates in the same way as the standard library's `json` module does, preserving them in the parsed output. Users are advised to upgrade. There are no known workarounds for this issue.
AI-Powered Analysis
Technical Analysis
CVE-2022-31116 is a vulnerability in UltraJSON (ujson), a high-performance JSON encoder and decoder implemented in pure C with Python bindings for versions 3.7 and above. The affected versions prior to 5.4.0 improperly handle JSON strings containing escaped surrogate characters that are not part of valid surrogate pairs. In Unicode, surrogate pairs are used to encode characters outside the Basic Multilingual Plane, and improper handling of lone surrogates can lead to incorrect decoding results. Specifically, ujson versions before 5.4.0 decode these lone surrogates incorrectly, which can corrupt string data and cause key confusion and value overwriting in Python dictionaries. This means that when JSON data from untrusted sources contains such malformed surrogate sequences, the resulting Python dictionary objects may have overwritten or misrepresented keys and values, potentially leading to logic errors, data integrity issues, or security flaws in applications relying on this data. From version 5.4.0 onward, UltraJSON aligns its decoding behavior with Python's standard json module by preserving lone surrogates in the parsed output, mitigating the issue. There are no known workarounds aside from upgrading to the fixed version. The vulnerability is classified under CWE-670, which relates to always-incorrect control flow implementation, indicating a fundamental flaw in how the decoder processes certain input sequences. Although no exploits are currently known in the wild, all users parsing JSON from untrusted sources with affected versions are at risk of data corruption and potential downstream impacts due to this flaw.
Potential Impact
For European organizations, the impact of this vulnerability primarily revolves around data integrity and application reliability. Organizations that utilize UltraJSON for parsing JSON data from external or untrusted sources risk corrupted data structures, which can lead to incorrect application behavior, logic errors, or security issues such as unauthorized data manipulation or denial of service through malformed inputs. This is particularly critical for sectors handling sensitive or regulated data, such as financial services, healthcare, and government agencies, where data integrity is paramount. Additionally, applications that rely on JSON for configuration, inter-service communication, or API responses could experience subtle bugs or failures that are difficult to diagnose. While this vulnerability does not directly lead to remote code execution or privilege escalation, the potential for key confusion and value overwriting could be exploited in complex attack chains or to bypass certain application-level security controls. The lack of known exploits suggests a low immediate threat, but the widespread use of UltraJSON in Python environments means that many European organizations could be affected if they have not updated to the patched version. The vulnerability's medium severity reflects the moderate risk posed by data corruption and the potential for indirect security consequences.
Mitigation Recommendations
The primary and most effective mitigation is to upgrade UltraJSON to version 5.4.0 or later, where the decoding behavior has been corrected to handle lone surrogates safely and consistently with the Python standard library. Organizations should audit their software dependencies to identify usage of UltraJSON versions below 5.4.0, especially in environments processing JSON from untrusted or external sources. For environments where immediate upgrading is not feasible, consider implementing input validation or sanitization layers that detect and reject JSON inputs containing malformed surrogate pairs before they reach the UltraJSON parser. Additionally, developers should review application logic that depends on JSON key uniqueness and integrity to detect anomalies that might arise from corrupted parsing results. Monitoring and logging JSON parsing errors or unexpected dictionary behaviors can help identify exploitation attempts or data corruption. Finally, organizations should incorporate this vulnerability into their software supply chain risk management and vulnerability scanning processes to ensure timely detection and remediation.
For access to advanced analysis and higher rate limits, contact root@offseq.com
Technical Details
- Data Version
- 5.1
- Assigner Short Name
- GitHub_M
- Date Reserved
- 2022-05-18T00:00:00.000Z
- Cisa Enriched
- true
Threat ID: 682d9849c4522896dcbf6686
Added to database: 5/21/2025, 9:09:29 AM
Last enriched: 6/22/2025, 12:23:04 AM
Last updated: 7/28/2025, 5:59:18 PM
Views: 8
Related Threats
CVE-2025-8960: SQL Injection in Campcodes Online Flight Booking Management System
MediumCVE-2025-8958: Stack-based Buffer Overflow in Tenda TX3
HighCVE-2025-8957: SQL Injection in Campcodes Online Flight Booking Management System
MediumCVE-2025-54707: CWE-89 Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') in RealMag777 MDTF
CriticalCVE-2025-54706: CWE-79 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') in Noor Alam Magical Posts Display
MediumActions
Updates to AI analysis are available only with a Pro account. Contact root@offseq.com for access.
External Links
Need enhanced features?
Contact root@offseq.com for Pro access with improved analysis and higher rate limits.