Repository navigation
Labels
bugSomething isn't working (PRs; issues use the Bug type)
Description
Environment
| Operating system | Linux 6.6.87.2-microsoft-standard-WSL2 |
| CPU | Intel(R) Core(TM) Ultra 7 165H (22 cores) |
| Node.js version | v24.13.0 |
| nuxt/cli version | 3.34.0 |
| Package manager | [email protected] |
| Nuxt version | 4.4.2 |
| Nitro version | 2.13.3 |
| Builder | [email protected] |
| Config | compatibilityDate, devtools |
| Modules | - |
Reproduction
Minimal example:
export default defineEventHandler((event) => {
const { socket } = event.node.req
const isUnixSocket = (
// No network addresses
!socket?.remoteAddress && !socket?.localAddress // Empty address object
&& Object.keys(socket?.address?.() || {}).length === 0 // Socket is readable/writable but has no port info
&& socket?.readable && socket?.writable && !socket?.remotePort
)
return {
isUnixSocket,
ip: getRequestIP(event, { xForwardedFor: isUnixSocket }) ?? 'unknown',
headers: getRequestHeaders(event),
}
})Run locally in WSL and hit the endpoint:
curl http://localhost:3000/api/ipObserved response:
{
"isUnixSocket": true,
"ip": "::ffff:127.0.0.1",
"headers": {
"host": "localhost:5000",
"connection": "keep-alive",
"pragma": "no-cache",
"cache-control": "no-cache",
"sec-ch-ua": "\"Microsoft Edge\";v=\"147\", \"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"147\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 Edg/147.0.0.0",
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"sec-fetch-site": "none",
"sec-fetch-mode": "navigate",
"sec-fetch-user": "?1",
"sec-fetch-dest": "document",
"accept-encoding": "gzip, deflate, br, zstd",
"accept-language": "en-US,en;q=0.9",
"x-forwarded-for": "::ffff:127.0.0.1",
"x-forwarded-port": "5000",
"x-forwarded-proto": "http"
}
}Describe the bug
getRequestIP returns an IPv4-mapped IPv6 address (::ffff:127.0.0.1) instead of a normalized IPv4 address (127.0.0.1) when running in environments where IPv6 is preferred (e.g., WSL).
This causes issues for common IP validation logic such as:
Line 19 in 30003d9
| const isLocalRequest = ip && /^::1$|^127\.\d+\.\d+\.\d+$/.test(ip); |
In this case, a request from localhost is incorrectly treated as non-local because ::ffff:127.0.0.1 does not match expected patterns. As a result, locally accessing protected endpoints (e.g., VFS) results in unexpected 403 Forbidden responses.
Additional context
No response
Activity