Skip to content
X-Real-IP is IPv4 for IPv6 connections, and X-Forwarded-For's second entry keeps changing
heytadeka
OP

20 days ago

On a *.up.railway.app service with nothing in front of the Railway edge:

  • A client connecting over IPv6 (confirmed with curl -6) gets an IPv4 X-Real-IP, identical to the one it gets over IPv4 from the same machine.
  • X-Forwarded-For always has 2 entries. Entry 0 equals X-Real-IP. Entry 1 is a different IPv4 address that changes between requests, even one second apart from the same client.
  • Forging both headers changes nothing, so I take it the edge overwrites them. I have read https://station.railway.com/questions/which-client-address-headers-does-the-ra-fb9e36d7, which doesn't cover this.

Request IDs, 2026-10-30 UTC, edge sjc1:

05:30:06Z curl -4 aDGf17PaRMOXH9JTGbGh5g

05:30:07Z curl -6 YaxPEFjOQwatKshfjVra_w

05:30:08Z curl -4 gi0x73_fQwelDMVLHn5Ytg

05:30:09Z curl -6 qnjtuiUpSYK6Zw-2ezItjw

Questions:

  1. Why is X-Real-IP IPv4 for an IPv6 connection, and what does srcIp show in your logs for these IDs?
  2. What are the two X-Forwarded-For entries, and why does entry 1 change?
  3. Is there a supported way to get the original client address, including IPv6?

I can share my client's addresses privately if needed.

Solved

1 Reply

Railway
BOT

20 days ago

For requests through our public edge, including *.up.railway.app, the edge replaces any caller-supplied X-Real-IP, X-Forwarded-For, X-Forwarded-Proto and X-Forwarded-Host, so forged copies having no effect is expected. X-Real-IP is the header we set as the client's remote address, and it is the one to read.

On IPv6: we can't confirm from here that the edge carries a native IPv6 client address through to X-Real-IP. What you're seeing, an IPv4 value for a curl -6 request that matches your IPv4 result, is the behavior today, and we have no header or setting we can point you to that delivers the original IPv6 address. We also couldn't match those request IDs to your service's edge logs from this thread, so we can't report the srcIp for them.

On X-Forwarded-For: it is rebuilt by our edge, not a proxy chain your client contributed to, and it isn't a stable contract for entry count or hop order. Entry 0 does not always track X-Real-IP, and we can't tell you what entry 1 represents, and nothing about it should be treated as a fixed address or range, which fits it changing between requests. For identifying clients, rely on X-Real-IP alone and avoid trust proxy-style settings that pick an address out of X-Forwarded-For by position.


Status changed to Awaiting User Response Railway • 20 days ago


Railway
BOT

13 days 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 • 13 days ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...