CVE-2026-33228: flatted: Prototype Pollution via parse()
--- Summary
The parse() function in flatted can use attacker-controlled string values from the parsed JSON as direct array index keys, without validating that they are numeric. Since the internal input buffer is a JavaScript Array, accessing it with the key "\\proto\\" returns Array.prototype via the inherited getter. This object is then treated as a legitimate parsed value and assigned as a property of the output object, effectively leaking a live reference to Array.prototype to the consumer. Any code that subsequently writes to that property will pollute the global prototype.
--- Root Cause
File: esm/index.js:29 (identical in cjs/index.js) const resolver = (input, lazy, parsed, $) => output => { for (let ke = keys(output), {length} = ke, y = 0; y < length; y++) { const k = ke[y]; const value = output[k]; if (value instanceof Primitive) { const tmp = input[value]; // Bug is here
No validation that value is a safe numeric index input is built as a plain Array. JavaScript's property lookup on arrays traverses the prototype chain for non-numeric keys. The key "\\proto\\" resolves to Array.prototype, which:
- has type "object" → passes the typeof tmp === object guard at line 30 - is not in the parsed Set yet → passes the !parsed.has(tmp) guard. - The reference to Array.prototype is then enqueued in lazy and later unconditionally assigned to the output object. --- Replication Steps const Flatted = require('flatted'); const parsed = Flatted.parse('[{"x":"proto"}]'); parsed.x.polluted = 'pwned'; console.log([].polluted); // Returns true --- Impact An attacker can supply a crafted flatted string to parse() that causes the returned object to hold a live reference to Array.prototype, enabling any downstream code that writes to that property to pollute the global prototype chain, potentially causing denial of service or code execution.
Recommended solution Validate that the index string represents an integer within the bounds of input before accessing it:
// Before (vulnerable) const tmp = input[value];
// After (safe) const idx = +value; // coerce boxed String → number const tmp = (Number.isInteger(idx) && idx >= 0 && idx < input.length) ? input[idx] : undefined;
Other sources
flatted is a circular JSON parser. Prior to version 3.4.2, the parse() function in flatted can use attacker-controlled string values from the parsed JSON as direct array index keys, without validating that they are numeric. Since the internal input buffer is a JavaScript Array, accessing it with the key "proto" returns Array.prototype via the inherited getter. This object is then treated as a legitimate parsed value and assigned as a property of the output object, effectively leaking a live reference to Array.prototype to the consumer. Any code that subsequently writes to that property will pollute the global prototype. This issue has been patched in version 3.4.2.
— MITRE
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
npm/flattedto a version that resolves this vulnerability.Fixed in 3.4.2 - Upgrade
Upgrade
flattedto a version that resolves this vulnerability.Fixed in 3.4.2 - Configuration
In flatted's resolver used by parse() (esm/index.js:29 and cjs/index.js), change the logic that currently does `tmp = input[value]` (where `value` comes from parsed JSON) to first validate `value` as an integer index within bounds of the input array, and only then access the array (e.g., use `const tmp = (Number.isInteger(idx) && idx >= 0 && idx < input.length) ? input[value] : ...`).
flatted parse() index key validation before accessing input buffer = Validate that the index string represents an integer within bounds (Number.isInteger(idx) && idx >= 0 && idx < input.length) before using it as an array index; do not use the unvalidated array index access `tmp = input[value]` for attacker-controlled `value`.
Event History
Frequently Asked Questions
What is the severity of CVE-2026-33228?
CVE-2026-33228 is rated as a high severity vulnerability due to its potential for prototype pollution attacks.
What is the impact of CVE-2026-33228?
CVE-2026-33228 allows an attacker to manipulate internal JavaScript object structures, potentially leading to denial of service or arbitrary code execution.
How do I fix CVE-2026-33228?
To remediate CVE-2026-33228, upgrade to version 3.4.2 or newer of the flatted package.
Which versions of flatted are affected by CVE-2026-33228?
CVE-2026-33228 affects all versions of flatted prior to 3.4.2.
What kind of attack can exploit CVE-2026-33228?
CVE-2026-33228 can be exploited through prototype pollution via malicious JSON strings passed to the parse() function.