Skip to content

codex login fails: Cloudflare challenge blocks CLI token exchange (Australia/Linux) #16052

Open

Description

@jakehower

Description

codex login and codex login --device-auth both fail with token_exchange_failed. Cloudflare's WAF is issuing a JavaScript challenge (cf-mitigated: challenge) on auth.openai.com, which the CLI's HTTP client cannot solve. This effectively makes the Codex CLI unusable without API key auth.

Error Messages

Browser OAuth flow:

Token exchange error: error sending request for url (https://auth.openai.com/oauth/token)
Error logging in: Token exchange failed: error sending request for url (https://auth.openai.com/oauth/token)

Device auth flow:

Error logging in with device code: error sending request for url (https://auth.openai.com/api/accounts/deviceauth/usercode)

Root Cause

curl -I https://auth.openai.com returns HTTP 403 with cf-mitigated: challenge — Cloudflare is serving a JavaScript challenge page ("Just a moment...") to non-browser clients. The Codex CLI's Rust HTTP client cannot solve this challenge, so the OAuth token exchange and device auth endpoints are unreachable.

HTTP/2 403
cf-mitigated: challenge
server: cloudflare

The browser OAuth redirect (step 1-3) works fine, but the server-to-server token exchange (step 4, CLI → auth.openai.com/oauth/token) is blocked by the challenge.

Environment

  • CLI version: codex-cli 0.117.0
  • OS: Arch Linux (kernel 6.19.6)
  • Region: Melbourne, Australia (cf-ray: *-MEL)
  • Install method: npm (~/.npm-global/bin/codex)

Reproduction

  1. codex logout
  2. codex login → fails with token_exchange_failed
  3. codex login --device-auth → fails with same error
  4. curl -I https://auth.openai.com → returns 403 with cf-mitigated: challenge

What I've ruled out

  • Happens on multiple networks (home and office) — not network-specific
  • Happens with Cloudflare WARP stopped (sudo systemctl stop warp-svc)
  • Happens with Tailscale down (sudo tailscale down)
  • Happens with no proxy env vars set
  • Happens on both IPv4 and IPv6
  • TLS handshake completes successfully (TLSv1.3 / TLS_AES_256_GCM_SHA384)
  • curl https://chatgpt.com/backend-api/codex/responses returns {"detail":"Method Not Allowed"} — so chatgpt.com endpoints are reachable

Expected Behavior

The CLI should be able to complete the OAuth token exchange without being blocked by Cloudflare's bot mitigation. Either:

  • The WAF rules on auth.openai.com should allowlist the Codex CLI's user-agent/request pattern, or
  • The CLI should handle Cloudflare challenges gracefully (e.g., falling back to device auth or providing clear guidance)

Activity

  1. added
    bugSomething isn't working
    CLIIssues related to the Codex CLI
    authIssues related to authentication and accounts
    on Mar 27, 2026
  2. github-actions commented on Mar 27, 2026

    @github-actions
    Contributor
  3. added
    authIssues related to authentication and accounts
    and removed
    authIssues related to authentication and accounts
    CLIIssues related to the Codex CLI
    on Mar 27, 2026
  4. ChocolatePancake commented on May 23, 2026

    @ChocolatePancake

    I have exactly the same issue. I am using two different proxy vps servers to login to codex. It used to work perfectly fine for the last three months

    Update: I checked two more ip addresses, they all get challenged by cloudflare. All the ip addresses are clean. Please fix it

  5. mastazi commented on Aug 31, 2026

    @mastazi

    I have the same issue. Getting cf-mitigated: challenge on Linux machine. Other machines from the same network work fine. Pausing my subscription in the meantime that this gets ironed out.

  6. unixapple commented on Sep 13, 2026

    @unixapple

    this is annoying and i managed to use cloudflare warp to be able to login but its a bit slow.

    so i vibed a project utlsproxy

    that make local requests to domains of auth.openai.com chatgpt.com to be proxied locally before sent to the OpenAI server, it use uTLS project under the hood so it can sent the proxied request with chrome fingerprint

    it make me to do codex sessions without using WARP, but i do not logout and relogin at the moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    authIssues related to authentication and accountsbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions