Skip to content

fix(browser): stop impersonating the source browser's UA on cookie import (STA-3514) - #12849

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/sta-3514-arc-cookie-user-agent
Aug 10, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/sta-3514-arc-cookie-user-agent

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Cookie imports no longer impersonate the source browser's User-Agent. The embedded browser always presents its own engine-derived UA (cleaned, or native for opt-out profiles), whether or not cookies were imported. This is a net deletion (+83/−429): the import-time UA synthesis, the persisted per-partition UA state, and the #12811 version gate that existed only to catch the synthesis's bad output all go.

User-visible fix: an Arc import no longer brands the whole browser as Chrome/1.x (Arc's marketing version read as a Chromium version), which made sites reject the browser as ancient — permanently, since the UA was persisted and re-applied every launch. Post-fix the session presents the real engine UA (Chrome/150.x), and previously-poisoned persisted state is simply never read again.

Why deletion rather than better version detection:

Screenshots

No visual change.

Testing

  • pnpm lint (oxlint + oxfmt clean on touched files)
  • pnpm typecheck (all three projects, from clean — tsbuildinfo cleared first)
  • pnpm test — src/main/browser/ suite: 33 files, 588/588 passing
  • Added or updated high-quality tests that would catch regressions

New/updated regression tests, all mutation-checked (re-introducing the old behavior flips them red):

  • import never calls setUserAgent (browser-cookie-import.test.ts)
  • legacy persisted UAs — valid Chrome-shaped and broken Chrome/1.x — are ignored on restore and the engine UA applies (browser-session-registry.persistence.test.ts)
  • native-mode profiles get no setUserAgent at all, even with a legacy persisted UA

Live Electron QA (real Electron 43 / Chromium 150 engine): bundled the actual production browser-session-ua.ts from this branch into a standalone Electron harness with a local HTTPS echo server; accounts.google.com DNS-mapped to it to observe real wire headers. All checks pass:

  • wire UA = Chrome/150.0.7871.47 (real engine version), no Electron/app tokens, not Chrome/1.x
  • navigator.userAgent byte-identical to the wire UA
  • Google auth host: wire UA is Firefox with no sec-ch-ua headers — the fix(browser): present Firefox UA on Google auth hosts to end ~1h sign-in staleness #12884 switch survives intact
  • Ran the identical harness against main's browser-session-ua.ts: every observed surface (wire UA, navigator UA, hints, auth-host behavior) is byte-identical between main and this branch. The deletion changes which code produces the session identity, not the identity itself.

AI Review Report

Reviewed the full lifecycle of the deleted state: every reader/writer of userAgent/userAgentByPartition meta (import write, restore read, profile-delete cleanup, clear-cookies cleanup) is removed together, so no orphaned reader remains. Verified persistMeta naturally drops legacy keys on the next write since the loader no longer carries them — no migration code needed. Confirmed the native-UA opt-out (#12608) and the Google auth-host Firefox switch (#12884) are untouched: the registry still sets mode state before the native early-return, and setupClientHintsOverride still installs the auth-host handler for both clean sessions and (unchanged) native opt-outs. Checked the one behavior change beyond bug scope: Chrome/Edge imports previously presented the source browser's exact version and now present the engine version — one major apart, both real; the engine-UA path is the one all fork imports already land on in production today.

Cross-platform: this PR only deletes macOS-only synthesis code (getUserAgentForBrowser returned null off-darwin, so non-macOS behavior is unchanged by construction). No shortcuts, labels, paths, or shell behavior touched; no Windows/Linux-specific code in the deleted region.

Security Audit

Removes an execFileSync('defaults', …) subprocess call and a persisted free-text value that was replayed into session state on every launch — both a net reduction in surface. No new input handling, IPC, path handling, or dependencies. The Google-bound cookie exclusion (isGoogleSourceBoundCookie) and partition allowlisting are unchanged.

Notes

  • Supersedes the earlier synthesis-hardening approach on this branch (preserved at tag sta3514-synth-approach).
  • What cannot be verified without a real account: long-run Google sign-in longevity. Per fix(browser): present Firefox UA on Google auth hosts to end ~1h sign-in staleness #12884's methodology, transplant behavior can't be A/B'd on one account. Risk is bounded: the auth-host path is byte-identical to main (measured), and the engine-UA fallback is what every fork import on main already uses.
  • Known residual (pre-existing, unchanged): with session.setUserAgent() active, Chromium emits no sec-ch-ua headers at all; identical on main, recorded in the harness diff.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 458c92e3-a2a1-4785-b3d9-a5665780ecb2

📥 Commits

Reviewing files that changed from the base of the PR and between bd9addb and 0f12479.

📒 Files selected for processing (9)
  • src/main/browser/browser-cookie-import-replacement.test.ts
  • src/main/browser/browser-cookie-import.arc-ua.test.ts
  • src/main/browser/browser-cookie-import.comet.test.ts
  • src/main/browser/browser-cookie-import.helium.test.ts
  • src/main/browser/browser-cookie-import.test.ts
  • src/main/browser/browser-cookie-import.ts
  • src/main/browser/browser-session-registry.persistence.test.ts
  • src/main/browser/browser-session-registry.ts
  • src/main/browser/browser-session-ua.ts
💤 Files with no reviewable changes (3)
  • src/main/browser/browser-cookie-import.arc-ua.test.ts
  • src/main/browser/browser-cookie-import.comet.test.ts
  • src/main/browser/browser-cookie-import.helium.test.ts

📝 Walkthrough

Walkthrough

Removed browser-specific user-agent resolution and overrides from Chromium cookie imports. Imports now retain the session’s startup-configured user agent and continue filtering Google integrity cookies. Removed persisted user-agent metadata, restoration logic, cleanup methods, and validation helpers. Updated persistence tests for legacy and valid persisted UAs, and updated cookie-import tests to verify that user-agent mutation and macOS browser-version lookup do not occur. Removed obsolete Comet, Helium, and Arc user-agent tests.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description covers the required sections, testing evidence, AI review, security audit, platform compatibility, risks, and follow-up notes.
Title check ✅ Passed The title clearly and concisely describes the main change: stopping source-browser User-Agent impersonation during cookie import.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.
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: 4ffc5086-e743-4592-a5f9-4b053e4ebdeb

📥 Commits

Reviewing files that changed from the base of the PR and between b70e337 and 548b53b.

📒 Files selected for processing (5)
  • src/main/browser/browser-cookie-import.arc-user-agent.test.ts
  • src/main/browser/browser-cookie-import.ts
  • src/main/browser/browser-session-registry.persistence.test.ts
  • src/main/browser/browser-session-registry.ts
  • src/main/browser/browser-session-ua.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron QA evidence

Validated the exact PR worktree in an isolated Electron profile seeded with the pre-fix Arc session metadata containing Chrome/1.104.0. CDP identity resolved to brennanb2025/sta-3514-arc-cookie-user-agent; the visible Browser settings rendered successfully with the Arc default session still active, while startup rewrote the profile metadata from the poisoned User-Agent to userAgent: null and an empty userAgentByPartition map. Renderer console inspection showed 0 errors.

STA-3514 Electron QA: Browser settings with Arc default session active after poisoned UA migration

@brennanb2025
brennanb2025 force-pushed the brennanb2025/sta-3514-arc-cookie-user-agent branch from bb31554 to a2aaac0 Compare August 8, 2026 19:46
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@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

🧹 Nitpick comments (1)
src/main/browser/browser-cookie-import.arc-user-agent.test.ts (1)

93-105: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover an invalid ArcCore.framework fallback.

Add a case where ArcCore.framework returns 1.104.0 and Last Version returns a valid Chromium version. The current suite covers a missing Core version, but not a malformed Core version that must fall back.

Proposed test
+  it('uses Last Version when ArcCore has an implausible version', async () => {
+    mockArcPlistVersion('1.104.0', '1.104.0')
+    mockArcLastVersion('126.0.6478.127\n')
+
+    const { getUserAgentForBrowser } = await import('./browser-cookie-import')
+
+    expect(getUserAgentForBrowser('arc')).toContain('Chrome/126.0.6478.127')
+  })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d3e339f1-0c7b-4ecf-82b9-e736324a8869

📥 Commits

Reviewing files that changed from the base of the PR and between 04f7123 and a2aaac0.

📒 Files selected for processing (5)
  • src/main/browser/browser-cookie-import.arc-user-agent.test.ts
  • src/main/browser/browser-cookie-import.ts
  • src/main/browser/browser-session-registry.persistence.test.ts
  • src/main/browser/browser-session-registry.ts
  • src/main/browser/browser-session-ua.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/main/browser/browser-session-registry.ts
  • src/main/browser/browser-cookie-import.ts
  • src/main/browser/browser-session-ua.ts
  • src/main/browser/browser-session-registry.persistence.test.ts

Comment on lines +75 to +79
afterEach(() => {
Object.defineProperty(process, 'platform', { value: originalPlatform })
process.env.HOME = originalHome
vi.restoreAllMocks()
})

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

In supported Node.js versions, what is the runtime result of assigning undefined to a process.env property?

💡 Result:

In Node.js, assigning the value undefined to a property of process.env does not unset or remove the environment variable [1][2]. Instead, the value is implicitly converted to the string 'undefined' [3][4]. As a result, if you execute process.env.MY_VAR = undefined;, accessing process.env.MY_VAR will return the string value 'undefined' [3][4]. This behavior occurs because process.env is a special object that forces all assigned values to be converted to strings [1][3]. To remove an environment variable from process.env, you must use the delete operator [3][4]. For example, using delete process.env.MY_VAR; will correctly remove the property from the object [3][4]. This implicit string conversion is documented behavior in Node.js, and developers are warned that this behavior is deprecated; future versions of Node.js may throw an error if values that are not strings, numbers, or booleans are assigned to process.env properties [3][4].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the referenced test file and relevant snippets.
if [ -f "src/main/browser/browser-cookie-import.arc-user-agent.test.ts" ]; then
  echo "FOUND reference file"
  nl -ba src/main/browser/browser-cookie-import.arc-user-agent.test.ts | sed -n '1,120p'
else
  echo "Reference file not present at expected path"
  fd -a 'browser-cookie-import.arc-user-agent.test.ts' . || true
fi

echo
echo "Node process.env undefined coercion probe:"
node - <<'JS'
const original = Object.getOwnPropertyDescriptor(process.env, 'HOME');
if (original && original.enumerable) delete process.env.HOME;
console.log('before:', process.env.HOME, Object.getOwnPropertyDescriptor(process.env, 'HOME') !== undefined);
process.env.HOME = undefined;
console.log('after assigns undefined:', process.env.HOME, typeof process.env.HOME, Object.getOwnPropertyDescriptor(process.env, 'HOME') !== undefined);
if (original && original.enumerable) delete process.env.HOME; else delete process.env.HOME;
console.log('delete result:', process.env.HOME, Object.getOwnPropertyDescriptor(process.env, 'HOME') !== undefined);
JS

Repository: stablyai/orca

Length of output: 212


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Reference file lines 1-120:"
awk '{printf "%6d  %s\n", NR, $0}' src/main/browser/browser-cookie-import.arc-user-agent.test.ts | sed -n '1,120p'

echo
echo "Node process.env undefined coercion probe:"
node - <<'JS'
const original = Object.getOwnPropertyDescriptor(process.env, 'HOME');
if (original && original.enumerable) delete process.env.HOME;
console.log('before:', process.env.HOME, Object.getOwnPropertyDescriptor(process.env, 'HOME') !== undefined);
process.env.HOME = undefined;
console.log('after assigns undefined:', process.env.HOME, typeof process.env.HOME, Object.getOwnPropertyDescriptor(process.env, 'HOME') !== undefined);
if (original && original.enumerable) delete process.env.HOME; else delete process.env.HOME;
console.log('delete result:', process.env.HOME, Object.getOwnPropertyDescriptor(process.env, 'HOME') !== undefined);
JS

Repository: stablyai/orca

Length of output: 5516


Restore process.env.HOME only as a string.

process.env coerces undefined to the string "undefined", so set HOME to an empty string when the original value is absent and delete it when appropriate.

@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.

🧹 Nitpick comments (1)
src/main/browser/browser-cookie-import.ts (1)

866-866: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use join() for application and plist paths.

These lines construct file paths with literal / separators. Use join() for the Info domain and application bundle paths.

Proposed fix
-    const plistVersion = readInfoPlistVersion(`${appPath}/Contents/Info`)
+    const plistVersion = readInfoPlistVersion(join(appPath, 'Contents', 'Info'))

As per coding guidelines, use path.join or Electron/Node path utilities for file paths; never assume / or \.

Also applies to: 897-925

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4bf7b736-21f2-4096-a75b-da561cb5814c

📥 Commits

Reviewing files that changed from the base of the PR and between a2aaac0 and c07f8ad.

📒 Files selected for processing (7)
  • src/main/browser/browser-cookie-import-replacement.test.ts
  • src/main/browser/browser-cookie-import.arc-user-agent.test.ts
  • src/main/browser/browser-cookie-import.comet.test.ts
  • src/main/browser/browser-cookie-import.helium.test.ts
  • src/main/browser/browser-cookie-import.test.ts
  • src/main/browser/browser-cookie-import.ts
  • src/main/browser/browser-session-ua.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/browser/browser-session-ua.ts

…port (STA-3514)

Delete the import-time UA synthesis entirely instead of patching its version
detection. The session now always keeps the engine-derived UA the registry
sets at startup (clean or native), for imported and non-imported profiles
alike.

Why deletion is the fix:
- The synthesis read CFBundleShortVersionString, which on forks is a
  marketing version — Arc imports presented Chrome/1.x and sites rejected
  the browser as ancient (STA-3514).
- Its stated purpose (keep Google-bound cookies valid) is handled by
  isGoogleSourceBoundCookie excluding those cookies since #736, and #12884
  measured that Google rejects re-transplants regardless of UA identity.
- #12608 measured the synthesized Chrome-shaped UA reaching
  /v3/signin/rejected while the engine UA reached account lookup.

Persisted userAgent/userAgentByPartition meta is no longer read; legacy keys
drop off on the next meta write. The #12811 gate existed only to catch bad
synthesized values, so it leaves with the synthesis.
@brennanb2025
brennanb2025 force-pushed the brennanb2025/sta-3514-arc-cookie-user-agent branch from c07f8ad to cf67942 Compare August 9, 2026 19:09
@brennanb2025 brennanb2025 changed the title fix(browser): stop Arc cookie import persisting a Chrome/1.x User-Agent (STA-3514) fix(browser): stop impersonating the source browser's UA on cookie import (STA-3514) Aug 9, 2026
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@brennanb2025

brennanb2025 commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Electron QA — STA-3514 (cookie import UA)

Head: 0f12479078c63c6d3257f387c7dc705ceb483eb2
Recommendation: PASS

Setup

  • Isolated ORCA_DEV_USER_DATA_PATH + CDP port 19455
  • Verified window.api.app.getIdentity() before interaction for brennanb2025/sta-3514-arc-cookie-user-agent
  • Disposable local echo endpoint; no real cookies, accounts, tokens, or browsing data accessed
  • Seeded the post-import state with Arc source metadata and legacy poisoned userAgent / userAgentByPartition = Chrome/1.158.1

Actions and result

  1. Launched this exact PR head through Electron.
  2. Restored the seeded Arc session and opened an embedded browser tab to the local echo endpoint.
  3. Captured navigator.userAgent and the request wire User-Agent inside the production session partition.

Observed embedded-browser UA:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.7871.47 Safari/537.36
Check Result
navigator.userAgent === wire User-Agent ✅ byte-identical
Chrome major 150 — running engine
Legacy Chrome/1.x applied ❌ no
Electron/ or app token present ❌ no
Restored profile source arc / Default

Evidence

Electron app launched from the isolated PR worktree:

Orca Electron session

Rendered summary of the values captured from the live Electron webview and local request echo:

Captured UA measurement summary

Limitations

  • The full Settings import UI was not run against an installed browser because that would access real cookies/keychain data.
  • Direct screenshot capture of the Electron webview timed out, so the second image is a rendered summary of the captured live values, not a direct webview frame.
  • The strongest safe path was exercised: production Electron session restore with Arc source metadata plus poisoned legacy UA fields, followed by a real local request through the embedded browser.

No cookie-import or UA-related console/app errors were observed. The isolated Electron process, echo server, and temporary profile were removed; the worktree remained clean.

@brennanb2025
brennanb2025 merged commit c03c01a into main Aug 10, 2026
44 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…port (STA-3514) (stablyai#12849)

* fix(browser): stop impersonating the source browser's UA on cookie import (STA-3514)

Delete the import-time UA synthesis entirely instead of patching its version
detection. The session now always keeps the engine-derived UA the registry
sets at startup (clean or native), for imported and non-imported profiles
alike.

Why deletion is the fix:
- The synthesis read CFBundleShortVersionString, which on forks is a
  marketing version — Arc imports presented Chrome/1.x and sites rejected
  the browser as ancient (STA-3514).
- Its stated purpose (keep Google-bound cookies valid) is handled by
  isGoogleSourceBoundCookie excluding those cookies since stablyai#736, and stablyai#12884
  measured that Google rejects re-transplants regardless of UA identity.
- stablyai#12608 measured the synthesized Chrome-shaped UA reaching
  /v3/signin/rejected while the engine UA reached account lookup.

Persisted userAgent/userAgentByPartition meta is no longer read; legacy keys
drop off on the next meta write. The stablyai#12811 gate existed only to catch bad
synthesized values, so it leaves with the synthesis.

* test(browser): catch source UA impersonation regression
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