Skip to content

fix(browse): stop faking chrome.runtime.connect/sendMessage in Layer C stealth - #2781

Closed
AyushRajgor wants to merge 1 commit into
garrytan:mainfrom
AyushRajgor:fix/stealth-no-fake-runtime-methods
Closed

AyushRajgor wants to merge 1 commit into
garrytan:mainfrom
AyushRajgor:fix/stealth-no-fake-runtime-methods

Conversation

@AyushRajgor

Copy link
Copy Markdown

Why (in your own words)

Layer C stealth injects a fake window.chrome.runtime that includes callable connect and sendMessage stubs which throw No matching signature for any input. Real Chrome never shows that to an ordinary web page: chrome.runtime is either undefined, or (only when an installed extension lists the origin in externally_connectable) carries real, working methods. Web apps that ship a companion Chrome extension probe chrome.runtime.sendMessage to detect it. In GStack Browser the probe finds a function, the app assumes its extension is installed, routes auth through the extension flow, that flow 403s, and the user is bounced back to the login page in a loop. The same site logs in fine in stock Chrome, Edge, and incognito. There is no opt-out because Layer C is always-on.

This PR drops the two callable stubs and keeps the enum shape (OnInstalledReason, PlatformOs, ...) that the Cloudflare/DataDome presence checks actually look at. That is the shape real Chrome shows a page with no connectable extension, so it is also the more consistent fingerprint (the v1.28 / #1363 principle: inconsistent fakes make detection easier, not harder).

Fixes #2780

Live evidence

Before (v1.79.0.0 unpatched, headed browse connect, on the affected site's login page):

$ browse js "JSON.stringify({hasChrome: !!window.chrome, hasRuntime: !!(window.chrome && window.chrome.runtime), hasSendMessage: !!(window.chrome && window.chrome.runtime && window.chrome.runtime.sendMessage), ua: navigator.userAgent})"
{"hasChrome":true,"hasRuntime":true,"hasSendMessage":true,"ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/151.0.7922.34 Safari/537.36"}

.gstack/browse-console.log during the login attempt:

[error] Failed to load resource: the server responded with a status of 403 ()
[error] ERROR TypeError: Error in invocation of runtime.sendMessage: No matching signature.
    at Object.sendMessage (<anonymous>:63:17)
    at <site>/main.<hash>.js:1:480593
    at _e.isExtensionInstalled (<site>/main.<hash>.js:1:480499)

.gstack/browse-network.log (site redacted): login POST 200 → tenant /login/callback → app POSTs /logout → redirect to /logout?org=...&client_id=<extension-id>&client_name=extension → 403 → back on the login page.

After (this branch, rebuilt with ./setup, headed browse connect):

$ browse js "JSON.stringify({runtime: typeof chrome.runtime, enumKeys: Object.keys(chrome.runtime).length, connect: typeof chrome.runtime.connect, sendMessage: typeof chrome.runtime.sendMessage, csi: typeof chrome.csi, loadTimes: typeof chrome.loadTimes, webdriver: navigator.webdriver})"
{"runtime":"object","enumKeys":7,"connect":"undefined","sendMessage":"undefined","csi":"function","loadTimes":"function","webdriver":false}

Logging into the same site in the patched GStack Browser now succeeds on the first try and the session persists in the profile.

Static tests:

$ bun test browse/test/stealth-layer-c.test.ts browse/test/stealth-extended.test.ts
 39 pass
 0 fail
 101 expect() calls
Ran 39 tests across 2 files. [103.00ms]

Scope

  • Changed: browse/src/stealth.ts (remove connect/sendMessage from the injected chrome.runtime; enum shape, id, chrome.app, csi, loadTimes untouched), browse/test/stealth-layer-c.test.ts (new test asserting the two methods are absent; markNative floor 7 → 6), browse/test/stealth-webdriver.test.ts (runtime test now asserts typeof runtime.connect/sendMessage === 'undefined' instead of expecting a throw).
  • Verified live by: rebuilding with ./setup, browse connect (headed, Windows 11, bundled Chromium 151), the browse js probe above, and a real login on the affected site that previously looped.
  • Did NOT test: stealth-webdriver.test.ts could not run on this machine. Playwright's chromium.launch() for chrome-headless-shell hangs under bun test here (120 s launch timeout before any test body runs). This matches the reason scripts/test-free-shards.ts excludes browser-launching tests from the Windows shard. The updated assertions mirror the live browse js result above; CI's macOS/Linux runners should exercise them. Not re-checked against bot.sannysoft.com / Cloudflare-fronted sites after the change; the enum shape they check is unchanged.

Liveness proof (required)

(maintainer note: the PR author will attach the GSTACK PR screenshot in a comment.)

Checklist

…C stealth

Real Chrome exposes callable chrome.runtime.connect / sendMessage to a web
page only when an installed extension lists that origin in
externally_connectable. On an ordinary page they are undefined. Layer C
injected stubs that throw "No matching signature" for any call, a shape
real Chrome never produces. Sites that probe chrome.runtime.sendMessage to
detect their own companion extension concluded it was installed and routed
auth through the extension flow, which fails and loops back to login.

Keep the enum shape (OnInstalledReason, PlatformOs, ...) that presence
checks look at; drop only the two callable stubs. Update the Layer C static
tests and the Chromium runtime test accordingly.
@trunk-io

trunk-io Bot commented Sep 2, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@trunk-io

trunk-io Bot commented Sep 2, 2026

Copy link
Copy Markdown

An error occurred while submitting your PR to the queue: Only users that are a part of this repo's Trunk organization or have write permissions to the repo can submit a PR to the queue

@capy-ai

capy-ai Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Thanks for this, @AyushRajgor. The fix is now on main: the stealth chrome.runtime stub no longer fakes connect/sendMessage (browse/src/stealth.ts) (fixed in v1.91.2.0, #2959). Closing as superseded; if you still see the problem on the latest gstack, please open an issue with ./setup --status output.

@capy-ai capy-ai Bot closed this Oct 3, 2026
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.

browse: Layer C stealth fakes chrome.runtime.connect/sendMessage, sites detect a phantom companion extension and break login

1 participant