frontend-maven-plugin icon indicating copy to clipboard operation
frontend-maven-plugin copied to clipboard

Non-Proxy hosts with wildcards are incorrectly passed to npm

Open StefanBauerTT opened this issue 9 months ago • 6 comments
trafficstars

Steps to reproduce

  • Configure a maven proxy with a wildcard non proxy hosts, e.g. *.google.de (see DefaultNpmRunnerTest.java)

Expected result

  • npm is called with --noproxy=*.google.de

Actual result

  • npm is called with --noproxy=.google.de. The asterisk is missing. ~~npm does not understand this syntax.~~

Analysis

  • in https://github.com/eirslett/frontend-maven-plugin/blame/b7b060fa13ca47e69172ee6d06194ffd41c35084/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NpmRunner.java#L39 , asterisks are deliberately removed

StefanBauerTT avatar Jan 30 '25 05:01 StefanBauerTT

@tkalmar do you remember any of this?

eirslett avatar Jan 30 '25 13:01 eirslett

short test:

npm config set https-proxy https://proxy.example.com:1337
npm show lodash    --registry=https://registry.npmjs.org/ <-- timeout
npm show lodash    --registry=https://registry.npmjs.org/ --noproxy=.npmjs.org <-- works
npm show lodash    --registry=https://registry.npmjs.org/ --noproxy=*.npmjs.org <-- timeout

so i can't confirm that npm does not understand this syntax

tkalmar avatar Jan 30 '25 14:01 tkalmar

Thank you for your swift response, @eirslett and @tkalmar. I missed a piece of the puzzle. The error occurred when running npm install. Our package.json contains a dependency with explicit git hostname like:

{
  "devDependencies": {
    "privateLib": "git+https://git.corp.network/privateLib.git#main"
  }
}

Error message was:

[INFO] Found proxies: [httpsproxy{protocol='https', host='proxy.corp.network', port=8080, nonProxyHosts='*.corp.network'}]
[INFO] npm error code 128
[INFO] npm error An unknown git error occurred
[INFO] npm error command git --no-replace-objects ls-remote https://git.corp.network/privateLib.git
[INFO] npm error fatal: unable to access 'https://git.corp.network/privateLib.git': Received HTTP code 503 from proxy after CONNECT

~~I had to explicitly add git.corp.network to the maven non-proxy hosts to make this work.~~ (Note from the future: It did not fix it)

I tried calling npm install --noproxy=*.corp.network and it also fails. So I was wrong with my guess that the asterisk is missing. Thanks for pointing that out. So this is a bug in npm itself?

StefanBauerTT avatar Jan 30 '25 14:01 StefanBauerTT

@StefanBauerTT I don't think that npm passes the proxy config to the git client. you could try to configure a no_proxy environment variable which should be used by git (i think also without *) So i think

<configuration>
    <environmentVariables>
        <no_proxy>.corp.network</no_proxy>
    </environmentVariables>        
</configuration>

should work.

tkalmar avatar Jan 30 '25 16:01 tkalmar

I found the place where the proxy settings get passed from the frontend plugin to git via environment variables:

https://github.com/eirslett/frontend-maven-plugin/blob/b7b060fa13ca47e69172ee6d06194ffd41c35084/frontend-plugin-core/src/main/java/com/github/eirslett/maven/plugins/frontend/lib/NpmRunner.java#L54

Surprisingly though, the no_proxy environment variable is not set here, so right now I don't understand how adding git.corp.network to the <nonProxyHosts> of my maven settings.xml fixed the issue.

StefanBauerTT avatar Jan 31 '25 06:01 StefanBauerTT

Ok, sorry for the confustion. Adding git.corp.network to the <nonProxyHosts> in the maven settings.xml acutally fixed nothing.

So the bottom line of this is that the frontend plugin sets the https_proxy but not the no_proxy environment variable. One could argue that this is inconsistent and can lead to confusing errors, just like the one I experienced.

I will leave it up to you if you consinder this a bug worth fixing or close this ticket with reference to @tkalmar 's workaround from https://github.com/eirslett/frontend-maven-plugin/issues/1172#issuecomment-2624910876 . Thank you for your time.

StefanBauerTT avatar Jan 31 '25 09:01 StefanBauerTT