fix(isURL): evaluate host whitelist against the actual host of bracketed URLs - #2866
Open
koding88 wants to merge 1 commit into
Open
fix(isURL): evaluate host whitelist against the actual host of bracketed URLs#2866koding88 wants to merge 1 commit into
koding88 wants to merge 1 commit into
Conversation
…ted URLs
The early host_whitelist branch checked 'host', which is the empty
string whenever the URL target is a bracket-wrapped host like
'[::1]' — the real address lives in the 'ipv6' variable at that
point. Two consequences:
- whitelisted bracketed hosts ('http://[::1]' with
host_whitelist: ['::1']) were always rejected;
- a whitelist entry matching the empty string (e.g. /^$/ or /.*/)
accepted arbitrary bracketed garbage hosts without any IP check,
because the whitelist result was returned before host validation.
Resolve the effective host with 'host || ipv6' before the check.
Plain-domain behavior, including the legacy early-return semantics
that let users allowlist non-FQDN hosts such as 'localhost', is
unchanged.
Regression tests fail before this change and pass after it; the
full suite passes with line coverage unchanged at 100%.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2866 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 114 114
Lines 2599 2599
Branches 658 659 +1
=========================================
Hits 2599 2599 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes isURL’s host_whitelist handling for bracketed IPv6 URLs (e.g. http://[::1]) by ensuring the whitelist is checked against the actual host value (ipv6) rather than the empty host string produced by the bracketed-host parsing path.
Changes:
- Update
src/lib/isURL.jsto evaluatehost_whitelistagainsthost || ipv6so bracketed IPv6 hosts are correctly allowlisted and empty-string whitelist matches no longer “accidentally” allow bracketed garbage. - Add regression tests covering allowlisted bracketed IPv6 hosts (string + regex entries, with/without port).
- Add regression test ensuring an empty-matching whitelist regex does not accept non-IP bracketed hosts.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/lib/isURL.js |
Uses `host |
test/validators.test.js |
Adds focused regression tests for bracketed IPv6 whitelist behavior and the empty-string whitelist edge case. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The early
host_whitelistbranch checkedhost, which is the empty string whenever the URL target is a bracket-wrapped host likehttp://[::1]— the real address lives in theipv6variable at that point. Two observable defects:http://[::1]host_whitelist: ['::1']http://[::1]:8080host_whitelist: ['::1']http://[2001:db8::1]/host_whitelist: [/^2001:/]http://[not-an-ip]host_whitelist: [/^$/]So whitelisted bracketed IPv6 hosts were always rejected, and a whitelist entry matching the empty string accepted arbitrary bracketed hosts without any IP validation.
Fix
Resolve the effective host before the check:
Plain-domain behavior — including the legacy early-return semantics that let users allowlist non-FQDN hosts such as
localhost— is unchanged.Tests
Two regression tests in
test/validators.test.js:Both fail on
masterand pass with this change. Full suite: 325 passing, ESLint clean, line coverage unchanged at 100%.Checklist