Repository navigation
fix(browser): import __Host- cookies host-only so Chromium keeps them - #12166
Conversation
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 SummaryThis PR fixes a bug where importing cookies from a file silently dropped
Confidence Score: 5/5Safe 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.
|
| 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
Reviews (3): Last reviewed commit: "test(browser): preserve ordinary cookie ..." | Re-trigger Greptile
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughCookie imports now handle 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
src/main/browser/browser-cookie-import.test.tssrc/main/browser/browser-cookie-import.ts
Electron validationValidated 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 settingsFile import entry pointBacking 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. |
…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


Summary
The cookie file/JSON import path (
importValidatedCookies) passed adomainattribute 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=/, andSecure. 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-, omitdomainand forcepath=/. 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 realHOME/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 itAdded a regression test that imports a
__Host-cookie alongside a normal domain cookie in one file and asserts the__Host-cookie is set with nodomainandpath=/, while the normal cookie keeps its.domain.AI Review Report
Reviewed the diff with an AI coding agent. Main risks checked:
__Host-shaping already exists there; this makes the file/JSON path consistent rather than inventing new behavior.__Host-skip thedomain/overridepath; the test asserts a normal cookie still receives.github.com.__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 beforecookies.set. This change only removes thedomainattribute (and forcespath=/) 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
importValidatedCookiesis 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.