a month ago
Hello Railway Support Team,
We are hosting a Node.js application using Express 5.2.1 and express-rate-limit 8.7.0 on Railway.
Our application is currently reporting the following warning:
ERR_ERL_UNEXPECTED_X_FORWARDED_FOR
We are considering the following Express configuration:
app.set("trust proxy", 1);
Before deploying this change to production, we would appreciate clarification on the following questions:
Does Railway overwrite or append the X-Forwarded-For header when a client provides its own value?
Is the X-Real-IP header always set by Railway and protected against client-side spoofing?
Is app.set("trust proxy", 1) the recommended configuration for an Express application hosted directly on a Railway *.up.railway.app domain?
What is the recommended secure approach for identifying the real client IP address when using express-rate-limit on Railway?
Our goal is to ensure that rate limiting works correctly without allowing users to bypass authentication protections by spoofing HTTP headers.
We would appreciate your guidance before making any changes to our production environment.
Thank you for your assistance.
Best regards,
La Centrale Côte d’Ivoire Development Team
1 Reply
a month ago
Our HTTP edge overwrites X-Forwarded-For, X-Real-IP, X-Forwarded-Proto and X-Forwarded-Host on every request, including your *.up.railway.app domain. Any copy the client sends is replaced, not appended to. X-Real-IP is set to the client's remote IP, so a caller can't choose its value by sending a forged copy through the edge.
For rate limiting, we recommend keying on X-Real-IP rather than relying on trust proxy. In Express, req.ip is worked out from the socket peer and X-Forwarded-For based on the trust proxy setting, and it never reads X-Real-IP. A fixed hop count like trust proxy = 1 isn't guaranteed to land on the visitor, because the forwarding chain doesn't have a fixed number of entries. The proxy addresses your container sees as its socket peer also aren't a published or stable range, so don't hard-code them as trusted proxies.
One caveat: requests over private networking (*.railway.internal) don't go through the public edge, so another service in the same environment can send its own forwarding headers. If anything inside that environment can reach the listener, X-Real-IP is only trustworthy for traffic that came through the public domain. An IP address also isn't a persistent identity, since users can change networks or use a VPN.
More detail is in our public networking specs.
Status changed to Awaiting User Response Railway • about 1 month ago
a month ago
This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!
Status changed to Solved Railway • about 1 month ago