The script above is a sample worker script to test this problem.
When I visited the “deployed” version of script on workers.dev, it always returns the following json output.
And it is clear that “X-Real-IP” is being renamed to “cf-connecting-ip”, which can be verified by changing the value of “X-Real-IP”.
Is there a way to disable this behavior? Or at least don’t delete “X-Real-IP” and just add “cf-connecting-ip”.
CF has some protections to prevent Workers from sending requests to IPs with the wrong SNI, so I assume it also has some protections against faking the client’s IP. @KentonVarda
This is basically a bug. Historically Cloudflare’s stack has used X-Real-IP internally to identify the client IP, and then renames it to CF-Connecting-IP as one of the last steps before sending the request to origin. The behavior you observe with workers is an artifact of that, since Workers run much earlier in the pipeline. We have it on our list to fix this someday but it’s kind of tricky to do without breaking existing users, etc.
Long story short, there is currently no way to send a header to your origin called X-Real-IP. Sorry.