diff --git a/doc/environment_variables.md b/doc/environment_variables.md index 8ade5018..04bb6374 100644 --- a/doc/environment_variables.md +++ b/doc/environment_variables.md @@ -11,7 +11,7 @@ can be set. checked in order, and the first one that has a value is used. * no_grpc_proxy, no_proxy - A comma separated list of comma-separated list of hostnames, IP addresses, + A comma separated list of hostnames, IP addresses, or CIDR blocks to connect to without using a proxy even if a proxy is set, for example: no_proxy=example.com,192.168.0.1,192.168.0.0/16. These variables are checked in order, and the first one diff --git a/packages/grpc-js/src/http_proxy.ts b/packages/grpc-js/src/http_proxy.ts index e4edfe01..ceeaa174 100644 --- a/packages/grpc-js/src/http_proxy.ts +++ b/packages/grpc-js/src/http_proxy.ts @@ -160,18 +160,18 @@ function isIpInCIDR(cidr: CIDRNotation, serverHost: string) { function hostMatchesNoProxyList(serverHost: string): boolean { for (const host of getNoProxyHostList()) { const parsedCIDR = parseCIDR(host); + // host is a CIDR and serverHost is an IP address + if (isIPv4(serverHost) && parsedCIDR && isIpInCIDR(parsedCIDR, serverHost)) { + trace('Not using proxy for target in no_proxy list: ' + serverHost); + return true; + } // host is a single IP or a domain name suffix - if (!parsedCIDR) { - if (host === serverHost || serverHost.includes(host)) { + else { + if (serverHost.endsWith(host)) { trace('Not using proxy for target in no_proxy list: ' + serverHost); return true; } } - // host is a CIDR or a domain - else if (isIpInCIDR(parsedCIDR, serverHost)) { - trace('Not using proxy for target in no_proxy list: ' + serverHost); - return true; - } } return false; }