Repository navigation
Description
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.commatches onlyexample.com, notsub.example.comor nested subdomains..example.commatchesexample.comand its subdomains.- Neither matches
notexample.comorexample.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
[Claimed browserbase#3465] fix(extension): respect host-only cookie d…