-
-
Notifications
You must be signed in to change notification settings - Fork 798
Description
Environment
Nitro (nitropack 2.13.1), dev mode, Unix socket deployment behind reverse proxy
Reproduction
- Start dev server on Unix socket:
NITRO_UNIX_SOCKET=/tmp/nitro.sock nuxi dev- Configure reverse proxy (e.g. nginx):
location / {
proxy_pass http://unix:/tmp/nitro.sock;
}
- Send request with spoofed header from the network:
curl -H "X-Forwarded-For: 127.0.0.1" http://dev-server.example.com/_vfs- VFS handler returns application source code instead of 403.
Describe the bug
createVFSHandler() restricts /_vfs access to local IPs. When the server runs on a Unix socket, it passes { xForwardedFor: isUnixSocket } to getRequestIP(), which enables trust of the X-Forwarded-For header. A client behind a reverse proxy can send X-Forwarded-For: 127.0.0.1 to satisfy the localhost check.
When the transport is a Unix socket, the peer IP isn't available from the socket layer, so trusting X-Forwarded-For as a fallback makes sense in principle — but most reverse proxy configurations forward the header from the original client, making it attacker-controlled.
Suggested fix: change getRequestIP(event, { xForwardedFor: isUnixSocket }) to getRequestIP(event, { xForwardedFor: false }), or deny /_vfs access entirely when socket-level IP info is unavailable.
Additional context
Dev mode only — VFS handler is not mounted in production builds. Requires Unix socket deployment behind a reverse proxy that passes through X-Forwarded-For.