Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix: accept the live xAI device verification host accounts.x.ai

Jose Gabriel Ramirez Encinas0e09861a9fa2
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index c39cbd285..cf98c3332 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.579",
+ "version": "0.1.580",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.579",
+ "version": "0.1.580",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",
diff --git a/control-api/package.json b/control-api/package.json
index 794acfe67..f32194a25 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.579",
+ "version": "0.1.580",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/services/grokSubscriptionOAuth.ts b/control-api/src/services/grokSubscriptionOAuth.ts
index c15cf0a0f..5685bd9c9 100644
--- a/control-api/src/services/grokSubscriptionOAuth.ts
+++ b/control-api/src/services/grokSubscriptionOAuth.ts
@@ -43,6 +43,12 @@ export const GROK_OAUTH_DEVICE_URL = 'https://auth.x.ai/oauth2/device/code'
export const GROK_OAUTH_TOKEN_URL = 'https://auth.x.ai/oauth2/token'
export const GROK_OAUTH_REVOKE_URL = 'https://auth.x.ai/oauth2/revoke'
export const GROK_OAUTH_DEVICE_GRANT = 'urn:ietf:params:oauth:grant-type:device_code'
+/**
+ * Exact hosts allowed for the user-facing device verification page. The live
+ * xAI device endpoint returns https://accounts.x.ai/oauth2/device (probed
+ * 2026-09-18); auth.x.ai stays allowed for the OAuth endpoints' own origin.
+ */
+export const GROK_OAUTH_VERIFICATION_HOSTS: readonly string[] = ['auth.x.ai', 'accounts.x.ai']
export const GROK_OAUTH_SCOPES = [
'openid',
'profile',
@@ -758,7 +764,7 @@ function assertVerificationUri(value: string): string {
'device verification URI is invalid'
)
}
- if (parsed.protocol !== 'https:' || parsed.hostname !== 'auth.x.ai') {
+ if (parsed.protocol !== 'https:' || !GROK_OAUTH_VERIFICATION_HOSTS.includes(parsed.hostname)) {
throw new GrokSubscriptionOAuthError(
'provider_unavailable',
'device verification URI origin is not frozen'
diff --git a/control-api/test/services.grokSubscriptionOAuth.test.ts b/control-api/test/services.grokSubscriptionOAuth.test.ts
index 62da05865..e028eb4ad 100644
--- a/control-api/test/services.grokSubscriptionOAuth.test.ts
+++ b/control-api/test/services.grokSubscriptionOAuth.test.ts
@@ -168,6 +168,51 @@ describe('grok subscription OAuth device broker', () => {
expect(JSON.stringify(result)).not.toContain('device-secret')
})
+ // Live xAI device endpoint (probed 2026-09-18) returns
+ // verification_uri=https://accounts.x.ai/oauth2/device, not auth.x.ai.
+ it.each([
+ ['https://accounts.x.ai/oauth2/device', true],
+ ['https://auth.x.ai/activate', true],
+ ['http://accounts.x.ai/oauth2/device', false],
+ ['https://accounts.x.ai.evil.example/oauth2/device', false],
+ ['https://evil.x.ai/oauth2/device', false],
+ ])('device start verification_uri %s allowed=%s', async (uri, allowed) => {
+ repos.insertState.mockImplementation(
+ async (
+ _db: unknown,
+ _key: Buffer,
+ input: { state: string; intent: string; expiresAt: Date }
+ ) => ({
+ state: input.state,
+ flow: 'device',
+ intent: input.intent,
+ status: 'pending',
+ connectionKey: CONNECTION_KEY,
+ expiresAt: input.expiresAt,
+ consumedAt: null,
+ cancelledAt: null,
+ createdAt: new Date(),
+ })
+ )
+ const fetchFn = vi.fn().mockResolvedValue({
+ ok: true,
+ status: 200,
+ json: async () => ({
+ device_code: 'device-secret',
+ user_code: 'ABCD-EFGH',
+ verification_uri: uri,
+ expires_in: 1800,
+ interval: 5,
+ }),
+ })
+ const run = startGrokDeviceConnect(deps(fetchFn), 'connect')
+ if (allowed) {
+ await expect(run).resolves.toMatchObject({ verificationUri: new URL(uri).toString() })
+ } else {
+ await expect(run).rejects.toMatchObject({ code: 'provider_unavailable' })
+ }
+ })
+
it('does not follow OAuth token redirects and treats 3xx as provider_unavailable', async () => {
repos.peekState.mockResolvedValue({
safe: {
diff --git a/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx b/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx
index dd2b82df9..010571f02 100644
--- a/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx
+++ b/control-ui/components/__tests__/CodexSubscriptionHub.test.tsx
@@ -763,7 +763,7 @@ describe('CodexSubscriptionHub with Grok enabled', () => {
fireEvent.click(screen.getByRole('menuitem', { name: 'Update' }))
fireEvent.click(await screen.findByRole('button', { name: 'Sign in with Grok' }))
const link = await screen.findByTestId('codex-device-verification-link')
- expect(link).toHaveAttribute('href', 'https://auth.x.ai')
+ expect(link).toHaveAttribute('href', 'https://accounts.x.ai/oauth2/device')
expect(link).not.toHaveAttribute('href', CODEX_DEVICE_VERIFICATION_URI)
// An unusable URI is never navigated to; the pre-opened tab is closed.
expect(tab.location.replace).not.toHaveBeenCalled()
diff --git a/control-ui/lib/__tests__/grokSubscriptionFeature.test.ts b/control-ui/lib/__tests__/grokSubscriptionFeature.test.ts
index 6f1a5375f..e8eea945c 100644
--- a/control-ui/lib/__tests__/grokSubscriptionFeature.test.ts
+++ b/control-ui/lib/__tests__/grokSubscriptionFeature.test.ts
@@ -43,6 +43,18 @@ describe('isAllowedGrokVerificationUri', () => {
expect(isAllowedGrokVerificationUri('https://auth.x.ai/device?user_code=ABCD')).toBe(true)
})
+ it('accepts the live xAI device verification page on accounts.x.ai', () => {
+ expect(isAllowedGrokVerificationUri('https://accounts.x.ai/oauth2/device')).toBe(true)
+ expect(isAllowedGrokVerificationUri('https://accounts.x.ai/oauth2/device?user_code=ABCD')).toBe(
+ true
+ )
+ expect(isAllowedGrokVerificationUri('http://accounts.x.ai/oauth2/device')).toBe(false)
+ expect(isAllowedGrokVerificationUri('https://accounts.x.ai.evil.example/oauth2/device')).toBe(
+ false
+ )
+ expect(isAllowedGrokVerificationUri('https://evil.x.ai/oauth2/device')).toBe(false)
+ })
+
it('rejects other schemes, hosts and look-alike hosts', () => {
expect(isAllowedGrokVerificationUri('http://auth.x.ai/device')).toBe(false)
expect(isAllowedGrokVerificationUri('https://auth.x.ai.evil.example/device')).toBe(false)
diff --git a/control-ui/lib/grokSubscription.ts b/control-ui/lib/grokSubscription.ts
index 8c267075b..4c98d86de 100644
--- a/control-ui/lib/grokSubscription.ts
+++ b/control-ui/lib/grokSubscription.ts
@@ -14,7 +14,7 @@ import {
export const GROK_SUBSCRIPTION_API_BASE = '/api/v1/admin/llm/providers/grok-subscription'
export const GROK_UNASSIGNED_CONNECTION_KEY = CODEX_UNASSIGNED_CONNECTION_KEY
export const SUBSCRIPTION_CONNECTION_REF_ANNOTATION = 'clerum.io/subscription-connection-ref'
-export const GROK_DEVICE_VERIFICATION_ORIGIN = 'https://auth.x.ai'
+export const GROK_DEVICE_VERIFICATION_ORIGIN = 'https://accounts.x.ai/oauth2/device'
export type GrokSubscriptionConnectionView = CodexSubscriptionConnectionView
export type GrokAssignableHost = CodexAssignableHost
@@ -64,7 +64,11 @@ function pickNumber(value: unknown, fallback = 0): number {
export function isAllowedGrokVerificationUri(value: string): boolean {
try {
const parsed = new URL(value)
- return parsed.protocol === 'https:' && parsed.hostname === 'auth.x.ai'
+ // Exact hosts: the live xAI device page is accounts.x.ai/oauth2/device.
+ return (
+ parsed.protocol === 'https:' &&
+ (parsed.hostname === 'auth.x.ai' || parsed.hostname === 'accounts.x.ai')
+ )
} catch {
return false
}
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index aa6fe2991..5340e6d03 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.592",
+ "version": "0.1.593",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.592",
+ "version": "0.1.593",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/control-ui/package.json b/control-ui/package.json
index a2f38f71b..7174bcbb0 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.592",
+ "version": "0.1.593",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",
diff --git a/docs/architecture/grok-subscription-transport-contract.md b/docs/architecture/grok-subscription-transport-contract.md
index 986a30c1d..97f699417 100644
--- a/docs/architecture/grok-subscription-transport-contract.md
+++ b/docs/architecture/grok-subscription-transport-contract.md
@@ -45,6 +45,7 @@ Exact HTTPS origins (no caller-supplied URL):
- Device authorization: `https://auth.x.ai/oauth2/device/code`
- Token: `https://auth.x.ai/oauth2/token`
- Revoke: `https://auth.x.ai/oauth2/revoke`
+- Device verification page (user-facing, returned by the device endpoint; confirmed by live probe 2026-09-18): `https://accounts.x.ai/oauth2/device`. Control API and Control UI accept only the exact hosts `auth.x.ai` and `accounts.x.ai` over HTTPS.
- Completions: `https://cli-chat-proxy.grok.com/v1/responses`
- Catalog (starting candidate): `https://cli-chat-proxy.grok.com/v1/models`