You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Redirect handler resolves a relative Location against a host read from a path starting with // #6184
RedirectHandler builds the base URL for a redirect with new URL(this.opts.path, requestOrigin). A path such as //users/start is a path on origin, and the first request is sent there, but new URL() reads it as a network-path reference to a host called users. A relative Location is then resolved against that host instead of the origin.
The same expression feeds the redirect-loop history, so a visited URL can be recorded with the wrong host.
Reproduction
Standalone reproduction script:
'use strict'const{ test }=require('node:test')constassert=require('node:assert')const{ createServer }=require('node:http')const{ once }=require('node:events')const{ Agent, interceptors }=require('undici')test('a relative Location after a path starting with // stays on the origin',async(t)=>{constseen=[]constserver=createServer((req,res)=>{seen.push(req.url)if(req.url==='//users/start'){res.writeHead(302,{location: '/login'})returnres.end()}res.end('ok')})t.after(()=>server.close())server.listen(0,'127.0.0.1')awaitonce(server,'listening')constagent=newAgent().compose(interceptors.redirect({maxRedirections: 3}))t.after(()=>agent.destroy())const{ statusCode, body }=awaitagent.request({origin: `http://127.0.0.1:${server.address().port}`,path: '//users/start',method: 'GET'})awaitbody.dump()assert.strictEqual(statusCode,200)assert.deepStrictEqual(seen,['//users/start','/login'])})
Steps to reproduce (if not using the script above):
Save the script as repro.js and run node --test repro.js.
Expected Behavior
Per RFC 3986, the relative Location resolves against the URL that was requested, so the second request reaches the same server at /login.
Actual Behavior
The second request tries to connect to a host named users and fails.
Logs & Screenshots
Error: getaddrinfo ENOTFOUND users
Environment
OS: Windows 11
Node.js version: v24.18.0
undici version: 8.12.3, and main at 8.12.4
Additional context
This also happens without unusual input: a base URL ending in a slash joined to a path starting with one produces //users.
I have a fix and a test ready, and can open a pull request.
_Note: Since SECURITY.md treats unsanitized input passed to request options as out of scope, I believe a regular issue is appropriate, but please let me know if you see it differently.
Activity