Skip to content

context.cookies(url) returns host-only cookies for subdomains #3464

Closed

Description

@Kelvin-Waititu

Bug

context.cookies(url) includes host-only cookies belonging to a parent hostname when filtering for a subdomain.

Confirmed on upstream main at 6f2686d792b7f5836b04754e0f6a44db39928592. This is provider-independent and does not require an LLM.

Minimal reproduction

With an initialized browser:

await browser.context.clearCookies();
await browser.context.addCookies([
  { name: "hostOnly", value: "value", url: "https://example.com/" },
]);

console.log(await browser.context.cookies("https://sub.example.com/"));
// Actual: includes hostOnly
// Expected: []

A deterministic internal reproduction, without launching a browser:

import { filterCookies } from "./packages/extension/understudy/cookies.js";

const cookie = {
  name: "hostOnly",
  value: "value",
  domain: "example.com",
  path: "/",
  expires: -1,
  httpOnly: false,
  secure: false,
  sameSite: "Lax" as const,
};

console.log(filterCookies([cookie], ["https://sub.example.com/"]));
// Actual: [cookie]
// Expected: []

The internal reproduction is verified by regression tests; the browser example illustrates the public API and has not been run against a live browser.

Expected behavior

  • example.com matches only example.com, not sub.example.com or nested subdomains.
  • .example.com matches example.com and its subdomains.
  • Neither matches notexample.com or example.com.other.test.
  • Path and secure filtering retain their existing behavior.

Source and root cause

packages/extension/understudy/cookies.ts, filterCookies, adds a leading dot to host-only domains before suffix matching. That erases the distinction between host-only cookies and domain cookies.

BrowserContext.cookies() in packages/extension/understudy/context.ts calls this helper after retrieving cookies via Storage.getCookies.

I have prepared a focused fix and regression tests. Before filing, I searched issues and PRs across all states for host-only cookies, filterCookies, hostname matching, and subdomain filtering. PR #3212 changes cookie attribute preservation during clearing, not this matching logic.

Activity

  1. added a commit that references this issue on Nov 17, 2026
    9d3cfa5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions