Skip to content

getRequestIP returns IPv4-mapped IPv6 (::ffff:127.0.0.1) on WSL causing localhost checks to fail and 403 in VFS handler #4205

Closed

Description

@mukundshah

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/ip

Observed 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:

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

Logs

Activity

  1. added
    pending triage
    on Apr 15, 2026
  2. added
    bug
    and removed
    pending triage
    on Apr 17, 2026
  3. added theissue type on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions