Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

grpc-js: Parsing logic of no_grpc_proxy/no_proxy variable(s) is flawed

Aperta
#3,039 1 commento 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
node.js, typescript
Ambito
networking

Direzione di ricerca

Inizia individuando l’entry point interno hostMatchesNoProxyList e confrontalo con il comportamento riprodotto in reproduce-bug.js. Esegui docker compose up --build, quindi verifica che gli host esatti e i sottodomini validi bypassino il proxy, mentre suffissi non correlati come notlocal.com e snapple.com non lo facciano.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem description

The logic for checking whether a host matches the no proxy list in hostMatchesNoProxyList is flawed due to the naive endsWith(host) logic.

Reproduction steps

Note these reproduction steps copy the function logic and have no dependency on the package as the relevant internal functions aren't publicly exposed. Parts unrelated to the bug with external dependencies are commented out and a version with a proposed fix is given (i.e. hostMatchesNoProxyListV2). This is done for ease of reproducibility.

Dockerfile:

FROM node:24-slim
WORKDIR /reproduce
RUN npm init -y
COPY reproduce-bug.js .
RUN node reproduce-bug.js

Docker compose:

services:
  bug-reproduce:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: bug_reproduce
    command: node reproduce-bug.js

reproduce-bug.js:

// Mocking the environment
process.env.https_proxy = 'http://proxy.local:3128';
process.env.no_proxy = 'local.com,apple.com';

// Existing grpc-js function
function getNoProxyHostList() {
  /* Prefer using 'no_grpc_proxy'. Fallback on 'no_proxy' if it is not set. */
  let noProxyStr = process.env.no_grpc_proxy;
  let envVar = 'no_grpc_proxy';
  if (!noProxyStr) {
    noProxyStr = process.env.no_proxy;
    envVar = 'no_proxy';
  }
  if (noProxyStr) {
    // trace('No proxy server list set by environment variable ' + envVar);
    return noProxyStr.split(',');
  } else {
    return [];
  }
}

// Exsting grpc-js function with bug, modified for ease of reproducibility
function hostMatchesNoProxyList(serverHost) {
  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)) {
    //   return true;
    // } else if (serverHost.endsWith(host)) {
    //   // host is a single IP or a domain name suffix
    //   return true;
    // }
    if (serverHost.endsWith(host)) {
      console.log(`[checking against (${host})]: ${serverHost}  MATCHES the no proxy host`)
      return true
    }
  }
  console.log(`${serverHost}  DOES NOT MATCH any of the no proxy hosts`)
  return false;
}

// Modified function with proposed fix
function hostMatchesNoProxyListV2(serverHost) {
  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)) {
    //   return true;
    // } else if (serverHost.endsWith(host)) {
    //   // host is a single IP or a domain name suffix
    //   return true;
    // }

    // Proposed fix
    if (serverHost === host) return true;
    if (serverHost.endsWith('.' + host)) return true;
    if (host.startsWith('.') && serverHost.endsWith(host)) return true;

  }

  console.log(`${serverHost}  DOES NOT MATCH any of the no proxy hosts`)

  return false;
}

const testHosts = [
  'local.com',     // Correctly matches
  'www.local.com', // Correctly matches
  'notlocal.com', // BUG: Should NOT match
  'www.notlocal.com', // BUG: Should NOT match
  'www.apple.com', // Correctly matches
  'www.snapple.com'  // BUG: Should NOT match
];

console.log(`NO_PROXY is set to: ${process.env.no_proxy}\n`);

testHosts.forEach(host => {
  hostMatchesNoProxyList(host);
});

// test proposed fix 
// testHosts.forEach(host => {
//   hostMatchesNoProxyListV2(host);
// });

Run docker compose up --build

Output :

[checking against (local.com)]: local.com  MATCHES the no proxy host
[checking against (local.com)]: www.local.com  MATCHES the no proxy host
[checking against (local.com)]: notlocal.com  MATCHES the no proxy host <-- BUG
[checking against (local.com)]: www.notlocal.com  MATCHES the no proxy host  <-- BUG
[checking against (apple.com)]: www.apple.com  MATCHES the no proxy host 
[checking against (apple.com)]: www.snapple.com  MATCHES the no proxy host <--- BUG
Environment

N/A - containerized example given

Additional context

The man pages for curl lay out the logic that is most commonly expected:

Comma-separated list of hosts for which not to use a proxy, if one is specified. The only wildcard is a single "*" character, which matches all hosts, and effectively disables the proxy. Each name in this list is matched as either a domain which contains the hostname, or the hostname itself. For example, "local.com" would match "local.com", "local.com:80", and "www.local.com", but not "www.notlocal.com".

This option overrides the environment variables that disable the proxy ("no_proxy" and "NO_PROXY"). If there is an environment variable disabling a proxy, you can set the no proxy list to "" to override it.

IP addresses specified to this option can be provided using CIDR notation (added in 7.86.0): an appended slash and number specifies the number of network bits out of the address to use in the comparison. For example "192.168.0.0/16" would match all addresses starting with "192.168". 
Lingua principale
TypeScript
Stelle
4.8k
Fork
716
Merge medio
1g 18h
PR unite (30g)
17

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di grpc/grpc-node

Tutte le issue di grpc/grpc-node

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.