Skip to content
Security clarification — X-Forwarded-For trust semantics on Railway public edge
ivannp2712-del
OP

a month ago

Hello Railway Support,

We are running a production Next.js application behind Railway’s public edge and use client IP information for application-level rate limiting.

Our current configuration explicitly trusts proxy headers and reads the first element of the X-Forwarded-For header after the request has passed through Railway’s public edge.

Before treating this behavior as a security boundary, we would like to confirm Railway’s supported and stable behavior.

Could you please clarify the following:

  1. Does Railway’s public edge remove, sanitize, overwrite, or otherwise control a client-supplied X-Forwarded-For header before forwarding the request to the deployment?
  2. Can an external client cause an arbitrary value supplied in its request to become the first element of the X-Forwarded-For chain received by the application?
  3. Is the first element of X-Forwarded-For guaranteed to represent the real connecting client IP from the application’s point of view?
  4. Is this behavior a supported and stable Railway platform contract across edge/CDN infrastructure changes, or is it only the current implementation detail?
  5. Does the same behavior apply both when the service is accessed through:
    • a Railway-generated *.up.railway.app domain, and
    • a custom domain attached to the same Railway service?
  6. If trusting the first X-Forwarded-For element is not the recommended approach, which Railway-provided header should we use for a spoof-resistant client IP suitable for application-level rate limiting?

For context, our application currently:

  • enables proxy trust explicitly;
  • uses X-Forwarded-For;
  • reads only the first element;
  • validates that the value is a valid IPv4 or IPv6 address;
  • rejects malformed values and falls back to a route-specific identity;
  • uses the derived identity only for rate limiting.

We are not asking for any private infrastructure details or credentials. We only need to confirm the correct and supported trust model for deriving the client IP behind Railway’s public edge.

Thank you.

Best regards,

Ivan

GoTermin

Project: GoTermin

Service: gotermin-web

Environment: production

Region: EU West

Framework: Next.js

Current public domain: Railway-generated *.up.railway.app

Solved

1 Reply

Railway
BOT

a month ago

Our HTTP edge overwrites X-Forwarded-For and X-Real-IP on every request. A client-supplied value is replaced, not kept or appended to, so an external client sending a forged header through the edge cannot make its own value the first element. This applies the same way to *.up.railway.app domains and custom domains, because both go through the same HTTP edge.

For rate limiting, we recommend X-Real-IP over parsing X-Forwarded-For. The edge sets it to the client's remote IP, and our public networking specifications document that meaning. We do not guarantee that X-Forwarded-For will hold exactly one entry or a fixed number of hops. If you later put Cloudflare in front of the service, X-Real-IP is set from CF-Connecting-IP, but only when the request actually comes from Cloudflare's published IPv4 ranges.

On stability: the header overwrite is the behavior we support, but the specifications note that networking details can change. The proxy addresses your container sees as the socket peer are not a stable range, so don't hard-code them as trusted-proxy CIDRs.

This only covers traffic that comes through the public edge. Requests over private networking (*.railway.internal) from other services in the same environment don't go through it, and those callers can set any forwarding headers they like. The same is true for any TCP proxy path. Trusting proxy headers from every immediate peer therefore means trusting every route to your listener. An IP address also isn't a persistent identity, since a client can change it by switching networks or using a VPN.


Status changed to Awaiting User Response Railway • about 1 month ago


Railway
BOT

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


Welcome!

Sign in to your Railway account to join the conversation.

Loading...