Skip to content

fix(fetch): handle URL credentials in dispatch path extraction#4892

Merged
mcollina merged 1 commit intomainfrom
fix/4889-fetch-path-with-credentials
Mar 15, 2026
Merged

fix(fetch): handle URL credentials in dispatch path extraction#4892
mcollina merged 1 commit intomainfrom
fix/4889-fetch-path-with-credentials

Conversation

@mcollina
Copy link
Copy Markdown
Member

Summary

  • fix fetch dispatch path extraction for URLs that include credentials
  • preserve the trailing ? behavior introduced in fix fetch stripping trailing ? from url #4837
  • add a websocket regression test for the 401 challenge/response flow with URL credentials

Details

Using url.href.slice(url.origin.length) breaks when userinfo is present (user:pass@...), because origin excludes credentials while href includes them. That produces an invalid path and prevents dispatch.

This change builds the path from url.pathname + url.search and explicitly preserves trailing ? when present.

Test plan

  • node --test test/websocket/issue-4889.js
  • npx borp -p "test/fetch/issue-4836.js"
  • npx eslint lib/web/fetch/index.js test/websocket/issue-4889.js

Closes #4889.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.89%. Comparing base (9b96516) to head (79bd034).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4892   +/-   ##
=======================================
  Coverage   92.89%   92.89%           
=======================================
  Files         112      112           
  Lines       35635    35638    +3     
=======================================
+ Hits        33102    33106    +4     
+ Misses       2533     2532    -1     

☔ View full report in Codecov by Sentry.
📢 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.

@domenic domenic mentioned this pull request Mar 14, 2026
7 tasks
@mcollina mcollina closed this Mar 14, 2026
@mcollina mcollina deleted the fix/4889-fetch-path-with-credentials branch March 14, 2026 07:40
@mcollina mcollina restored the fix/4889-fetch-path-with-credentials branch March 15, 2026 08:12
@mcollina mcollina reopened this Mar 15, 2026
@mcollina mcollina force-pushed the fix/4889-fetch-path-with-credentials branch from 230ae5a to 79bd034 Compare March 15, 2026 08:51
@mcollina
Copy link
Copy Markdown
Member Author

@KhafraDev @domenic can you urgently review this? I need to land asap, ship a minor to be included in the upcoming Node 24 security release

Copy link
Copy Markdown
Contributor

@domenic domenic left a comment

Choose a reason for hiding this comment

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

Code LGTM, left some nits on the tests

test('fetch path extraction does not match hostnames inside scheme', async (t) => {
const hosts = ['h', 't', 'p', 'ht', 'tp', 'tt']

for (const scheme of ['http', 'https']) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could add for (const userinfo of ['', 'user:pass@']) and then update the URL to ${scheme}://${userinfo}${host}/test?a=b#frag for extra coverage.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure I understand the motivation behind changing this file.

@mcollina mcollina merged commit ea3a06d into main Mar 15, 2026
36 of 37 checks passed
@mcollina mcollina deleted the fix/4889-fetch-path-with-credentials branch March 15, 2026 18:49
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.

url.href.slice(url.origin.length) path extraction breaks when URL contains credentials

4 participants