Skip to content

fix: RFC 6265 domain matching in Chrome cookies capability#84

Merged
graydawnc merged 1 commit intomainfrom
fix/cookies-rfc6265-domain-match
Apr 15, 2026
Merged

fix: RFC 6265 domain matching in Chrome cookies capability#84
graydawnc merged 1 commit intomainfrom
fix/cookies-rfc6265-domain-match

Conversation

@graydawnc
Copy link
Copy Markdown
Collaborator

Summary

Chrome cookie lookup used a host_key LIKE '%.${host}' suffix match, which missed parent-domain cookies whenever the request URL used a subdomain. Replaced with proper RFC 6265 §5.1.3 matching via enumerated host_key IN (...).

Why it matters

Any connector querying cookies on a subdomain URL was silently returning incomplete cookie sets. Concrete repro with Reddit:

  • .reddit.com is where reddit_session, token_v2, etc. actually live in Chrome's store
  • Querying https://www.reddit.com built pattern %.www.reddit.com → missed .reddit.com entirely → connector reported AUTH_NOT_LOGGED_IN even when the user was logged in
  • Twitter happened to work only because twitter-bookmarks queries https://x.com (already apex)

Change

  • New pure helper getMatchingHostKeys(host): returns [host, '.host', '.parent', '.grandparent', ...] stopping before bare TLDs. Handles leading dots, case-insensitivity, and empty / single-label inputs.
  • queryAllCookiesForDomainqueryAllCookiesForHost: uses host_key IN (?, ?, ...) instead of a LIKE pattern.
  • Unit tests cover the matching rules (apex, subdomain, deep subdomain, TLD guard, casing, leading dot, single-label).

Verification

  • pnpm --filter @spool/core test — 147 passed, 1 skipped (integration requiring Chrome env var)
  • Live probe against actual Chrome DB confirmed both https://reddit.com (10 cookies) and https://www.reddit.com (14 cookies) now return reddit_session correctly

Not in scope

Reddit connector is still pinned to https://reddit.com (apex) since that's what shipped in npm 0.1.0 and it works with both old and new capability. Future connectors can freely use subdomain URLs.

🤖 Generated with Claude Code

The previous implementation built a `LIKE '%.${host}'` pattern, which
only matched cookie host_keys that end in the full request hostname.
Cookies set with an explicit parent Domain attribute (e.g.
`.reddit.com`) were missed when the request URL used a subdomain
(`https://www.reddit.com`), because `.reddit.com` does not end in
`.www.reddit.com`.

Replace with proper RFC 6265 §5.1.3 matching: enumerate all valid
host_key values for a given request host (self host-only, self with
leading dot, each parent domain with leading dot — stopping before bare
TLDs) and query with `IN (...)`.

Verified live against Chrome cookie DB:
- https://reddit.com → 10 cookies, reddit_session present
- https://www.reddit.com → 14 cookies, reddit_session present (includes
  extra host-only cookies on www.reddit.com, correctly excluded from
  the apex query)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@graydawnc graydawnc merged commit 785de5e into main Apr 15, 2026
3 checks passed
@graydawnc graydawnc deleted the fix/cookies-rfc6265-domain-match branch April 15, 2026 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant