Skip to content

fix: correct x-statsig-id format to bypass anti-bot rules#567

Merged
chenyme merged 1 commit into
chenyme:mainfrom
KK1aus:fix/statsig-id-format
Jun 3, 2026
Merged

fix: correct x-statsig-id format to bypass anti-bot rules#567
chenyme merged 1 commit into
chenyme:mainfrom
KK1aus:fix/statsig-id-format

Conversation

@KK1aus

@KK1aus KK1aus commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Problem

Grok's website added new anti-bot controls (issue #562). All HTTP API endpoints except WebSocket imagine return:

{"error":{"code":7,"message":"Request rejected by anti-bot rules.","details":[]}}

Root Cause

Grok's frontend JavaScript intercepts every fetch call and computes the x-statsig-id header via a Statsig SDK evaluation. When that evaluation fails (headless, first paint, etc.), it falls back to:

catch(e) { t = btoa("x1:" + e) }

The old code generated values with the prefix e: (e.g. e:TypeError: Cannot read properties of undefined...), but the real browser uses the prefix x1: (e.g. x1:TypeError: ...). Grok's server validates this prefix and rejects anything else.

Fix

Changed the prefix in _statsig_id() from e: to x1:, matching exactly what the real browser's fetch interceptor produces as a Statsig evaluation fallback. The dynamic_statsig config toggle is now effectively always-on (each request gets a randomized error variable name).

Validation

Tested directly against grok.com/rest/app-chat/conversations/new with 3 different SSO tokens — all returned 200 where they previously returned 403. Also deployed to local Docker and confirmed the service works end-to-end.

Fixes #562

The grok.com frontend's fetch interceptor generates x-statsig-id by
running a Statsig SDK evaluation per request. When that evaluation
fails (headless, first paint, etc.), it falls back to:

    btoa("x1:" + error.toString())

The old code used the prefix "e:" instead of "x1:", which Grok's
anti-bot now detects and rejects with HTTP 403.

Verified against 3 SSO tokens — all return 200 on app-chat endpoints.

Fixes chenyme#562
@KK1aus KK1aus force-pushed the fix/statsig-id-format branch from c8e4a2d to 7015258 Compare June 3, 2026 03:23
@chenyme chenyme merged commit 5805cbb into chenyme:main Jun 3, 2026
3 of 4 checks passed
@leadscloud leadscloud mentioned this pull request Jun 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.

bug: 官网grok新增风控,除了imagine ws还能用,其余接口都报403

2 participants