Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

npm install with proxy config triggers username + password auth requirment in proxy server although curl and web browser do not #18735

Open
4 of 7 tasks
sray opened this issue Oct 6, 2017 · 0 comments
Labels

Comments

@sray
Copy link

sray commented Oct 6, 2017

I'm opening this issue because:

  • npm is crashing.
  • npm is producing an incorrect install.
  • npm is doing something I don't understand.
  • Other (see below for feature requests):

What's going wrong?

Using npm (through windows cmd) behind a proxy that does not require username + password authentication with the following npm config results in the proxy denying npm cli the request and requesting username + password authentication.

Requesting the same npm using curl (in git bash) does not trigger the proxy to interfere and the http request is processed as expected. The response json is identical to the json you get accessing http://registry.npmjs.org/[somepackage] directly through the browser.

How can the CLI team reproduce the problem?

  1. install latest node and npm
  2. adjust npm config (see supporting information) to use a proxy that runs in two modes (requiring credentials for accessing some resources and not requiring credentials for standard web resources like npmjs.org)
  3. run npm install [somepackage]

generates the error (see npm-debug.log)

compare with:

  1. install latest git bash for windows
  2. run curl -k -L --proxy [proxy-host]:[proxy-port] http://registry.npmjs.org/[somepackage] -o [somepackage].json

returns the expected json from standard npm registry

supporting information:

  • npm config get registry prints: http://registry.npmjs.org/

  • npm config adjustments:

strict-ssl=false
registry=http://registry.npmjs.org/
proxy=http://[proxy-host]:[proxy-port]/
proxy-https=http://[proxy-host]:[proxy-port]/
  • OS: Windows 7

  • Network:

    • Geographic location where npm was run:
    • I use a proxy to connect to the npm registry.
    • I use a proxy to connect to the web.
    • I use a proxy when downloading Git repos.
  • npm-debug.log of running npm install htmlparser:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\tools\\nodejs\\node-v6.11.3-win-x64\\node.exe',
1 verbose cli   'C:\\tools\\nodejs\\node-v6.11.3-win-x64\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'install',
1 verbose cli   'htmlparser' ]
2 info using npm@3.10.10
3 info using node@v6.11.3
4 silly loadCurrentTree Starting
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 silly fetchPackageMetaData htmlparser
8 silly fetchNamedPackageData htmlparser
9 silly mapToRegistry name htmlparser
10 silly mapToRegistry using default registry
11 silly mapToRegistry registry http://registry.npmjs.org/
12 silly mapToRegistry data Result {
12 silly mapToRegistry   raw: 'htmlparser',
12 silly mapToRegistry   scope: null,
12 silly mapToRegistry   escapedName: 'htmlparser',
12 silly mapToRegistry   name: 'htmlparser',
12 silly mapToRegistry   rawSpec: '',
12 silly mapToRegistry   spec: 'latest',
12 silly mapToRegistry   type: 'tag' }
13 silly mapToRegistry uri http://registry.npmjs.org/htmlparser
14 verbose request uri http://registry.npmjs.org/htmlparser
15 verbose request no auth needed
16 info attempt registry request try #1 at 16:18:25
17 verbose request id 0a6fcc8d0d3a3b87
18 http request GET http://registry.npmjs.org/htmlparser
19 http 401 http://registry.npmjs.org/htmlparser
20 verbose bad json <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
[...]
20 verbose bad json Access to this website requires authentication.
[...]
20 verbose bad json <div class="details"><p>
20 verbose bad json username: <br />
20 verbose bad json Requesting-IP: [my-internal-machine-ip]<br />
20 verbose bad json URL: GET http://[proxy-host]:[proxy-port]/[some random string]/[requesting-ip]/http://registry.npmjs.org/htmlparser<br />
20 verbose bad json category: <br />
20 verbose bad json reason: UNKNOWN<br />
20 verbose bad json message: WWW_AUTH_REQUIRED
20 verbose bad json </p></div>
20 verbose bad json </body>
20 verbose bad json </html>
21 error registry error parsing json
[...]

The request by npm seems to be forwarded to a second proxy with a different proxy port and some url rewriting whereas the request made by curl does not. I would expect both http get requests made by npm and curl to be identical and thus resulting in the same behaviour of the proxy. Since I can download the htmlparser json from the registry with other tools (like my web browser), it seems to be a proxy configuration issue within npm that somehow creates a different request than the one curl or my web browser create. But I am by no means sure ;-) So, if you have other suggestions where to look for clues to explain and fix this inconsistent behaviour, let me know.

@kenany kenany added the proxy label Oct 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants