js-cookie Prototype Pollution via __proto__ Attribute Injection (CVE-2026-46625)
The js-cookie library is vulnerable to prototype pollution via the `assign()` function when processing JSON-derived objects, enabling an attacker to inject arbitrary cookie attributes by manipulating the `__proto__` property, as demonstrated by CVE-2026-46625.
The js-cookie library, versions 3.0.5 and earlier, contains a prototype pollution vulnerability (CVE-2026-46625) within its internal assign() function. This function copies properties from source objects to a target object using for...in loops and plain assignment. When processing a source object derived from JSON (e.g., via JSON.parse), the __proto__ member becomes an own enumerable property. The assign function iterates over this property and inadvertently triggers the Object.prototype.__proto__ setter. This results in a per-instance prototype pollution where attacker-controlled keys are inherited by the merged attributes object, allowing modification of cookie attributes.
Attack Chain
- Attacker crafts a JSON payload containing a
__proto__property with malicious cookie attributes (e.g., domain, secure, samesite, expires, path). - The application fetches configuration data from a backend endpoint, parsing the JSON response using
JSON.parse. - The parsed JSON data, containing the attacker’s payload, is passed as the
attributesargument toCookies.set(),Cookies.remove(),Cookies.withAttributes(), orCookies.withConverter(). - The
assign()function withinjs-cookieiterates over the attacker-controlled__proto__property in the source object. - The
target[key] = source[key]assignment triggers theObject.prototype.__proto__setter on the target object. - The attacker-provided cookie attributes are added to the prototype of the merged attributes object.
- The
set()function enumerates the merged object and includes the attacker-injected attributes in theSet-Cookieheader. - The browser receives the
Set-Cookieheader with the attacker-controlled attributes, potentially leading to session hijacking or other security issues.
Impact
Applications that use js-cookie and forward JSON-derived objects as the attributes argument to Cookies.set, Cookies.remove, Cookies.withAttributes, or Cookies.withConverter are vulnerable. This pattern is common when cookie configurations are loaded from backend APIs. Successful exploitation allows attackers to control cookie attributes like domain, secure, and samesite, potentially leading to cross-site scripting (XSS) or session fixation attacks. A sample payload {"__proto__":{"domain":"evil.example","secure":"false","samesite":"None"}} results in cookies being set for the attacker’s domain.
Recommendation
- Upgrade to a patched version of
js-cookiethat addresses the prototype pollution vulnerability. - Apply the patch suggested in the advisory to
src/assign.mjsto prevent the__proto__property from being processed. - Implement input validation to sanitize or reject JSON payloads containing the
__proto__property before they are used as cookie attributes. - Deploy the Sigma rule “Detect Prototype Pollution via JSON proto Attribute in js-cookie” to identify exploitation attempts.
- Review and audit existing code that uses
js-cookieto ensure that JSON-derived objects are not directly passed as cookie attributes.
Detection coverage 2
Detect Prototype Pollution via JSON __proto__ Attribute in js-cookie
highDetects CVE-2026-46625 exploitation — identifies requests where a __proto__ attribute is used to manipulate cookie settings via js-cookie.
Detect js-cookie Set-Cookie with Suspicious Attributes
mediumDetects potentially malicious Set-Cookie headers where the js-cookie library is used to set suspicious cookie attributes.
Detection queries are available on the platform. Get full rules →