netlify / netlify/cli

Proxy support is broken

Open
#3,115 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: configuration good first issue status: confirmed type: bug
Dominant language
TypeScript
Stars
1.9k
Forks
474
Avg merge
23h 30m
Merged PRs (30d)
53

Description

Describe the bug

Proxy support was introduced in #1215, but it is currently broken.

To Reproduce

Steps to reproduce the behavior:

  1. Somehow make api.netlify.com unavailable, e.g. by being on a closed network where a proxy is required. For reproduction purposes, one can force this by modifying /etc/hosts and pointing api.netlify.com to a local container / VM where we spin up a trivial HTTP server that simply stalls on any incoming request.
  2. Have a proxy server set up, e.g. mitmproxy or Charles.
  3. Run any command through a proxy, e.g. HTTP_PROXY=http://localhost:8888 netlify login.

At this point netlify-cli would simply stall, and if you monitor the proxy server you'll notice that no request is going through it.

Configuration

N/A.

Expected behavior

Any network request originating from netlify-cli should be proxied.

CLI Output

N/A.

Additional context

This happens because getConfig happens before the proxy is even configured (with getAgent)

https://github.com/netlify/cli/blob/7a55e9871059ac656096735d1c0369b4d473e07e/src/utils/command.js#L46-L57

getConfig calls resolveConfig which is @netlify/config.

https://github.com/netlify/cli/blob/7a55e9871059ac656096735d1c0369b4d473e07e/src/utils/command.js#L4

Looking at @netlify/config's resolveConfig: https://github.com/netlify/build/blob/6813d73a21a6c4a6b99576c5b7bc60fae5d8bac4/packages/config/src/main.js#L32-L36 we see that there are API requests made at this stage unless offline is true. These requests obviously aren't going through the proxy.

I guess to actually fully support proxies you need to add proxy support to @netlify/config as well.


Knowing the cause of the issue, here's a risky workaround btw: just set offline to true in src/utils/command.js:

-    const cachedConfig = await this.getConfig({ cwd, state, token, ...apiUrlOpts })
+    const cachedConfig = await this.getConfig({ cwd, state, token, offline: true, ...apiUrlOpts })

One can hot edit this directly into node_modules/netlify-cli/src/utils/command.js. (Don't complain to me if anything breaks, obviously.)


Related: I believe #2016 is exactly this problem.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/utils/command.js, where getConfig runs before getAgent configures the proxy, then trace resolveConfig in @netlify/config at packages/config/src/main.js. Reproduce with HTTP_PROXY=http://localhost:8888 netlify login and a stalled api.netlify.com endpoint. Done means the initial configuration requests use the proxy without breaking normal or offline behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
cli, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.