Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-fetch-native/proxy - noProxy does not properly parse hosts with port #125

Open
CS-JJ opened this issue Apr 16, 2024 · 1 comment
Open

Comments

@CS-JJ
Copy link

CS-JJ commented Apr 16, 2024

Environment

Node 21.6.1
node-fetch-native 1.6.4

Reproduction

Make any request specifying port in the url to a host that is on the noProxy list.

http_proxy = 10.0.0.1:3128
no_proxy = 10.10.10.10
await fetch('http://10.10.10.10:8001/healthz')

You should observe the host applying the proxy settings to the request instead of observing the specified no_proxy configuration

Describe the bug

The bypassProxy implementation does not check/parse the hostname from any port specification in the request.
This causes any requests to hosts in the no_proxy configuration using a specified port to have proxy configurations applied.

Suggested fix

host = host.split(':').at(0);

Additional context

There is an existing workaround to this issue by specifying the host with the port in the no_proxy variable
This would correctly bypass the proxy settings in the current implementation.

no_proxy=10.10.10.10:8001
fetch('10.10.10.10:8001/healthz') 

Logs

No response

@CS-JJ
Copy link
Author

CS-JJ commented Apr 29, 2024

ended cloning and running a local version for my project.

Realized that the implementation also doesn't support ip cidr ranges.

I'm running Node 21 and this implementation using the BlockList worked for me.

function bypassProxy(host, noProxy) {
  host = host.split(":").at(0);
  const blockList = new BlockList;
  for (const _host of noProxy) {
    if (/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/.test(_host)) {
      if (_host.search('/') >= 0) {
        blockList.addSubnet(_host.split("/").at(0), parseInt(_host.split("/").at(-1)))
      } else {
        blockList.addAddress(_host)
      }
    }
  }
  if (!noProxy) {
    return false;
  }
  for (const _host of noProxy) {
    if (_host === host || (_host[0] === "." && host.endsWith(_host.slice(1))) || blockList.check(host)) {
      return true;
    }
  }
  return false;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant