Skip to content

fix: route OAuth token requests through HTTPS_PROXY again - #11598

Merged
joehan merged 6 commits into
firebase:mainfrom
Ultranmus:fix/auth-client-proxy
Nov 30, 2026
Merged

joehan merged 6 commits into
firebase:mainfrom
Ultranmus:fix/auth-client-proxy

Conversation

@Ultranmus

Copy link
Copy Markdown
Contributor

Description

Fixes #11595.

Since 15.22.3 (#10717), getAuthClient() in src/requireAuth.ts sets transporterOptions.agent to apiv2.noKeepAliveAgent. gaxios uses a caller-supplied agent as is and skips its HTTPS_PROXY handling, and Node.js does not apply NODE_USE_ENV_PROXY to custom agents. So OAuth token requests skip the proxy, and in proxy-only environments (CI runners with GOOGLE_APPLICATION_CREDENTIALS) commands hang after command requires scopes and then fail.

This adds authTransporterAgent() to apiv2.ts, which returns the no-keep-alive agent only when no proxy is set in the environment. getAuthClient() passes the agent only when there is one. This matches the premature-close retry in apiv2.ts, which already skips its no-keep-alive agent when a proxy is set. Without a proxy, behavior is unchanged.

Scenarios Tested

  • New unit tests in apiv2.spec.ts: authTransporterAgent() returns the no-keep-alive agent with no proxy, and undefined for each of HTTPS_PROXY, https_proxy, HTTP_PROXY and http_proxy.
  • End to end with the compiled CLI: called requireAuth({}) with HTTPS_PROXY pointing at a local proxy and GOOGLE_APPLICATION_CREDENTIALS pointing at a fake service-account key.
    • With this change: the proxy receives CONNECT www.googleapis.com:443 and the call fails with invalid_grant, as expected for a fake key (same as 15.22.2 in the issue).
    • On main: the proxy receives nothing; the token request goes direct.
  • npm run mocha: 6145 passing. The 2 failures (should return expected tsc path, should output the date in the correct format) also fail on main on my machine.
  • tsc --noEmit, eslint (no new warnings) and prettier pass.

Sample Commands

No command or flag changes. Reproduction from the issue:

export HTTPS_PROXY=http://proxy.example:8888
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
firebase projects:list

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes an issue where OAuth token requests ignored the HTTPS_PROXY environment variable, causing commands to hang behind a proxy. It introduces authTransporterAgent in src/apiv2.ts which returns undefined if a proxy is configured in the environment, allowing gaxios to handle the proxy routing. Otherwise, it falls back to the standard noKeepAliveAgent. The getAuthClient function in src/requireAuth.ts is updated to use this new agent, and corresponding unit tests are added in src/apiv2.spec.ts. There are no review comments, so I have no feedback to provide.

@joehan

joehan commented Nov 30, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution! We could add some better tests here too

@codecov-commenter

codecov-commenter commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@c7d8259). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/requireAuth.ts 57.14% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11598   +/-   ##
=======================================
  Coverage        ?   61.33%           
=======================================
  Files           ?      870           
  Lines           ?    51132           
  Branches        ?    10319           
=======================================
  Hits            ?    31362           
  Misses          ?    18632           
  Partials        ?     1138           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Move building the GoogleAuth options into authClientOptions() so it can be
tested, and test it: the no-keep-alive agent without a proxy, no agent with
one, the caller's options kept, and a token request through a transporter
with these options reaching a local proxy as a CONNECT tunnel. That last
test fails without the fix (no request reaches the proxy).
@Ultranmus

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @joehan! I added tests in 7597f54:

  • requireAuth.ts now builds the auth client options in authClientOptions(), so they can be tested directly. The tests cover the no-keep-alive agent without a proxy, no agent when one is set, and the caller's options being kept.
  • A test starts a local proxy and sends a token request through a DefaultTransporter with those options, the way the auth client does. It checks that the request reaches the proxy as a CONNECT tunnel. Without the fix it fails, because no request reaches the proxy.

@joehan joehan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit on the new tests

Comment thread src/requireAuth.spec.ts Resolved
Ultranmus and others added 2 commits December 1, 2026 01:05
gaxios skips the proxy for hosts NO_PROXY (or no_proxy) lists, so the
token-request test failed on a machine where it covers the test host. Save
and clear both with the other proxy variables.
@joehan
joehan merged commit df2c7f4 into firebase:main Nov 30, 2026
20 checks passed
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.

requireAuth ignores HTTPS_PROXY since 15.22.3: custom no-keep-alive agent bypasses the proxy

3 participants