-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## `target[key] = source[key]` is not always a write\n\nThe vulnerable function in CVE-2026-46625 is `assign` in `src/assign.mjs`. The unpatched body, five lines including braces:\n\n```js\nexport default function (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i]\n for (var key in source) {\n target[key] = source[key]\n }\n }\n return target\n}\n```\n\n`assign` is called once per `Cookies.set()` invocation, from `src/api.mjs`:\n\n```js\nattributes = assign({}, defaultAttributes, attributes)\n```\n\n`target` is a fresh `{}`. `defaultAttributes` is the library's `{path: '/'}` constant. The third argument is whatever the caller passed for cookie attributes.\n\nFor a caller who builds the third argument with object-literal syntax, like `Cookies.set('session', token, {expires: 7, secure: true})`, the merge is uneventful. The for-loop iterates `expires` and `secure`. The writes are plain data assignments against `target`. The merged object is the union of own data properties.\n\nFor a caller who hands `assign` an object built by `JSON.parse` against untrusted input, the loop is governed by a property of the JavaScript language that the developer almost certainly did not have in mind when they wrote `target[key] = source[key]`. The bracket-assignment operator is not always a plain write. When the key is the string `__proto__` and the target's prototype chain includes `Object.prototype`, the operator invokes a setter. The setter does not store the key. It replaces the target's prototype with the value.\n\n## JSON.parse keeps `__proto__`. Object literals do not.\n\nObject-literal syntax treats `__proto__` as a directive. The expression `{__proto__: x}` constructs an object whose `[[Prototype]]` is `x`; the result has no own property named `__proto__` afterward. ECMA-262 specifies the behavior at the grammar level under `PropertyDefinition`. It is a feature of the object initializer, not a property write.\n\nJSON has no concept of prototypes. The grammar accepts `__proto__` as a string-quoted member name in an object value, no different from any other quoted name. `JSON.parse` materializes the result by walking the parse tree and writing each member as an own data property of the resulting object. The string `__proto__` survives the walk:\n\n```js\n> Object.getOwnPropertyNames({__proto__: {x: 1}})\n[]\n> Object.getOwnPropertyNames(JSON.parse('{\"__proto__\":{\"x\":1}}'))\n[ '__proto__' ]\n```\n\nThe two parsers produce different objects from inputs the human eye reads as similar. A library that consumes the output of both, as `js-cookie` does the moment a caller passes a JSON-parsed configuration object, has to behave the same way under both. The `for (var key in source)` loop in `assign` enumerates the own enumerable properties of `source` plus its inherited enumerable ones. For a JSON-parsed source, the enumeration includes the string `__proto__`. For an object-literal source, it does not.\n\n## `target.__proto__ = X` is a setter call\n\n`target[key] = source[key]` is not a write when `key` is `__proto__`. It is a setter call that replaces the target's prototype.\n\n`target` is a fresh `{}`. Its prototype chain ends at `Object.prototype`. `Object.prototype` declares `__proto__` as an accessor pair, with a getter that returns the object's `[[Prototype]]` and a setter that delegates to `Object.setPrototypeOf` against the receiver. Every plain object in the runtime inherits the accessor.\n\nThe expression `target[key] = source[key]`, where `key` is the string `\"__proto__\"`, runs through the language's `[[Set]]` semantics. `[[Set]]` walks the prototype chain looking for an existing accessor. It finds the `__proto__` setter on `Object.prototype` and calls it. The setter does not store an own property named `__proto__` on `target`. It calls `Object.setPrototypeOf(target, source[\"__proto__\"])`. The merge target's prototype is replaced with whatever the attacker placed under `__proto__` in the JSON string.\n\nThis is the sentence in the CVE-2026-46625 description that reads \"Object.prototype itself is untouched.\" It is precisely accurate. No write occurred against any shared object. `Object.prototype.foo` is still undefined. `({}).foo` on any freshly constructed object literal anywhere else in the process is still undefined. What changed is the prototype of one specific object: the merged attributes object that `set` is about to iterate.\n\n## The serializer walks the prototype back out\n\nThe next several lines of `set` build the Set-Cookie attribute string:\n\n```js\nvar stringifiedAttributes = ''\nfor (var attributeName in attributes) {\n if (!attributes[attributeName]) {\n continue\n }\n\n stringifiedAttributes += '; ' + attributeName\n\n if (attributes[attributeName] === true) {\n continue\n }\n\n stringifiedAttributes += '=' + attributes[attributeName].split(';')[0]\n}\n```\n\n`for (var attributeName in attributes)` enumerates own enumerable AND inherited enumerable properties of its target. `attributes` is the merged object. Its `[[Prototype]]` is now the attacker's object. Every enumerable key the attacker placed on that object is reachable through `attributes` by inheritance.\n\nThe loop body cannot tell the difference between an own property the developer wrote and an inherited property the attacker installed via the setter. It iterates both. It appends each as `'; ' + attributeName + '=' + value`. The Set-Cookie header carries both.\n\nThe two for-loops in the call path do the same thing in opposite directions. The first walks the prototype chain into the merge, picking up `__proto__` as an own enumerable key from the JSON-parsed source. The second walks the prototype chain out of the merge, picking up the keys the attacker hung off the new prototype. The library iterates the prototype on the way in. It iterates the prototype on the way out. The setter in the middle does the trade.\n\n## What the attacker writes lands in the header\n\nThe payload shape the CVE-2026-46625 description sketches:\n\n```json\n{\"__proto__\":{\"domain\":\"evil.example.com\",\"samesite\":\"None\"}}\n```\n\nRun through the unpatched library, with `Cookies.set('c', 'v', JSON.parse(payload))`:\n\n```js\n> const merged = assign({}, {path: '/'}, JSON.parse(payload))\n> Object.getOwnPropertyNames(merged)\n[ 'path' ]\n> Object.getOwnPropertyNames(Object.getPrototypeOf(merged))\n[ 'domain', 'samesite' ]\n```\n\nThe serializer iterates `path`, `domain`, `samesite`. Each value is non-empty. Each gets appended.\n\n```\nSet-Cookie: c=v; path=/; domain=evil.example.com; samesite=None\n```\n\nThe browser receives the wire format and stores the cookie with the attributes the wire format declares. Browser cookie storage cannot distinguish the application's intended attributes from the attacker's inherited ones; both arrived in the same string from the same origin.\n\nThe CVE description names five attributes the attacker can choose: `domain`, `secure`, `samesite`, `expires`, `path`. The choice set is whatever the browser's cookie attribute grammar accepts as a key-value pair. `domain=` widens the cookie's reach to any parent or sibling domain the attacker can read. `samesite=None` removes a CSRF mitigation the application explicitly opted into. `expires=Thu, 01 Jan 1970 00:00:00 GMT` clobbers the cookie out of existence at the browser. Each is a string under an attacker-chosen key in JSON. Each is a Set-Cookie attribute on the wire.\n\n## The patch had to fit inside the loop\n\nThe fix for CVE-2026-46625, commit `eb3c40e`, merged on 15 May 2026:\n\n```diff\n for (var key in source) {\n+ if (key === '__proto__') continue\n target[key] = source[key]\n }\n```\n\nThe diff blocks the exact key the setter cares about. It does not block `constructor`. It does not block `prototype`. It does not change `target = {}` to `Object.create(null)`. It does not replace the `for...in` with `Object.keys(source).forEach`. The commit message explains why:\n\n> Note that at the moment we're tied to using this kind of for-loop for compatibility with IE 10 + 11.\n\nInternet Explorer 10 stopped receiving security updates from Microsoft in January 2016. Internet Explorer 11's desktop client was retired on 15 June 2022. The commit landed on 15 May 2026, four years after Microsoft pulled the browser the loop is shaped around. js-cookie served 26.5 million weekly downloads from the npm registry in the week before this post. In 2026, the merge helper in a library at that fan-out is shaped at the line level by a browser whose last release shipped in 2013.\n\nThe constraint pins the patch to the only place it could live without breaking IE 11. `Object.create(null)` is supported in IE 9. `Object.entries` is not. `for...in` is. The maintainer chose the smallest change consistent with the compatibility matrix. The smallest change is a one-key blocklist against the one key the disclosed payload sends. The previous commit to touch `src/assign.mjs`, `0f293a6`, dated 12 December 2019, is titled \"Turn `extend()` into `assign()`,\" and its commit body reads: \"The assign method is supposed to behave similar to `Object.assign()` (which we can't use due to IE support).\" Six and a half years between the two commits. The IE constraint outlived IE.\n\n`constructor` is also an own enumerable property after `JSON.parse('{\"constructor\":{\"domain\":\"x\"}}')`. The assignment `target.constructor = X` does not invoke a setter (constructor on `Object.prototype` is a plain data property, not an accessor), so the merge target's prototype is unchanged. But it does install a new own property `constructor` on `target`, which the downstream for-loop will then enumerate and serialize as `; constructor=[object Object]`. Browsers ignore the unknown attribute. The hazard is narrower than `__proto__`'s. The merge helper still does not know which keys carry special meaning, in JavaScript or in the cookie attribute grammar.\n\n## This is Object Literal As Map, from the write side\n\nThis blog has a name for `{}` as a string-keyed container under attacker-controlled keys: [Object Literal As Map](/patterns/object-literal-as-map). The canonical exhibits read from the container. multiparty's `fields[name] || (fields[name] = [])` in [CVE-2026-8161](/posts/multiparty-cve-2026-8161-object-literal-as-map) is a property read that walks the prototype chain into a crash. form-data-objectizer's `if (inputName in result)` in [CVE-2026-46510](/posts/form-data-objectizer-cve-2026-46510-in-walks-the-prototype-chain) is a membership check that walks the prototype chain into a recursive write back into `Object.prototype` itself.\n\njs-cookie's `target[key] = source[key]` is the same pattern from the write side. The container is `{}`. The keys are attacker-controlled. The write at `__proto__` invokes a setter that replaces the container's prototype. The downstream consumer's for-loop walks the prototype the setter installed and serializes its keys onto the wire. The leak runs between iteration and inheritance, in both directions of the merge.\n\nThe three CVEs cluster around the same root cause and reach for the same three escapes: `Object.create(null)` for the container, `hasOwnProperty.call` for the membership read, an explicit blocklist for the key. multiparty chose the read gate. form-data-objectizer chose the read gate. js-cookie chose the blocklist. The container is `{}` in all three patched releases. The merge helper, the parser, and the result jar continue to ship the prototype chain to user code as if it were data.\n\nPoC: [GHSA-qjx8-664m-686j](https://github.com/advisories/GHSA-qjx8-664m-686j)","closing_line":"Object.prototype was untouched. The cookie's domain still moved.","hook_md":"The patch for CVE-2026-46625 adds one line to js-cookie's five-line `assign` helper: `if (key === '__proto__') continue`, inside the `for (var key in source)` loop the helper uses to merge cookie attributes. The CVE description ends with the sentence \"Object.prototype itself is untouched.\" The commit message names the bug as \"prototype pollution.\" The two statements are not in conflict; they describe the same write, observed from different sides of the merge target.","post_id":659,"slug":"js-cookie-cve-2026-46625-merge-target-got-a-new-prototype","title":"CVE-2026-46625: js-cookie's Merge Target Got a New Prototype. Object.prototype Was Untouched.","type":"initial","unreadable_sentence":"`target[key] = source[key]` is not a write when `key` is `__proto__`. It is a setter call that replaces the target's prototype."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaxWiogAKCRDeZjl4jgkQ JmZkAQD93fDqEMRn8UeskZm1dgCjFuGHp9Hj4DiLr/paYA0M7AD/RAy4oRQxrAMI +byeNZFq+gf44juAqTsb0XiRQKn/Wwg= =E/ro -----END PGP SIGNATURE-----