Skip to content

google-gemini-cli-auth: OAuth token exchange fails behind proxy (fetchWithSsrFGuard uses createPinnedDispatcher instead of EnvHttpProxyAgent) #34401

Closed as not planned

Description

@lyfuci

Summary

When running openclaw config to authenticate with Google Gemini CLI OAuth, the exchangeCodeForTokens step fails with AbortError: This operation was aborted on machines that require an HTTP proxy to reach Google's servers.

Root Cause

In google-gemini-cli-auth/oauth.ts, the fetchWithTimeout call uses fetchWithSsrFGuard which defaults to createPinnedDispatcher mode. This dispatcher resolves the hostname to an IP and connects directly, bypassing the system proxy environment variables (http_proxy/https_proxy/HTTPS_PROXY).

The relevant branch in fetchWithSsrFGuard:

if (mode === GUARDED_FETCH_MODE.TRUSTED_ENV_PROXY && hasProxyEnvConfigured())
    dispatcher = new EnvHttpProxyAgent(); // ← this path is NOT taken for OAuth
else if (params.pinDns !== false)
    dispatcher = createPinnedDispatcher(pinned); // ← direct IP, bypasses proxy

Since exchangeCodeForTokens (oauth.ts:414) posts to https://oauth2.googleapis.com/token, on machines where direct outbound connections to Google IPs are blocked (common in China / corporate networks), the request times out and throws AbortError.

Reproduction

  1. Set up a machine where https_proxy=http://<proxy>:<port> is required to reach Google
  2. Confirm curl https://oauth2.googleapis.com/ works (via proxy)
  3. Confirm direct IP connection to 172.253.117.95:443 times out (no proxy)
  4. Run openclaw config → select Google → Gemini CLI OAuth
  5. Complete browser authentication successfully
  6. Observe: AbortError: This operation was aborted at exchangeCodeForTokens

Expected Behavior

The OAuth token exchange request should respect the system proxy settings (HTTPS_PROXY/https_proxy) and use EnvHttpProxyAgent (or equivalent) when proxy env vars are configured.

Suggested Fix

Pass pinDns: false or use TRUSTED_ENV_PROXY mode for the fetchWithSsrFGuard call in exchangeCodeForTokens (and ideally all OAuth-related fetches in the plugin):

const { response, release } = await fetchWithSsrFGuard({
  url: TOKEN_URL,
  init: { ... },
  // Add this to respect system proxy:
  pinDns: false,
  // or use TRUSTED_ENV_PROXY mode
});

Environment

  • OpenClaw version: 2026.3.2
  • OS: Linux Ubuntu (x64)
  • Node.js: v24.13.1
  • Network: HTTP proxy required for external access (https_proxy=http://192.168.31.99:8910)
  • no_proxy correctly excludes LAN ranges, but Google IPs require proxy

Activity

  1. lyfuci commented on Mar 4, 2026

    @lyfuci
    ContributorAuthor

    Additional Error Variant

    When attempting with NODE_OPTIONS="--dns-result-order=ipv4first" GLOBAL_AGENT_HTTP_PROXY=... workaround, the error changes to TypeError: fetch failed (immediate network rejection rather than timeout):

    [openclaw] Failed to start CLI: TypeError: fetch failed
     at node:internal/deps/undici/undici:16416:13
     at async fetchWithSsrFGuard (.../fetch-guard-TrC02Qcz.js:117:24)
     at async fetchWithTimeout (.../oauth.ts:244:33)
     at async exchangeCodeForTokens (.../oauth.ts:414:20)
    

    Both AbortError: This operation was aborted (timeout) and TypeError: fetch failed (immediate rejection) stem from the same root cause — createPinnedDispatcher bypasses system proxy and attempts a direct connection to Google's IP, which is blocked.

    The NODE_OPTIONS / GLOBAL_AGENT_HTTP_PROXY workaround has no effect because fetchWithSsrFGuard uses its own undici dispatcher, not the global Node.js http agent.

  2. lyfuci commented on Mar 4, 2026

    @lyfuci
    ContributorAuthor

    Local Patch (workaround until official fix)

    Applied the following patch to extensions/google-gemini-cli-auth/oauth.ts:

      const { response, release } = await fetchWithSsrFGuard({
        url,
        init,
        timeoutMs,
    +   pinDns: false,
      });

    This allows fetchWithSsrFGuard to fall through to EnvHttpProxyAgent when proxy env vars are configured, instead of using createPinnedDispatcher which bypasses the proxy entirely.

    After applying this patch, the OAuth token exchange successfully completes through the system proxy.

  3. added a commit that references this issue on Mar 4, 2026
    a09907c
  4. openclaw-barnacle commented on Apr 14, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  5. added
    stale
    on Apr 14, 2026
  6. openclaw-barnacle commented on Apr 21, 2026

    @openclaw-barnacle

    Closing due to inactivity.
    If this is still an issue, please retry on the latest OpenClaw release and share updated details.
    If you are absolutely sure it still happens on the latest release, open a new issue with fresh repro steps.

  7. locked as resolved and limited conversation to collaborators on Apr 24, 2026
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

    stale

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions