[BUG] Agent does not respect npm's noproxy config when initiating request using environment instead
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
- Deploy an NPM package to a URL that requires the use of a proxy server to access
- Set your system's
no_proxyenvironment variable to INCLUDE this domain- (This seems counter-intuitive, yes, see comment about corporate environment above)
- Set NPM's
noproxyconfig value (e.g. in ~/.npmrc or directory-local .npmrc) to EXCLUDE this domain- e.g. if
NO_PROXY=.example.com,.actually-needs-proxy.foo, then set .npmrc tonoproxy=.example.com - The expectation being that NPM config's
noproxywould override the system's environment variables
- e.g. if
- Attempt to
npm installthe package from step 1 - 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
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di npm/agent
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 48/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 22/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
-
Add LICENSE.mdForse già presa @Suryaseenivasan2005 l’ha presa 149 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
Issue simili
-
docs: add SECURITY.md vulnerability reporting policyForse già presa @AK-Lmn l’ha presa oggi. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
flisk-sh/linux2wasm#12 ·
I maintainer di solito rispondono entro 1 giorno
-
possible bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
Mintplex-Labs/anything-llm#7388 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 60/100
I maintainer di solito rispondono entro 1 giorno
-
v6: Minified bootstrap.min.css is missing header infoForse già presa @lazerg l’ha presa oggi. Apertabug build confirmed has-pr v6
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
[workshop-sync] workshop/side-quest-26-01-forecast-costs.md: forecast default history window is inaccurateForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertadocumentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
githubnext/gh-aw-workshop#6332 ·
I maintainer di solito rispondono entro 1 giorno