Repository navigation
fix(abstractions): normalize allowed hosts whitespace and enforce url validation when empty - #2194
Hardik K (hardikkaurani) wants to merge 10 commits into
Conversation
|
Hi Vincent Biret (@baywet), opened this PR normalizing allowed hosts whitespace and strengthening URL validation. All tests and CI checks are passing. Whenever you have a chance, could you please review? Thanks! |
|
I've addressed the review comments and updated the PR:
Whenever convenient, please take another look. Thank you! |
… validation when empty Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…d guard browser empty fallback Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
888cea4 to
e56aa96
Compare
|
I've updated the PR to resolve the review feedback regarding browser test execution:
Ready for review! |
…me-less hosts Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
|
I've pushed an update addressing the review findings on URL validation in
|
There was a problem hiding this comment.
🟡 Changes recommended
The validator accepts malformed HTTPS URLs that browsers resolve to a disallowed page origin, allowing authentication credentials to be sent to a non-allowlisted destination.
1 open issue
2 resolved since last review
Review effort: Balanced
| parsed = new URL(trimmedUrl, browserBase); | ||
| } else { | ||
| const hasScheme = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//i.test(trimmedUrl); | ||
| const candidate = hasScheme ? trimmedUrl : trimmedUrl.startsWith("//") ? `${defaultProtocol}${trimmedUrl}` : `${defaultProtocol}//${trimmedUrl}`; |
There was a problem hiding this comment.
[P1] Scheme-less URLs can authenticate a different browser host
On https://other.example/app/, an allowlist containing httpbin.org now accepts httpbin.org/path, because validation prepends https://. Browser fetch instead treats the unchanged string as relative, sending it to other.example. Both isUrlHostValid and validateProtocol pass, so an API key or bearer token can reach a host outside the allowlist. This input was rejected before this change.
Please resolve all browser-relative references against browserBase, including bare paths, or ensure the validated absolute URL is also the URL sent. A regression test should cover an allowlisted httpbin.org with a different browser origin.
There was a problem hiding this comment.
Addressed in commit 35441f7.
- WHATWG Browser Base Resolution: In browser environments, all relative references, including bare paths such as
httpbin.org/path, are now resolved againstbrowserBaseusingnew URL(trimmedUrl, browserBase), matching browser fetch destination semantics. - Node.js Compatibility: When
browserBaseis undefined, supported scheme-less host behavior (https://) is preserved, while unresolvable relative paths without a base are rejected. - Regression Coverage: Added tests verifying browser-base resolution and allowlist enforcement, alongside coverage for absolute URLs, protocol-relative URLs, path-relative references, and credential attachment consistency through
ApiKeyAuthenticationProvider.
All 38 validator tests and 142 abstractions tests pass cleanly.
There was a problem hiding this comment.
🟡 Changes recommended
The validator rejects valid percent-containing paths and queries, causing credentials to be omitted, while browser-incompatible assertions and global overrides break Chrome tests.
3 open issues
2 resolved since last review
Review effort: Balanced
|
I've pushed an update addressing the latest review feedback and browser CI test failures:
Whenever convenient, please take another look and trigger the workflow run. Thanks! |
…ts and credential behavior
| await otherProvider.authenticateRequest(reqRelative); | ||
| expect(reqRelative.headers.tryGetValue("X-OTHER-KEY")).to.deep.equal(["other-api-key"]); |
There was a problem hiding this comment.
Good catch. Updated the test expectation to be protocol-aware based on window.location.protocol.
When running in an HTTP-served browser test environment, it now asserts that authenticateRequest rejects with the expected protocol error (Authentication scheme can only be used with https requests) and confirms credentials are not attached. When running under HTTPS, it validates successful authentication and header population. The relative-URL destination hostname checks (other.example) remain asserted across both cases.
…-aware in browser tests
|
I have updated the test in
Whenever convenient, could you please approve the workflow run and review? Thanks! |


Description
This PR strengthens host validation and normalization in
AllowedHostsValidator:Whitespace trimming & host normalization:
validateHosts,host?.trim().toLowerCase()ensures hosts with leading or trailing whitespace (e.g." http://invalid.com ") are correctly checked against thehttp:///https://prefix restriction and rejected with an Error.normalizeHosts, hosts are trimmed viahost.trim().toLowerCase()and empty entries are filtered out, ensuring entries like" example.com "match target URLs consistently.URL validation & security hardening:
allowedHostsis empty (this.allowedHosts.size === 0), URL parsing and userinfo rejection (parsed.username || parsed.password) are now enforced before returningtrue, preventing host spoofing and malformed URLs from bypassing checks.Test coverage:
setAllowedHosts.allowedHostsis empty.cc Vincent Biret (@baywet)