[BUG] Agent does not respect npm's noproxy config when initiating request using environment instead

Aperta
#125 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@ychampion ci sta già lavorando.

Dal 13/11/2026.

  • #177 di @ychampion — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript, nodejs
Ambito
networking

Direzione di ricerca

Start in lib/index.js::getAgent and trace the normalizedOptions passed to lib/agents.js, then compare the proxy handling with lib/proxy.js::getProxy and isNoProxy. Reproduce the differing NPM and environment noproxy values from the issue; done means the configured NPM noproxy value is used consistently throughout the request lifecycle.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Is there an existing issue for this?
  • I have searched the existing issues
Current Behavior

In lib/index.js::getAgent when constructing the appropriate Agent for a request for the first time, the proxy and noProxy options are passed through from NPM's config. The calls to lib/proxy.js::getProxy and lib/proxy.js::isNoProxy use those values, and this results in proxyForUrl in getAgent having the appropriate proxy URL set for the request.

However, the normalizedOptions are built with only the proxy option set. This means that when agent is constructed, lib/agents.js::Agent::#noProxy is null.

When lib/agents.js::Agent::#getProxy is ultimately called to start the request, it makes another call to lib/proxy.js::getProxy but passes noProxy: null (set by the constructor) to the options argument resulting in using the environment variable no_proxy/NO_PROXY value instead.

When environment no_proxy/NO_PROXY and NPM config's noproxy value differ, this results in not using the proxy (because of env NO_PROXY) rather than using it (because of NPM config).


This seems to be something bizarre with our corporate private package locations where there are some resources on a domain that need the corp proxy while other resources on the domain don't.

However, I think that this is still a bug with NPM as the chosen "no proxy" value — whether it be environment or npm config — should be consistent throughout the whole request process for a given resource.

Expected Behavior

The NPM config's noproxy value should be used consistently throughout the request lifecycle for a particular package/resource.

I think that this can be achieved by adding noProxy to normalizedOptions in lib/index.js::getAgent, although it may need to be excluded from cacheKey.


If the expectation is that the system's environment variables should always win over NPM config, a different change would likely be necessary (likely ignoring noProxy option during getAgent).

Steps To Reproduce
  1. Deploy an NPM package to a URL that requires the use of a proxy server to access
  2. Set your system's no_proxy environment variable to INCLUDE this domain
    1. (This seems counter-intuitive, yes, see comment about corporate environment above)
  3. Set NPM's noproxy config value (e.g. in ~/.npmrc or directory-local .npmrc) to EXCLUDE this domain
    1. e.g. if NO_PROXY=.example.com,.actually-needs-proxy.foo, then set .npmrc to noproxy=.example.com
    2. The expectation being that NPM config's noproxy would override the system's environment variables
  4. Attempt to npm install the package from step 1
  5. Observe ETIMEDOUT error as @npmcli/agent attempts to use environmental NO_PROXY over NPM config noproxy
Environment
  • npm: 10.9.2 (however, verified that NPM 11.x uses this same version of @npmcli/agent)
  • Node: 18.20.8
  • OS: macOS
  • platform: MPB M1 Pro 2021
Lingua principale
JavaScript
Stelle
9
Fork
15
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di npm/agent

Tutte le issue di npm/agent

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.