-
-
Notifications
You must be signed in to change notification settings - Fork 36.6k
http: match subdomains for plain NO_PROXY entries #65617
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ import { runProxiedRequest } from '../common/proxy-server.js'; | |
| const server = http.createServer(common.mustCall((req, res) => { | ||
| res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
| res.end('Hello World\n'); | ||
| }, 5)); | ||
| }, 7)); | ||
| server.on('error', common.mustNotCall((err) => { console.error('Server error', err); })); | ||
| server.listen(0, '127.0.0.1'); | ||
| await once(server, 'listening'); | ||
|
|
@@ -78,6 +78,43 @@ await once(proxy, 'listening'); | |
| assert.strictEqual(signal, null); | ||
| } | ||
|
|
||
| { | ||
| // Test NO_PROXY with a plain domain also matching subdomains. | ||
| const { code, signal, stderr, stdout } = await runProxiedRequest({ | ||
| NODE_USE_ENV_PROXY: 1, | ||
| REQUEST_URL: `http://test.example.com:${server.address().port}/test`, | ||
| HTTP_PROXY: `http://localhost:${proxy.address().port}`, | ||
| RESOLVE_TO_LOCALHOST: 'test.example.com', | ||
| NO_PROXY: 'example.com', | ||
| }); | ||
|
|
||
| // The request should succeed and bypass proxy. | ||
| assert.match(stdout, /Status Code: 200/); | ||
| assert.match(stdout, /Hello World/); | ||
| assert.match(stdout, /Resolving lookup for test\.example\.com/); | ||
| assert.strictEqual(stderr.trim(), ''); | ||
| assert.strictEqual(code, 0); | ||
| assert.strictEqual(signal, null); | ||
| } | ||
|
|
||
| { | ||
| // Test NO_PROXY with a plain domain should NOT match partial domain names. | ||
| const { code, signal, stderr, stdout } = await runProxiedRequest({ | ||
| NODE_USE_ENV_PROXY: 1, | ||
| REQUEST_URL: `http://badexample.com:${server.address().port}/test`, | ||
| HTTP_PROXY: `http://localhost:${server.address().port}`, | ||
| RESOLVE_TO_LOCALHOST: 'badexample.com', | ||
| NO_PROXY: 'example.com', | ||
| }); | ||
|
|
||
| // The request should go through the proxy (not bypass it), | ||
| // because badexample.com is not a subdomain of example.com. | ||
| assert.match(stdout, /Status Code: 200/); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test seems to pass whether the proxy is used or bypassed, since both paths reach the same server. Could we also assert that the custom lookup for
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch, will fix |
||
| assert.strictEqual(stderr.trim(), ''); | ||
| assert.strictEqual(code, 0); | ||
| assert.strictEqual(signal, null); | ||
| } | ||
|
|
||
| // Test NO_PROXY with leading-dot entry should NOT match partial domain names. | ||
| // Regression test: .example.com must not match notexample.com or badexample.com. | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we limit suffix matching to domain entries?
As written,
NO_PROXY=127.0.0.1also bypassesfoo.127.0.0.1, although IP entries are documented as exact matches. Empty entries from trailing commas can also match hostnames ending in a dot.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will look into that