Repository navigation
fix: send all requests through the configured HTTP proxy - #10013
Draft
kuldeepsinh19 wants to merge 1 commit into
Draft
kuldeepsinh19 wants to merge 1 commit into
kuldeepsinh19 wants to merge 1 commit into
Conversation
`--http-proxy` (which defaults to `HTTP_PROXY`/`HTTPS_PROXY`) was only passed to the CLI's Netlify API client. Every other request bypassed the proxy and failed on networks that require one: - Node.js's built-in `fetch()` ignores both the `agent` option and the proxy environment variables. It's used by `@netlify/config` to fetch the site's extensions and by the CLI's own `fetch()` calls. - `http`/`https` requests that don't set an agent, such as those made by the Netlify API client that `@netlify/config` creates to fetch the site info, use the default global agent. When a proxy is configured, also install an undici `EnvHttpProxyAgent` as the global dispatcher and a proxy agent as `https.globalAgent`. Both use the same proxy URL and CA certificate, respect `NO_PROXY` (with the same matching rules), and never proxy requests to the local machine. Fixes netlify#3115
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
CodeRabbit Verify
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3115
On a network where the internet is only reachable through a proxy, even
netlify statusfails (see #3115 (comment)):--http-proxy(which defaults toHTTP_PROXY/HTTPS_PROXY) is only passed as anHttpsProxyAgentto the CLI's own Netlify API client. Every other request bypasses the proxy:fetch()ignores both theagentoption and the proxy environment variables. It's used by@netlify/config(site extensions) and by about 35 of the CLI's own calls (deploy,logs,db,functions:create, live tunnel, …).http/httpsrequests without an agent use Node's default global agent. That includes the separate Netlify API client@netlify/configcreates for the site info (@netlify/apiusesnode-fetch).resolveConfig()has no option to pass an agent, so this can't be fixed by passing ours through.When a proxy is configured,
getAgent()now also sets:EnvHttpProxyAgentas the global dispatcher, for case 1;https.globalAgentto anHttpsProxyAgentsubclass that connects directly to hosts it shouldn't proxy, for case 2.Both:
--http-proxy-certificate-filenameCA as the existing agent;NO_PROXY/no_proxy, with the same matching rules as undici;localhost,127.0.0.1,[::1]), so the framework server and functions server innetlify devare unaffected.Nothing changes when no proxy is configured.
Notes:
undiciwas already in the lockfile (7.30.1, through cheerio) as a dev dependency. It's now a direct dependency at the same version, so the lockfile diff only drops"dev": true. I didn't useNODE_USE_ENV_PROXY/http.setGlobalProxyFromEnv()because they aren't available on all Node versions inengines(>=22.13.0).netlify devwith a proxy configured, outgoingfetch()/httpscalls from function code that runs in the CLI's process also go through the proxy (except local andNO_PROXYhosts). That's what users behind a proxy need, but it's a change.HttpsProxyAgentWithCA) as it is. It still doesn't applyNO_PROXY, as before. Itscallback()override is never called withhttps-proxy-agentv8: agent-base only callsconnect(). So--http-proxy-certificate-filenamecurrently doesn't apply to that client. I'm happy to fix that in a follow-up.Verification
I recreated the issue's network in a container:
/etc/hostspointsapi.netlify.comandapi.netlifysdk.comat a closed port, so they can only be reached through a logging proxy (which resolves them with real DNS). Then I ranHTTP_PROXY=… netlify status --debugwith the built CLI and a dummy token:main@netlify/configsite inforequest to https://api.netlify.com/api/v1/sites/… failed, reason: connect ECONNREFUSEDUnauthorizedwith the dummy token)@netlify/configextensionsCONNECT api.netlifysdk.com:443)Tests in
tests/unit/lib/http-agent.test.ts(with a local proxy that records requests):getAgent(), a globalfetch()goes through the proxy. This fails onmain.getAgent(), anhttpsrequest without an agent (node-fetch) goes through the proxy. This fails onmain.localhostdon't go through the proxy.NO_PROXYhosts and their subdomains don't go through the proxy, for bothfetch()andhttps.npm run test:unit(846 tests),npm run typecheck,eslint(no new suppressions) andoxfmt --checkpass. The new tests also pass on Node 22.13.0. I didn't run the integration suites.This change was written with help from an AI coding assistant (Claude Code). I've reviewed every line and can explain any of it.