[json-bigint] DoS via `__proto__` assignment
The json-bigint parsing library assigns parsed keys named __proto__ onto objects, which lets a small crafted JSON document confuse the bignumber.js library. An attacker could then make stringification or arithmetic on the parsed result hang, causing a denial of service.
- Fixed in 50 days
- Disclosed after 51 days
I would like to report a DoS in json-bigint.
It allows to cause denial of service using very limited input (~70 bytes).
Module
module name: json-bigint
version: 0.3.1
npm page: https://www.npmjs.com/package/json-bigint
Module Description
JSON.parse/stringify with bigints support. Based on Douglas Crockford JSON.js package and bignumber.js library.
Module Stats
2 301 424 weekly downloads
Vulnerability
Vulnerability Description
Json parsing library assigns to __proto__, which can be abused to confuse bignumber.js library, causing a DoS on various operations with the resulting number (stringification, arithmetic) via a very small input (70 bytes).
Steps To Reproduce:
const JSONbig = require('json-bigint')
const json = '{"__proto__":1000000000000000,"c":{"__proto__":[],"length":1e200}}'
const r = JSONbig.parse(json)
console.log(r.toString())
Note that the object parsed, but an attempt to convert it to a string (or to do any arithmetic operation on it) will hang.
Demo with arithmetic operation hanging:
const JSONbig = require('json-bigint')
const json = '{"__proto__":1000000000000000,"c":{"__proto__":[],"0":42,"length":2}}'
const r = JSONbig.parse(json)
r.dividedBy(42)
Patch
Be careful when assigning to __proto__ value.
Supporting Material/References:
- [OPERATING SYSTEM VERSION]:
Linux xps 5.7.6-arch1-1 #1 SMP PREEMPT Thu, 25 Jun 2020 00:14:47 +0000 x86_64 GNU/Linux
Wrap up
- I contacted the maintainer to let them know: N
- I opened an issue in the related repository: N
Impact
Denial of service via untrusted input.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the parser copies attacker-controlled keys, including __proto__, directly onto objects without guarding against prototype assignment, so the resulting object's prototype is replaced with attacker-chosen values.
Impact
Denial of service via untrusted input: a roughly 70-byte payload can hang stringification or arithmetic on the parsed value.
What the attacker needed
Attacker controls JSON input; application parses it with json-bigint
The fix
The parser should avoid assigning to __proto__ when building objects from parsed input.
How it was found
- Parse a small crafted JSON string containing __proto__ keys with the library.
- Convert the parsed result to a string, which hangs.
- Alternatively call an arithmetic method such as dividedBy on the parsed result, which also hangs.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This library reads JSON text and turns it into JavaScript objects, and it also handles very large numbers. JavaScript objects have a special hidden property called __proto__ that controls how the object behaves; if untrusted input can set it, the object can be bent into an odd shape. Here that odd shape makes the number library loop forever when you print or calculate with the number, so a tiny input can freeze the program.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.