an hour ago
Title: Express trust proxy = 1 — Can Railway ingress prevent X-Forwarded-For spoofing?
Hello Railway Community,
I'm running a Node.js Express application on Railway behind Railway's public networking ingress. My application also receives requests through a Vercel external rewrite.
My Express application currently uses:
app.set('trust proxy', 1)
This is needed for HTTPS detection and secure session cookies.
I need clarification about the following:
- Does Railway ingress overwrite or sanitize incoming
X-Forwarded-Forheaders? - Can someone directly calling a Railway public domain send a forged
X-Forwarded-Forheader that reaches Express unchanged? - Is
X-Real-IPguaranteed to contain the actual client IP, regardless of caller-supplied headers? - Does the behavior differ when requests arrive through a Vercel external rewrite?
- Which header or configuration does Railway recommend for secure client-IP-based rate limiting?
This matters because my application uses client IP addresses for authentication and OTP rate limiting.
I'd appreciate an answer from someone familiar with Railway's ingress implementation or an official documentation reference.
Thank you!
1 Reply
an hour ago
Our HTTP edge overwrites X-Real-IP, X-Forwarded-For, X-Forwarded-Proto and X-Forwarded-Host on every request that comes through a public domain, including .up.railway.app. Caller-supplied values are replaced, not appended to. That means someone calling your Railway domain directly cannot get a forged X-Forwarded-For or X-Real-IP through to Express unchanged.
X-Real-IP is set to the remote IP of whatever connected to our edge. For direct traffic that's the visitor. For traffic through your Vercel rewrite, it's the rewrite proxy's connection. Any visitor IP that Vercel passes along in its own headers is something our edge doesn't validate, so how far you trust it depends on your setup with Vercel. The one exception we handle specially is Cloudflare: when the connection comes from Cloudflare's published IPv4 ranges with CF-Connecting-IP set, we use that value as X-Real-IP.
For rate limiting on traffic through the public edge, we recommend reading X-Real-IP directly. Express's req.ip doesn't use X-Real-IP. It's calculated from the socket peer and X-Forwarded-For based on trust proxy, and a numeric hop count can pick out an intermediary in a multi-hop path. We also don't publish a stable CIDR for the proxy address your container sees as its socket peer, so don't hard-code one.
Requests sent over private networking (*.railway.internal) skip the edge and its header overwriting. Other services in the same environment can send whatever headers they want, and so can anything you expose through a TCP proxy. The full details are in the public networking specs.
Status changed to Awaiting User Response Railway • about 1 hour ago