| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -158,7 +158,7 @@ class ProxyConfig { | |||
| 158 | 158 | // Follow curl's behavior: strip leading dot before matching suffixes. | |
| 159 | 159 | if (entry[0] === '.') { | |
| 160 | 160 | const suffix = entry.substring(1); | |
| 161 | - if (host.endsWith(suffix)) return false; | ||
| 161 | + if (host === suffix || (host.endsWith(suffix) && host[host.length - suffix.length - 1] === '.')) return false; | ||
| 162 | 162 | } | |
| 163 | 163 | ||
| 164 | 164 | // Handle wildcards like *.example.com | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ import { runProxiedRequest } from '../common/proxy-server.js'; | |||
| 10 | 10 | const server = http.createServer(common.mustCall((req, res) => { | |
| 11 | 11 | res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
| 12 | 12 | res.end('Hello World\n'); | |
| 13 | - }, 3)); | ||
| 13 | + }, 5)); | ||
| 14 | 14 | server.on('error', common.mustNotCall((err) => { console.error('Server error', err); })); | |
| 15 | 15 | server.listen(0, '127.0.0.1'); | |
| 16 | 16 | await once(server, 'listening'); | |
@@ -77,5 +77,42 @@ await once(proxy, 'listening'); | |||
| 77 | 77 | assert.strictEqual(code, 0); | |
| 78 | 78 | assert.strictEqual(signal, null); | |
| 79 | 79 | } | |
| 80 | + | ||
| 81 | + // Test NO_PROXY with leading-dot entry should NOT match partial domain names. | ||
| 82 | + // Regression test: .example.com must not match notexample.com or badexample.com. | ||
| 83 | + { | ||
| 84 | + const { code, signal, stderr, stdout } = await runProxiedRequest({ | ||
| 85 | + NODE_USE_ENV_PROXY: 1, | ||
| 86 | + REQUEST_URL: `http://notexample.com:${server.address().port}/test`, | ||
| 87 | + HTTP_PROXY: `http://localhost:${server.address().port}`, | ||
| 88 | + RESOLVE_TO_LOCALHOST: 'notexample.com', | ||
| 89 | + NO_PROXY: '.example.com', | ||
| 90 | + }); | ||
| 91 | + | ||
| 92 | + // The request should go through the proxy (not bypass it), | ||
| 93 | + // because notexample.com is not a subdomain of example.com. | ||
| 94 | + assert.match(stdout, /Status Code: 200/); | ||
| 95 | + assert.strictEqual(stderr.trim(), ''); | ||
| 96 | + assert.strictEqual(code, 0); | ||
| 97 | + assert.strictEqual(signal, null); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + { | ||
| 101 | + const { code, signal, stderr, stdout } = await runProxiedRequest({ | ||
| 102 | + NODE_USE_ENV_PROXY: 1, | ||
| 103 | + REQUEST_URL: `http://badexample.com:${server.address().port}/test`, | ||
| 104 | + HTTP_PROXY: `http://localhost:${server.address().port}`, | ||
| 105 | + RESOLVE_TO_LOCALHOST: 'badexample.com', | ||
| 106 | + NO_PROXY: '.example.com', | ||
| 107 | + }); | ||
| 108 | + | ||
| 109 | + // The request should go through the proxy (not bypass it), | ||
| 110 | + // because badexample.com is not a subdomain of example.com. | ||
| 111 | + assert.match(stdout, /Status Code: 200/); | ||
| 112 | + assert.strictEqual(stderr.trim(), ''); | ||
| 113 | + assert.strictEqual(code, 0); | ||
| 114 | + assert.strictEqual(signal, null); | ||
| 115 | + } | ||
| 116 | + | ||
| 80 | 117 | proxy.close(); | |
| 81 | 118 | server.close(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments