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
dns interceptor runs a DNS lookup for IPv6 literal origins and fails with ENOTFOUND #6060
The dns interceptor is meant to pass requests whose origin is already an IP address straight through. That works for IPv4 literals, but for an IPv6 literal such as http://[::1]:3000 the interceptor performs a lookup for the string [::1], which fails with getaddrinfo ENOTFOUND [::1]. The same request without the interceptor succeeds.
What should happen
A request to an IPv6 literal origin should be dispatched as is, without a lookup, in the same way an IPv4 literal is.
Reproduction
const{ Agent, interceptors, request }=require('undici')consthttp=require('node:http')constserver=http.createServer((req,res)=>res.end('ok')).listen(0,'::1',async()=>{const{ port }=server.address()constagent=newAgent().compose(interceptors.dns())try{constres=awaitrequest(`http://[::1]:${port}/`,{dispatcher: agent})console.log(res.statusCode,awaitres.body.text())}catch(err){console.log(err.code,err.message)}server.close()agent.close()})
With a custom lookup option the callback is invoked with origin.hostname === '[::1]', so any user lookup has to special case brackets too.
Root cause
In lib/interceptor/dns.js the bypass check is isIP(origin.hostname) !== 0. URL#hostname keeps the brackets around IPv6 addresses (new URL('http://[::1]').hostname === '[::1]'), and net.isIP('[::1]') returns 0, so the request falls through to runLookup().
Activity