CVE-2022-31116
JSON

7.5high

Incorrect handling of invalid surrogate pair characters in ujson

Severity
7.5high CVSS:3.1 by GitHub_M
Exploit likelihood
2.54% (higher than 85% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-wpqr-jcpx-745rPYSEC-2026-1057

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.

Affected

Product or packageVersionsReported by
ultrajson ultrajson< 5.4.0CVE List
ujson (PyPI)before 5.4.0GitHub Advisory Database, PyPA Advisory Database
ultrajson_project ultrajsonbefore 5.4.0NVD
fedoraproject fedora35, 36NVD

All scores

GitHub_M7.5high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
GitHub7.5high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NVD7.5high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
NVD5.0medium CVSS:2.0AV:N/AC:L/Au:N/C:N/I:N/A:P
PyPA Advisory Database7.5high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

Classification

CWE-670

SSVC (CISA-ADP): exploitation poc, automatable yes, technical impact partial.

What each source says

CVE List

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.

GitHub Advisory Database
Impact

What kind of vulnerability is it? Who is impacted?

Anyone parsing JSON from an untrusted source is vulnerable.

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.

Examples:

# An unpaired high surrogate character is ignored.
>>> ujson.loads(r'"\uD800"')
''
>>> ujson.loads(r'"\uD800hello"')
'hello'

# An unpaired low surrogate character is preserved.
>>> ujson.loads(r'"\uDC00"')
'\udc00'

# A pair of surrogates with additional non surrogate characters pair up in spite of being invalid.
>>> ujson.loads(r'"\uD800foo bar\uDC00"')
'foo bar𐀀'
Patches

Has the problem been patched? What versions should users upgrade to?

Users should upgrade to UltraJSON 5.4.0.

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:

>>> ujson.loads(r'"\uD800"')
'\ud800'
>>> ujson.loads(r'"\uD800hello"')
'\ud800hello'
>>> ujson.loads(r'"\uDC00"')
'\udc00'
>>> ujson.loads(r'"\uD800foo bar\uDC00"')
'\ud800foo bar\udc00'
Workarounds

Is there a way for users to fix or remediate the vulnerability without upgrading?

Short of switching to an entirely different JSON library, there are no safe alternatives to upgrading.

For more information

If you have any questions or comments about this advisory:

NVD (es)

UltraJSON es un codificador y decodificador JSON rápido escrito en C puro con enlaces para Python versiones 3.7+.&#xa0;Se encontró que las versiones afectadas descodificaban incorrectamente determinados caracteres.&#xa0;Las cadenas JSON que contienen caracteres suplentes escapados que no forman parte de un par suplente adecuado se decodificaron incorrectamente.&#xa0;Además de corromper las cadenas, esto permitió una posible confusión de claves y sobrescritura de valores en los diccionarios.&#xa0;Todos los usuarios que analizan JSON de fuentes que no son de confianza son vulnerables.&#xa0;A partir de la versión 5.4.0, UltraJSON decodifica sustitutos solitarios de la misma manera que lo hace el módulo "json" de la biblioteca estándar, conservándolos en la salida analizada.&#xa0;Se recomienda a los usuarios que actualicen.&#xa0;No se conocen mitigaciones adicionales para este problema

References

https://github.com/ultrajson/ultrajson/security/advisories/GHSA-wpqr-jcpx-745rexploit, third-party-advisory, web
https://github.com/ultrajson/ultrajson/commit/67ec07183342589d602e0fcf7bb1ff3e19272687patch, third-party-advisory, web
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/OPPU5FZP3LCTXYORFH7NHUMYA5X66IA7/vendor-advisory
https://lists.fedoraproject.org/archives/list/package-announce%40lists.fedoraproject.org/message/NAU5N4A7EUK2AMUCOLYDD5ARXAJYZBD2/vendor-advisory
https://nvd.nist.gov/vuln/detail/CVE-2022-31116advisory
https://github.com/ultrajson/ultrajsonpackage
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/NAU5N4A7EUK2AMUCOLYDD5ARXAJYZBD2web
https://lists.fedoraproject.org/archives/list/package-announce@lists.fedoraproject.org/message/OPPU5FZP3LCTXYORFH7NHUMYA5X66IA7web
https://pypi.org/project/ujsonpackage
https://github.com/advisories/GHSA-wpqr-jcpx-745radvisory

Sources

SourceRecordLicence
CVE ListCVE-2022-31116 changed 2025-04-22CVE Terms of Use
GitHub Advisory DatabaseGHSA-wpqr-jcpx-745r changed 2026-07-07CC-BY-4.0
NVDCVE-2022-31116 changed 2026-06-17Public domain
PyPA Advisory DatabasePYSEC-2026-1057 changed 2026-07-07CC-BY-4.0