-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The check was a lookup, and the lookup walked the chain\n\nThe vulnerable function is `treatInitial(key, value, result)` in `index.cjs`. It runs once per `FormData` entry. The first segment of the form key drives a three-way branch:\n\n```js\ntreatInitial(key, value, result) {\n const firstMatch = key.match(/^(.+?)(\\[([\\s\\S]+$))/)\n\n if (firstMatch) {\n const inputName = firstMatch[1]\n const rest = firstMatch[2]\n\n let newResult\n\n if (inputName in result) {\n newResult = result[inputName]\n } else if (rest == \"[]\") {\n newResult = []\n result[inputName] = newResult\n } else {\n newResult = {}\n result[inputName] = newResult\n }\n\n this.treatSecond(value, rest, newResult)\n } else {\n result[key] = value\n }\n}\n```\n\nFor a field named `user[name]`, `inputName` is `\"user\"` and `rest` is `\"[name]\"`. The branch picks: is `user` already on `result`? If not, create a new `{}` for it, recurse into it, assign `result[\"user\"][\"name\"] = value`. Standard nested-form handling.\n\nThe `if (inputName in result)` branch is the deduplication path. Two form fields named `user[name]` and `user[email]` should produce `{user: {name: \"...\", email: \"...\"}}`, not two separate `user` objects. The first field creates `result[\"user\"] = {}` and recurses into it. The second field finds `\"user\"` already on `result`, reuses the existing `{}`, and recurses into the same target. The `in` operator is the gate that decides which of those two branches runs.\n\nThe JavaScript `in` operator does not check own properties. It walks the prototype chain. Every plain object in V8 inherits from `Object.prototype`, which carries twelve own properties:\n\n```\nconstructor isPrototypeOf toLocaleString\nhasOwnProperty propertyIsEnumerable toString\nvalueOf __proto__ __defineGetter__\n__defineSetter__ __lookupGetter__ __lookupSetter__\n```\n\n`in` returns `true` for each of them, against any plain object, on the first call after construction.\n\nFor `inputName = \"__proto__\"`:\n\n- `\"__proto__\" in result` returns `true` because `Object.prototype` declares `__proto__` as an accessor.\n- `newResult = result[\"__proto__\"]`. On a plain object, that accessor returns the object's actual prototype, which is `Object.prototype` itself.\n- `this.treatSecond(value, \"[polluted]\", Object.prototype)` runs against the global prototype.\n\nThe check that was supposed to detect duplicate top-level keys handed the recursion a reference to `Object.prototype`.\n\n## The recursion wrote it\n\n`treatSecond` pulls the next segment from `rest` and decides whether to assign or descend:\n\n```js\ntreatSecond(value, rest, result) {\n const secondMatch = rest.match(/^\\[(.*?)\\]([\\s\\S]*)$/)\n const key = secondMatch[1]\n const newRest = secondMatch[2]\n\n let newResult\n\n if (rest == \"[]\") {\n result.push(value)\n } else if (newRest == \"\") {\n result[key] = value\n } else {\n if (typeof result == \"object\" && key in result) {\n newResult = result[key]\n } else if (newRest == \"[]\") {\n newResult = []\n result[key] = newResult\n } else {\n newResult = {}\n result[key] = newResult\n }\n\n this.treatSecond(value, newRest, newResult)\n }\n}\n```\n\nWith `result = Object.prototype`, `key = \"polluted\"`, `newRest = \"\"`:\n\n```js\nresult[key] = value\n// equivalent to\nObject.prototype.polluted = value\n```\n\nThe library performs the write the form field named. Running the unpatched library on the package's own test harness:\n\n```js\nconst F = require(\"./index.cjs\");\nconst fd = { entries: () => [[\"__proto__[polluted]\", \"pwned\"]] };\nF.toObject(fd);\nconsole.log({}.polluted, [].polluted);\n// pwned pwned\n```\n\nEvery plain object in the process inherits `polluted` from `Object.prototype` for the rest of the process's lifetime. Every array, too: arrays inherit from `Array.prototype`, which inherits from `Object.prototype`. Every `Map`, `Set`, `Date`, and `Error` instance. The pollution is process-wide and survives until the process exits.\n\nOne HTTP form field. The library never wrote `__proto__`; the language wrote it for them.\n\n## The diff picks both readings of the bug\n\nThe patch for CVE-2026-46510 landed in commit `7c54b99` on 9 May 2026, merged from a fork by reporter Mohamed Bassia. Two changes, one commit, both targeting the same bug:\n\n```diff\n- if (inputName in result) {\n+ if (hasOwn(result, inputName)) {\n newResult = result[inputName]\n```\n\n```diff\n+ assertSafeKeySegment(inputName)\n+\n let newResult\n```\n\nEither change alone closes the path.\n\nSwap `in` for `Object.prototype.hasOwnProperty.call`, and `hasOwn(result, \"__proto__\")` returns `false` on a fresh object, because `__proto__` is inherited, not own. The branch falls through to `result[inputName] = {}`, which on a plain object assigns through the `__proto__` setter and replaces the object's actual prototype with a fresh empty object. The recursion writes into the empty object, not into `Object.prototype`. Pollution closed.\n\nAdd the explicit blocklist, and the function throws on `__proto__`, `constructor`, and `prototype` before the lookup runs. Pollution closed.\n\nThe maintainer chose both. The two changes encode two different theses about what the original code got wrong. The blocklist treats `__proto__`/`constructor`/`prototype` as a closed enumeration of dangerous names. The `hasOwnProperty` swap treats `in` as the wrong operator. The first reads CVE-2026-46510 as \"these three names are special.\" The second reads it as \"this membership check was the wrong tool.\" They are not the same patch. Shipping both is shipping both readings.\n\nThe commit message says \"Fix prototype pollution in form keys.\" The diff fixes that, and one other thing the commit message does not mention.\n\n## This is Object Literal As Map\n\nThe result container is `{}`. The keys are attacker-controlled. The membership check uses `in`. That shape has a name on this blog: [Object Literal As Map](/patterns/object-literal-as-map). The canonical exhibit is [multiparty (CVE-2026-8161)](/posts/multiparty-cve-2026-8161-object-literal-as-map), where a 2013 line of code initialized `var fields = {}` and read `fields[name]` with `name` coming from a multipart form field. Each of the twelve `Object.prototype` keys returned a non-undefined inherited value, the `||` short-circuit picked the inherited value over the new-array fallback, `.push()` ran on a non-array (the `toString` function), and the process exited.\n\nMultiparty's read leaked the prototype chain into a crash. form-data-objectizer's read leaks the prototype chain into a write. The mechanisms diverge after the lookup. The root cause is identical: a JavaScript map built on `{}` whose membership is queried against attacker input without `hasOwnProperty`. Both libraries fixed the leak with the same swap. Both libraries' result containers are still `{}` in their patched releases. `Object.create(null)` and `Map` continue to exist, and they continue to be the constructions that would make this bug class structurally impossible. The npm ecosystem continues to reach for `{}`.\n\nThe downstream half of this attack is [Prototype Pollution Trust Bypass](/patterns/prototype-pollution-trust-bypass). [CVE-2026-34621](/posts/adobe-acrobat-cve-2026-34621-pdf-weaponizer) is what happens when a privilege gate reads properties off objects whose prototypes an attacker has poisoned. form-data-objectizer is what produces the poison. Any Node.js application that calls `FormDataObjectizer.toObject(req.body)` and runs a trust check anywhere downstream that reads `someObject.admin` or `someObject.role` against an object built from JSON or query parameters is one HTTP form POST from inheriting an attacker-chosen role. The form-data-objectizer half installs the value on `Object.prototype`; the Acrobat-style gate reads it as own-property-or-inherited and waves the call through.\n\n## The other test the CVE forced\n\nThe patch's spec file adds five new test cases. Four assert that the three dangerous segments throw. The fifth asserts something different:\n\n```js\nit(\"parses inherited non-reserved names as own properties\", () => {\n const formData = formDataWithEntries([[\"toString[value]\", \"yes\"]])\n\n const object = FormDataObjectizer.toObject(formData)\n\n expect(object).toEqual({\n toString: {\n value: \"yes\"\n }\n })\n})\n```\n\nThis is not a security test. It is a correctness test. It asserts that a form field named `toString[value]` produces `{toString: {value: \"yes\"}}`.\n\nBefore the patch, the field did not produce that output. Running version 1.0.0 against the same input:\n\n```js\nconst F = require(\"./index.cjs\");\nconst fd = { entries: () => [[\"toString[value]\", \"yes\"]] };\nconsole.log(F.toObject(fd));\n// {}\n```\n\nThe output is the empty object. `\"toString\" in {}` returns `true` because `Object.prototype.toString` is inherited. `result[\"toString\"]` returns the `toString` function. `treatSecond(\"yes\", \"[value]\", function toString() {...})` assigns `.value = \"yes\"` to the function object and returns. The result object never receives a `toString` key. The form field is silently dropped on the floor.\n\nThe same is true for `valueOf[x]`, `hasOwnProperty[x]`, `constructor[x]`, `isPrototypeOf[x]`, and the seven other inherited names. Every one of them was a silently broken top-level form field name in version 1.0.0. `index.cjs` shipped its first commit on 15 February 2021. Every form between then and 9 May 2026 that carried a top-level field named after an `Object.prototype` property was parsed into the wrong object, with no error, no warning, and no test catching it. A consumer's `models` field passing through unaffected, their `toString` field vanishing without trace.\n\nThe maintainer wrote the test for that on 9 May 2026 because the prototype pollution disclosure forced the patch, and the patch's `in` → `hasOwnProperty` swap closed both the CVE and the correctness bug, and the new test verifies that the swap closed the correctness bug. The CVE produced the test for a five-year-old data-loss bug that had nothing to do with security.\n\n## What `name in result` meant\n\nThe author wrote `if (inputName in result)` to mean \"is this field already part of the result so far?\" That is not what JavaScript means by `inputName in result`. JavaScript means \"does this name resolve to a non-undefined value through the prototype chain starting at `result`?\" The two sentences read the same in English. They produce different programs.\n\nThe two sentences also pin different mitigations. The first mitigation, the one the author thought they were writing, is `Object.prototype.hasOwnProperty.call(result, inputName)` and was added to the diff. The second mitigation, the one the JavaScript language actually wanted, is to stop using `{}` as a map for attacker-controlled keys and reach for `Object.create(null)` or `Map`. The first mitigation closes the demonstrated chain. The second closes the bug class.\n\nEvery npm package that uses `{}` as a string-keyed map against caller-supplied keys is one careless `in` away from CVE-2026-46510. The patch swaps the operator. The container stays `{}`. The next consumer who reaches for `in` to mean \"has this key been set on this map\" inherits the same five-year shipping path.\n\nPoC: [advisories/GHSA-m2hg-wjq3-28wq](https://github.com/advisories/GHSA-m2hg-wjq3-28wq)","closing_line":"The line shipped on 15 February 2021 and was rewritten on 9 May 2026. Nothing about the `in` operator's semantics changed in between.","hook_md":"form-data-objectizer is an npm package that converts a `FormData` instance into a plain JavaScript object. It supports Rails-style bracket notation: a field named `user[name]` becomes `{user: {name: \"...\"}}`. The parser walks the path one segment at a time. Before it descends into the first segment, it asks whether the result object already has that segment. In version 1.0.0, line 45 of `index.cjs` asks the question with the JavaScript `in` operator.\n\nThe `in` operator walks the prototype chain. `\"__proto__\" in {}` returns `true` on a fresh plain object with no prior writes. Every form field whose first segment is `__proto__` is a write into `Object.prototype`. That is CVE-2026-46510.","post_id":564,"slug":"form-data-objectizer-cve-2026-46510-in-walks-the-prototype-chain","title":"CVE-2026-46510: form-data-objectizer Checked Map Membership With `in`. The `in` Operator Walks The Prototype Chain.","type":"initial","unreadable_sentence":"The CVE produced the test for a five-year-old data-loss bug that had nothing to do with security."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaqwh+gAKCRDeZjl4jgkQ JriJAP9/YtNc5szOmDT1fpN8nft/RN1HnCnUYBP5qykOEddiWAEAy10NSpbCi0fy Bpy5lZvPV5MUXeqC8DKO60fout4qIw8= =wNUF -----END PGP SIGNATURE-----