Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
fix(providers): forward Grok sso-rw cookie to fix anti-bot 403 (#3063) (#3098)
Diego Rodrigues de Sa e Souza365c29a115b1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f0aeed3e97..badab26d76 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,6 +22,7 @@ _Development cycle in progress — entries are added as work merges into `releas### 🔧 Bug Fixes+- **providers:** forward Grok's paired `sso-rw` cookie for grok-web — both the executor and the connection validator now send `sso=…; sso-rw=…` (via the new `buildGrokCookieHeader` helper) when the pasted blob carries `sso-rw`, fixing the `403` _"Request rejected by anti-bot rules"_ that Grok returns for `sso` alone. The add-account hint now asks for the full cookie line. ([#3063](https://github.com/diegosouzapw/OmniRoute/issues/3063))- **providers:** fix claude-web persistent 403 — `execute()` was calling the synchronous `normalizeClaudeSessionCookie()` which never injects `cf_clearance`; changed to async `normalizeClaudeSessionCookieWithAutoRefresh()` with `allowAutoSolve:true`. Also removes dead executor `claude-web-auto-refresh.ts` and correctly reclassifies `duckduckgo-web` and `veoaifree-web` as `NOAUTH_PROVIDERS`. (#3090 — thanks @oyi77)- **autoCombo:** rotate across all provider connections, never waste capacity — `buildAutoCandidates` now expands each provider into one candidate per active connection (e.g. 43 Cerebras keys → 43 candidates). Adds `ScoreTierRotator` with per-combo round-robin state, combo-name-aware tier preferences (smart/fast/cheap/coding), `connectionDensity` factor (weight 0.05), and budget-cap degradation using the rotator. (#3078 — thanks @oyi77)- **providers:** fix SiliconFlow model sync from configured endpoint — routes model discovery through `providerSpecificData.baseUrl` so CN (`api.siliconflow.cn`) vs Global endpoint selection is respected, and prevents `/sync-models` from treating `source: "local_catalog"` fallback responses as successful remote syncs. (#3094 — thanks @xz-dev)diff --git a/open-sse/executors/grok-web.ts b/open-sse/executors/grok-web.tsindex ef18ae6a8f..69921f9316 100644--- a/open-sse/executors/grok-web.ts+++ b/open-sse/executors/grok-web.ts@@ -19,7 +19,7 @@ import {type ExecuteInput,} from "./base.ts";import { FETCH_TIMEOUT_MS } from "../config/constants.ts";-import { extractCookieValue } from "@/lib/providers/webCookieAuth";+import { buildGrokCookieHeader } from "@/lib/providers/webCookieAuth";// ─── Constants ──────────────────────────────────────────────────────────────@@ -1739,11 +1739,12 @@ export class GrokWebExecutor extends BaseExecutor {traceparent: `00-${traceId}-${spanId}-00`,};- // Cookie auth — accepts a bare value, "sso=<value>", or a full- // DevTools cookie blob; we extract the sso pair and ignore the rest.+ // Cookie auth — accepts a bare value, "sso=<value>", or a full DevTools+ // cookie blob. Forwards both `sso` and (when present) the paired `sso-rw`+ // write cookie, which Grok's anti-bot now requires (#3063).if (credentials.apiKey) {- const token = extractCookieValue(credentials.apiKey, "sso");- if (token) headers["Cookie"] = `sso=${token}`;+ const cookieHeader = buildGrokCookieHeader(credentials.apiKey);+ if (cookieHeader) headers["Cookie"] = cookieHeader;}// Apply upstream extra headersdiff --git a/src/lib/providers/validation.ts b/src/lib/providers/validation.tsindex 6af959ddcd..e4ea04e0f4 100644--- a/src/lib/providers/validation.ts+++ b/src/lib/providers/validation.ts@@ -27,7 +27,11 @@ import {safeOutboundFetch,} from "@/shared/network/safeOutboundFetch";import { getProviderOutboundGuard } from "@/shared/network/outboundUrlGuard";-import { extractCookieValue, normalizeSessionCookieHeader } from "@/lib/providers/webCookieAuth";+import {+ buildGrokCookieHeader,+ extractCookieValue,+ normalizeSessionCookieHeader,+} from "@/lib/providers/webCookieAuth";import { buildJulesApiUrl } from "@/lib/cloudAgent/julesApi.ts";import { getGigachatAccessToken } from "@omniroute/open-sse/services/gigachatAuth.ts";import { validateQoderCliPat } from "@omniroute/open-sse/services/qoderCli.ts";@@ -2764,7 +2768,7 @@ async function validateGrokWebProvider({ apiKey, providerSpecificData = {} }: an"sentry-environment=production,sentry-release=d6add6fb0460641fd482d767a335ef72b9b6abb8,sentry-public_key=b311e0f2690c81f25e2c4cf6d4f7ce1c","Cache-Control": "no-cache","Content-Type": "application/json",- Cookie: `sso=${token}`,+ Cookie: buildGrokCookieHeader(apiKey),Origin: "https://grok.com",Pragma: "no-cache",Referer: "https://grok.com/",diff --git a/src/lib/providers/webCookieAuth.ts b/src/lib/providers/webCookieAuth.tsindex 35a837de26..4e9263c5fc 100644--- a/src/lib/providers/webCookieAuth.ts+++ b/src/lib/providers/webCookieAuth.ts@@ -40,6 +40,29 @@ export function extractCookieValue(rawValue: string, cookieName: string): stringreturn trimmed;}+/**+ * Build the `Cookie` header value for grok.com from whatever the user pasted.+ *+ * Always emits `sso=<value>`. When the pasted blob also carries the paired+ * `sso-rw` write cookie, it is forwarded too — Grok's anti-bot now rejects+ * requests that send `sso` without `sso-rw` (error code 7, #3063). `sso-rw` is+ * only appended when it appears as a real cookie pair in the input, so a bare+ * `sso` value (no `;`/`=`) is never mistaken for an `sso-rw` value.+ *+ * Returns "" when no `sso` value can be extracted.+ */+export function buildGrokCookieHeader(rawValue: string): string {+ const sso = extractCookieValue(rawValue, "sso");+ if (!sso) return "";++ const parts = [`sso=${sso}`];+ if (/(?:^|;\s*)sso-rw=/.test(rawValue)) {+ const ssoRw = extractCookieValue(rawValue, "sso-rw");+ if (ssoRw) parts.push(`sso-rw=${ssoRw}`);+ }+ return parts.join("; ");+}+export function normalizeSessionCookieHeaders(rawValues: Array<string | null | undefined>,defaultCookieName: stringdiff --git a/src/shared/constants/providers.ts b/src/shared/constants/providers.tsindex ece95f716f..ec515b5857 100644--- a/src/shared/constants/providers.ts+++ b/src/shared/constants/providers.ts@@ -299,7 +299,8 @@ export const WEB_COOKIE_PROVIDERS = {color: "#1DA1F2",textIcon: "GW",website: "https://grok.com",- authHint: "Paste your sso= cookie value from grok.com",+ authHint:+ "Paste the full grok.com cookie line from DevTools → Application → Cookies. Include both `sso` and `sso-rw` (e.g. `sso=...; sso-rw=...`) — Grok's anti-bot rejects `sso` on its own.",subscriptionRisk: true,riskNoticeVariant: "webCookie",},diff --git a/tests/unit/web-cookie-auth.test.ts b/tests/unit/web-cookie-auth.test.tsindex 4cb51c28cc..ba9e158ee3 100644--- a/tests/unit/web-cookie-auth.test.ts+++ b/tests/unit/web-cookie-auth.test.ts@@ -1,8 +1,12 @@import test from "node:test";import assert from "node:assert/strict";-const { extractCookieValue, normalizeSessionCookieHeader, stripCookieInputPrefix } =- await import("../../src/lib/providers/webCookieAuth.ts");+const {+ extractCookieValue,+ normalizeSessionCookieHeader,+ stripCookieInputPrefix,+ buildGrokCookieHeader,+} = await import("../../src/lib/providers/webCookieAuth.ts");test("stripCookieInputPrefix removes 'cookie:' and 'bearer ' prefixes", () => {assert.equal(stripCookieInputPrefix("Cookie: sso=abc"), "sso=abc");@@ -55,3 +59,31 @@ test("extractCookieValue: cookie name with regex metacharacters is escaped", ()const blob = "foo=1; my.cookie+name=hello; bar=2;";assert.equal(extractCookieValue(blob, "my.cookie+name"), "hello");});++// #3063 — Grok now requires the paired `sso-rw` write cookie alongside `sso`.+test("buildGrokCookieHeader: bare sso value emits only sso (no phantom sso-rw)", () => {+ assert.equal(buildGrokCookieHeader("eyJ0eXAi.abc.def"), "sso=eyJ0eXAi.abc.def");+});++test("buildGrokCookieHeader: single sso= pair emits only sso", () => {+ assert.equal(buildGrokCookieHeader("sso=eyJ0eXAi.abc"), "sso=eyJ0eXAi.abc");+});++test("buildGrokCookieHeader: full cookie blob forwards both sso and sso-rw", () => {+ const blob = "cf_clearance=zzz; sso=AAA.bbb; sso-rw=CCC.ddd; other=1";+ assert.equal(buildGrokCookieHeader(blob), "sso=AAA.bbb; sso-rw=CCC.ddd");+});++test("buildGrokCookieHeader: order-independent — sso-rw before sso in the blob", () => {+ const blob = "sso-rw=CCC.ddd; sso=AAA.bbb";+ assert.equal(buildGrokCookieHeader(blob), "sso=AAA.bbb; sso-rw=CCC.ddd");+});++test("buildGrokCookieHeader: blob with sso but no sso-rw emits only sso", () => {+ assert.equal(buildGrokCookieHeader("foo=1; sso=AAA.bbb; bar=2"), "sso=AAA.bbb");+});++test("buildGrokCookieHeader: blob without sso returns empty string", () => {+ assert.equal(buildGrokCookieHeader("foo=1; sso-rw=CCC.ddd; bar=2"), "");+ assert.equal(buildGrokCookieHeader(""), "");+});