fix: reject credentialed URLs for IPv6, punycode, and text fragments - #30
Merged
Merged
Conversation
url-regex-safe can match a substring after `@` when exact matching is disabled, so userinfo-bearing URLs were accepted even though the common exact-match path rejects them. Reject username/password up front.
This was referenced Jul 28, 2026
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MTbj6CYXGsk6rhXx7J8SUP
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.
Bug
The full
url-httpAPI intentionally rejects credentialed HTTP(S) URLs (e.g.https://admin:admin@host), but that check could be bypassed for IPv6, punycode, and text-fragment URLs.Impact
Callers that rely on
url-httpto reject userinfo-bearing URLs could accept phishing / host-confusion inputs such as:https://trusted.example@example.com/#:~:text=xhttps://trusted.example@xn--80a0aaa.com/http://trusted.example@[::1]/These previously returned the full href (including credentials) instead of
false.Root cause
For those URL shapes, matching runs with
exact: false.url-regex-safe({ auth: false })can then match a substring after@whileurl-httpstill returns the originalhref.Fix
Reject URLs with a non-empty
usernameorpasswordimmediately after WHATWG parsing, before the regex check.Validation
npm testpasses (100% coverage)Note
Low Risk
Small, security-hardening change in URL validation with targeted tests; no broader API or dependency changes.
Overview
Closes a bypass where credentialed
http(s)URLs could still validate when IPv6, punycode, or text-fragment handling ranurl-regex-safein non-exact mode and matched past the@.After parsing with
URL, the validator now returnsfalseifusernameorpasswordis set, before any regex logic—so inputs likehttps://trusted.example@example.com/#:~:text=xno longer return the fullhref.Regression tests were added for text-fragment, punycode, and IPv6 credentialed cases in the full (non-lightweight) test suite.
Reviewed by Cursor Bugbot for commit ac22920. Bugbot is set up for automated code reviews on this repo. Configure here.