Skip to content

fix(browser): import __Host- cookies host-only so Chromium keeps them - #12166

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/fix-browser-cookies-expiring
Aug 3, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/fix-browser-cookies-expiring

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

Summary

The cookie file/JSON import path (importValidatedCookies) passed a domain attribute for every cookie. Chromium rejects any __Host--prefixed cookie that carries a Domain attribute — the __Host- prefix requires the cookie to be host-only, path=/, and Secure. As a result, importing a cookie file silently dropped __Host- session cookies (e.g. GitHub's __Host-user_session_same_site), so users stayed logged out after importing.

The browser-native import path already shapes __Host- cookies host-only; this brings the file/JSON import path to parity: when the cookie name starts with __Host-, omit domain and force path=/. Normal cookies are unchanged.

Screenshots

No visual change.

Testing

  • pnpm lint — exit 0 (oxlint + native/type-aware code-quality audits + verify steps)
  • pnpm typecheck — exit 0 (all three tsconfig projects)
  • pnpm test — the changed file's suite passes 26/26. The full local suite shows failures only in unrelated, environment-sensitive files (pty.test.ts, codex-accounts/runtime-home-service.test.ts, codex/codex-real-home-path.test.ts, check-root-directory-entries, relay/daemon socket tests). These key off real HOME/ORCA_* env and local filesystem state, the failing set varies run-to-run, and none touch cookie import. They reproduce identically without this change (those files are untouched here); CI's clean environment is the authoritative gate.
  • pnpm build — not run locally (packaging is unaffected by this logic-only change); CI covers it
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

Added a regression test that imports a __Host- cookie alongside a normal domain cookie in one file and asserts the __Host- cookie is set with no domain and path=/, while the normal cookie keeps its .domain.

AI Review Report

Reviewed the diff with an AI coding agent. Main risks checked:

  • Parity with the browser-native path — the same __Host- shaping already exists there; this makes the file/JSON path consistent rather than inventing new behavior.
  • Normal cookies unaffected — only names starting with __Host- skip the domain/override path; the test asserts a normal cookie still receives .github.com.
  • Detection correctness — __Host- is matched by name prefix, matching Chromium's prefix rule.

Cross-platform: this is pure main-process cookie-shaping logic with no keyboard shortcuts, UI labels, filesystem paths, shell invocation, or Electron platform-specific APIs. Behavior is identical on macOS, Linux, and Windows.

Security Audit

Cookie import already validates each entry (validateCookieEntry) and strips non-printable bytes before cookies.set. This change only removes the domain attribute (and forces path=/) for __Host--named cookies — it does not broaden what can be imported, add command/path execution, touch IPC, or expose secrets. If anything it enforces the stricter host-only scoping the __Host- prefix is designed to guarantee. No follow-up needed.

Notes

importValidatedCookies is the shared file/JSON import path (Settings "Import Cookies from file" and JSON import entrypoints). The browser-native import path already had this handling, so no change was needed there.

The cookie file/JSON import path passed a Domain attribute for every
cookie. Chromium rejects any __Host--prefixed cookie that carries a
Domain (the prefix requires host-only, path=/, Secure), so file import
silently dropped session cookies like GitHub's __Host-user_session_same_site
and users stayed logged out after importing.

Mirror the browser-native import path, which already shapes __Host-
cookies host-only: omit domain and force path=/ when the name is
__Host--prefixed. Add a regression test covering both a __Host- cookie
and a normal domain cookie in one import.
@greptile-apps

greptile-apps Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes a bug where importing cookies from a file silently dropped __Host--prefixed cookies (e.g., GitHub's __Host-user_session_same_site) because Chromium rejects any __Host- cookie that carries a domain attribute. The file/JSON import path (importValidatedCookies) previously set domain on every cookie; now it omits domain and forces path=/ for __Host--named cookies, matching the behavior already present in the browser-native import path.

  • browser-cookie-import.ts: In importValidatedCookies, checks cookie.name.startsWith('__Host-') and conditionally spreads domain and hard-codes path=/ for host-prefixed cookies; normal cookies are unchanged.
  • browser-cookie-import.test.ts: Adds a regression test that imports one __Host- cookie and one normal cookie in the same file, asserting the host-prefixed cookie has no domain property and path='/', while the normal cookie retains its original domain and path.

Confidence Score: 5/5

Safe to merge — the change is narrow, well-tested, and brings the file/JSON import path to parity with the already-correct browser-native path.

The logic is simple and self-contained: a two-line conditional that omits domain and forces path=/ only for cookies whose name starts with __Host-. The validateCookieEntry guard upstream ensures cookie.domain is always a non-empty string, so the downstream domain-summary code at line 585 remains safe even for host-prefixed cookies. The regression test covers both the new __Host- behavior and the invariant that normal cookies are not affected.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/main/browser/browser-cookie-import.ts Adds __Host- prefix detection in importValidatedCookies to omit domain and force path=/ — correct per RFC 6265bis; normal cookies and downstream domain-summary logic are unaffected.
src/main/browser/browser-cookie-import.test.ts New regression test correctly validates __Host- host-only shaping and that a sibling normal cookie keeps its original domain and path.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[importValidatedCookies] --> B[For each ValidatedCookie]
    B --> C{cookie.name startsWith '__Host-'?}
    C -- Yes --> D[isHostPrefixed = true]
    C -- No --> E[isHostPrefixed = false]
    D --> F["cookies.set({ url, name, value, path: '/', secure, httpOnly, ... })"]
    E --> G["cookies.set({ url, name, value, domain: cookie.domain, path: cookie.path, secure, httpOnly, ... })"]
    F --> H[Chromium accepts cookie as host-only]
    G --> I[Chromium accepts cookie as normal domain cookie]
    H --> J[domainSet tracking via cookie.domain]
    I --> J
Loading

Reviews (3): Last reviewed commit: "test(browser): preserve ordinary cookie ..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6f9f618b-1d8a-41b4-a70d-1af17378ae3a

📥 Commits

Reviewing files that changed from the base of the PR and between f6c9d75 and c6980ed.

📒 Files selected for processing (1)
  • src/main/browser/browser-cookie-import.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/browser/browser-cookie-import.test.ts

📝 Walkthrough

Walkthrough

Cookie imports now handle __Host- cookies as host-only cookies. They omit the domain and force the path to /. Standard cookies retain their configured domain and path. Tests cover both behaviors.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: importing __Host- cookies as host-only for Chromium compatibility.
Description check ✅ Passed The description covers the required sections, testing status, regression coverage, AI review, security audit, and cross-platform review.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ac91407a-28c9-495e-bf66-90a83ce4bc6c

📥 Commits

Reviewing files that changed from the base of the PR and between 95c431f and 6147963.

📒 Files selected for processing (2)
  • src/main/browser/browser-cookie-import.test.ts
  • src/main/browser/browser-cookie-import.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron validation

Validated final head c6980ed in an isolated Orca dev profile attached to the intended pencilfish worktree instance.

Scenario exercised: Settings → Browser → Session & Cookies, then opened the real Import Cookies menu and verified the From File… entry is present and interactive.

Browser cookie settings

Browser cookie settings

File import entry point

Import Cookies menu with From File

Backing verification: the focused browser-cookie-import suite passes 26/26. Controlled mutation checks prove the regression test fails if the __Host- input path is forwarded, if any domain property is sent, or if an ordinary cookie path is changed.

Remaining UI gap: selecting From File… opens a native file chooser, which CDP cannot drive. I did not substitute OS-level automation. The main-process payload transformation is therefore verified by the focused test and the already-shipping native-browser parity path, while the visible entry point and menu were exercised in Electron.

@brennanb2025
brennanb2025 merged commit a20165a into main Aug 3, 2026
43 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…stablyai#12166)

* fix(browser): import __Host- cookies host-only so Chromium keeps them

The cookie file/JSON import path passed a Domain attribute for every
cookie. Chromium rejects any __Host--prefixed cookie that carries a
Domain (the prefix requires host-only, path=/, Secure), so file import
silently dropped session cookies like GitHub's __Host-user_session_same_site
and users stayed logged out after importing.

Mirror the browser-native import path, which already shapes __Host-
cookies host-only: omit domain and force path=/ when the name is
__Host--prefixed. Add a regression test covering both a __Host- cookie
and a normal domain cookie in one import.

* test(browser): cover __Host- cookie payload constraints

* test(browser): preserve ordinary cookie paths
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