Skip to content

fix(env-http-proxy-agent): NO_PROXY wildcard semantics - #5777

Open
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix-noproxy-wildcard-semantics
Open

fix(env-http-proxy-agent): NO_PROXY wildcard semantics#5777
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:fix-noproxy-wildcard-semantics

Conversation

@mcollina

@mcollina mcollina commented Sep 5, 2026

Copy link
Copy Markdown
Member

Fix NO_PROXY wildcard matching in EnvHttpProxyAgent so fetch() is internally consistent with node:http (see nodejs/node#57872, the NO_PROXY differences table).

Three non-sensible behaviors are fixed:

  • *.example.com previously bypassed the proxy for the apex example.com itself. A *.domain entry is a subdomain wildcard and must only match sub.example.com / a.b.example.com, not the apex. node:http already does this.
  • * (a wildcard with surrounding whitespace) was not recognized as a global wildcard because the check compared the whole NO_PROXY string against *.
  • none.invalid,* (a * among other entries) was likewise not recognized as a global wildcard.

A bare * entry now matches all hosts regardless of position or whitespace, and is port-aware (*:80 only bypasses that port).

Tests updated and added; all env-http-proxy-agent tests pass and lint is clean.

Refs: nodejs/node#57872

Make `*.domain` NO_PROXY entries match subdomains only, not the apex
host (align with node:http and the usual wildcard convention), and
recognize a bare '*' entry as a global wildcard regardless of its
position or surrounding whitespace (e.g. ' * ' or 'none.invalid,*').
Previously these bypassed the proxy incorrectly or not at all.

Refs: nodejs/node#57872
@codecov-commenter

codecov-commenter commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.47619% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.51%. Comparing base (17117f6) to head (5aff5bc).
⚠️ Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
lib/dispatcher/env-http-proxy-agent.js 90.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5777      +/-   ##
==========================================
+ Coverage   93.50%   93.51%   +0.01%     
==========================================
  Files         110      110              
  Lines       39072    39374     +302     
==========================================
+ Hits        36534    36821     +287     
- Misses       2538     2553      +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +103 to +108
if (entry.hostname === '*') {
if (entry.port && entry.port !== port) {
continue
}
return false // Never proxy if a wildcard entry is present.
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this also introduces *:PORT behavior, while node:http currently only treats an exact * entry as a global wildcard.

Is that difference intentional given the goal of keeping the two implementations consistent?

If *:PORT is intended here, it might also be worth adding coverage for the non-matching-port case.

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

Successfully merging this pull request may close these issues.

3 participants