Skip to content

fix(browser): strip app/Electron UA tokens on WhatsApp Web - #19740

Closed
igor-giro wants to merge 1 commit into
stablyai:mainfrom
igor-giro:fix/whatsapp-web-ua-gate
Closed

igor-giro wants to merge 1 commit into
stablyai:mainfrom
igor-giro:fix/whatsapp-web-ua-gate

Conversation

@igor-giro

Copy link
Copy Markdown

Problem

Opening https://web.whatsapp.com in Orca's embedded browser shows WhatsApp's browser gate — "WhatsApp works with Google Chrome 100+ / To use WhatsApp, update Chrome" — even though the runtime is current.

Reproduced on Orca 1.4.198 (macOS): the embedded tabs send

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Orca/1.4.198 Chrome/150.0.7871.224 Electron/43.4.1 Safari/537.36

WhatsApp's UA sniffing trips on the Electron/… (and app) product tokens and refuses the session despite Chrome/150.

Fix

Host-scoped UA exception for web.whatsapp.com only, mirroring the existing Google auth-host Firefox switch: that host sees the session identity minus the Orca/… and Electron/… tokens (platform, Chrome and WebKit/Safari tokens stay byte-identical to the real engine). Applied consistently in the three places a UA is decided:

  • browser-session-ua.ts — the wire header via webRequest.onBeforeSendHeaders
  • browser-manager-navigation.ts — the navigation-time navigator.userAgent override (with restore when leaving the host)
  • browser-viewport-user-agent.ts — the desktop viewport UA builder

The session-wide UA deliberately keeps the Electron tokens: per the existing comment in browser-session-ua.ts, a Chrome-shaped app-wide identity is exactly what Cloudflare Turnstile rejects (error 600010). Only the one host that gates on those tokens gets the stripped identity. Client hints are untouched — Chromium's real sec-ch-ua brands carry no Electron entry, so they agree with the stripped UA.

Scope guard: exact-hostname match (web.whatsapp.com only — www/faq.whatsapp.com accept the stock UA), lookalike hosts rejected.

Verification

  • Unit tests added: browser-whatsapp-ua.test.ts (host matching incl. lookalikes, token stripping incl. lowercase dev token, idempotence) and a WhatsApp case in browser-viewport-user-agent.test.ts.
  • Tests were not run locally (fresh clone without the native runtime/deps; the install is long-running) — relying on CI.
  • Manual repro of the bug itself was done against the released 1.4.198 build; the fixed build was not manually exercised.

web.whatsapp.com UA-sniffs and shows its 'update Chrome' wall whenever the
Electron/app product tokens are present, even alongside a current Chrome
token (reproduced on 1.4.198: Chromium 150 rejected).

Host-scoped exception mirroring the Google auth-host Firefox switch: only
web.whatsapp.com sees the session identity minus the Orca/ and Electron/
tokens, kept consistent across the wire header (webRequest), the navigation
override, and the viewport UA builder. The session-wide UA keeps the
Electron tokens on purpose — a Chrome-shaped app-wide identity is what
Cloudflare Turnstile rejects (see browser-session-ua.ts).
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 6b5dba20-a94b-42cc-ba97-c8d4d79db062

📥 Commits

Reviewing files that changed from the base of the PR and between b94bcdc and 4d636be.

📒 Files selected for processing (6)
  • src/main/browser/browser-manager-navigation.ts
  • src/main/browser/browser-session-ua.ts
  • src/main/browser/browser-viewport-user-agent.test.ts
  • src/main/browser/browser-viewport-user-agent.ts
  • src/main/browser/browser-whatsapp-ua.test.ts
  • src/main/browser/browser-whatsapp-ua.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Adds exact-host WhatsApp Web detection and user-agent compatibility helpers. WhatsApp Web navigation, request headers, and desktop viewport overrides now remove Orca/ and Electron/ tokens while preserving the browser identity. Google authentication handling remains unchanged. Tests cover host matching, token removal, unchanged unrelated user-agents, idempotence, and viewport output.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 4d636

WhatsApp Web receives a Chrome-compatible user agent without Orca or Electron tokens, while other hosts retain the existing identity. The change is ready to merge with no identified merge-blocking risk.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, solution, scope, and verification limits, but it omits most required template sections, including ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing che… Update the description to use the repository template. Add the missing sections, provide an issue reference after “Fixes #”, add N/A with a reason for Visual Proof if applicable, document testing and platform coverage, complete the requir…
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: removing app and Electron user-agent tokens for WhatsApp Web.
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.
Full details: Description check

Explanation

The description explains the problem, solution, scope, and verification limits, but it omits most required template sections, including ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing checklist, AI Disclosure, Review, boundary confirmation, Notes, and Checklist.

Resolution

Update the description to use the repository template. Add the missing sections, provide an issue reference after “Fixes #”, add N/A with a reason for Visual Proof if applicable, document testing and platform coverage, complete the required checkboxes, and include the required boundary and compatibility notes.

  • Fix all pre-merge checks with AI

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.

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

ℹ️ No critical issues — one minor coverage gap noted below.

Reviewed changes

A host-scoped UA exception for web.whatsapp.com that strips the Orca/… and Electron/… product tokens from the session identity, applied in the three places a UA is decided — mirroring the existing Google auth-host Firefox switch while keeping the session-wide Electron tokens that Cloudflare Turnstile expects.

  • browser-whatsapp-ua.ts (new) — isWhatsAppWebUrl (exact-hostname match, rejects lookalikes) and whatsAppCompatUserAgent (strips only the app and Electron tokens, case-insensitive and idempotent).
  • browser-session-ua.ts — wire header rewrite for requests to web.whatsapp.com.
  • browser-manager-navigation.ts — navigation-time navigator.userAgent override to the stripped UA, with restore on leaving the host.
  • browser-viewport-user-agent.ts — desktop viewport UA builder strips the tokens on WhatsApp Web.
  • tests — new browser-whatsapp-ua.test.ts (host matching, token stripping, lowercase dev token, idempotence) plus a WhatsApp case in browser-viewport-user-agent.test.ts.

I traced the override/restore transitions in applyGoogleAuthUserAgent, the wire handler, and the viewport builder (including the viewport-clear restore path in browser-manager-viewport.ts, which is already covered because it flows through buildViewportUserAgentOverride), and found no correctness issues. The hostname guard, token regex, and the whatsAppUa !== sessionUa && currentUa === whatsAppUa restore condition all check out.

ℹ️ Missing tests for the two host-switch integration points

The pure helpers and the viewport builder are well covered, but the two places where the WhatsApp exception plugs into existing host-switching machinery have no direct test, even though each Google equivalent does: the wire-handler branch in setupGoogleAuthUserAgentOverride (Google branches are tested in browser-session-registry.test.ts) and the navigation-time override/restore in applyGoogleAuthUserAgent (Google onto/off-host switching is tested in browser-manager-viewport-override.test.ts). The restore condition is subtle enough that pinning it is worth two extra cases.

Technical details
# Add integration tests for the WhatsApp UA exception

## Affected sites
- src/main/browser/browser-session-ua.ts:30 — WhatsApp wire-handler branch, untested (sibling Google branches each have a case in browser-session-registry.test.ts).
- src/main/browser/browser-manager-navigation.ts:53 — restore condition, untested (sibling Google onto/off-host switching is tested in browser-manager-viewport-override.test.ts).

## Required outcome
- One wire-handler test asserting the WhatsApp destination gets the stripped UA (and non-WhatsApp hosts still get the stock UA).
- One navigation test asserting the override is applied on entering web.whatsapp.com and restored to the session UA on leaving.

## Suggested approach (optional)
Mirror the existing `setupGoogleAuthUserAgentOverride` cases and the "onto and back off an auth host" navigation case, substituting the WhatsApp helpers.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor

Superseded by #19927 (merged as fb85f88d64), closing.

Your diagnosis here was correct and it was the first independent confirmation that the Electron/ and app tokens were breaking real sites — it turned out to be the same root cause as STA-7147, where users were being signed out of x.com and LinkedIn, in one case severely enough that LinkedIn revoked the session in their own Chrome and demanded SMS re-verification.

#19927 reverts the session-wide UA change from #18749, so main no longer sends Orca/x.y.z or Electron/x.y.z to any host. WhatsApp Web should now pass its browser gate without a host exception, which makes the web.whatsapp.com special case unnecessary — worth confirming on the next build.

Thanks for catching and reporting this one.

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.

2 participants