Repository navigation
fix(browser): stop impersonating the source browser's UA on cookie import (STA-3514) - #12849
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
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 (9)
💤 Files with no reviewable changes (3)
📝 WalkthroughWalkthroughRemoved 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)
✨ 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: 4ffc5086-e743-4592-a5f9-4b053e4ebdeb
📒 Files selected for processing (5)
src/main/browser/browser-cookie-import.arc-user-agent.test.tssrc/main/browser/browser-cookie-import.tssrc/main/browser/browser-session-registry.persistence.test.tssrc/main/browser/browser-session-registry.tssrc/main/browser/browser-session-ua.ts
Electron QA evidenceValidated 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. |
bb31554 to
a2aaac0
Compare
|
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. |
There was a problem hiding this comment.
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 winCover an invalid
ArcCore.frameworkfallback.Add a case where
ArcCore.frameworkreturns1.104.0andLast Versionreturns 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
📒 Files selected for processing (5)
src/main/browser/browser-cookie-import.arc-user-agent.test.tssrc/main/browser/browser-cookie-import.tssrc/main/browser/browser-session-registry.persistence.test.tssrc/main/browser/browser-session-registry.tssrc/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
| afterEach(() => { | ||
| Object.defineProperty(process, 'platform', { value: originalPlatform }) | ||
| process.env.HOME = originalHome | ||
| vi.restoreAllMocks() | ||
| }) |
There was a problem hiding this comment.
🩺 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:
- 1: https://stackoverflow.com/questions/10265208/node-js-process-env-assigning-process-env-property-to-undefined-results-in-stri
- 2: Setting
undefinedtoprocess.env.*sets a"undefined"string value nodejs/node#48875 - 3: https://nodejs.org/dist/latest/docs/api/process.html
- 4: https://nodejs.org/api/process.html
🏁 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);
JSRepository: 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);
JSRepository: 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.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/browser/browser-cookie-import.ts (1)
866-866: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
join()for application and plist paths.These lines construct file paths with literal
/separators. Usejoin()for theInfodomain 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.joinor 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
📒 Files selected for processing (7)
src/main/browser/browser-cookie-import-replacement.test.tssrc/main/browser/browser-cookie-import.arc-user-agent.test.tssrc/main/browser/browser-cookie-import.comet.test.tssrc/main/browser/browser-cookie-import.helium.test.tssrc/main/browser/browser-cookie-import.test.tssrc/main/browser/browser-cookie-import.tssrc/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.
c07f8ad to
cf67942
Compare
|
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. |
Electron QA — STA-3514 (cookie import UA)Head: Setup
Actions and result
Observed embedded-browser UA:
EvidenceElectron app launched from the isolated PR worktree: Rendered summary of the values captured from the live Electron webview and local request echo: Limitations
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. |
…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



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:
isGoogleSourceBoundCookie, which excludes those cookies from import entirely. That mechanism stays./v3/signin/rejectedwhile the engine UA reached normal account lookup.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 passingNew/updated regression tests, all mutation-checked (re-introducing the old behavior flips them red):
setUserAgent(browser-cookie-import.test.ts)Chrome/1.x— are ignored on restore and the engine UA applies (browser-session-registry.persistence.test.ts)setUserAgentat all, even with a legacy persisted UALive Electron QA (real Electron 43 / Chromium 150 engine): bundled the actual production
browser-session-ua.tsfrom this branch into a standalone Electron harness with a local HTTPS echo server;accounts.google.comDNS-mapped to it to observe real wire headers. All checks pass:Chrome/150.0.7871.47(real engine version), noElectron/app tokens, notChrome/1.xnavigator.userAgentbyte-identical to the wire UAsec-ch-uaheaders — the fix(browser): present Firefox UA on Google auth hosts to end ~1h sign-in staleness #12884 switch survives intactbrowser-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/userAgentByPartitionmeta (import write, restore read, profile-delete cleanup, clear-cookies cleanup) is removed together, so no orphaned reader remains. VerifiedpersistMetanaturally 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, andsetupClientHintsOverridestill 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 (
getUserAgentForBrowserreturnednulloff-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
sta3514-synth-approach).session.setUserAgent()active, Chromium emits nosec-ch-uaheaders at all; identical on main, recorded in the harness diff.