-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add method to get client's claimed IP #904
Comments
…equest As per ticket description of ticket tornadoweb#904, a method to return the first public IP address from X-Forwarded-For should be implemented. This update contains the below changes: 1. In tornado/httpserver.py HTTPRequest.get_claimed_ip() is implemented which simply returns remote_ip 2. In tornado/test/httpserver_test.py The test for verifying ip_headers already existed in XHeaders. I simply modified the internal class Handler to retrieve the output of get_claimed_ip from the request messge and write it to the dictionary. The same tests that were written for verifying ip_headers have been re-used except that they now check that remote ip equals claimed_ip
I agree that That said, there is another (maybe not so uncommon) example when using Cloudflare - these guys expose the client IP address via the This allows Nginx to work and populate logs with actual client IPs and for logging/analytics purposes it would be great if I could tell Tornado which header to use for the "real ip" to appear in logs and for other purposes. |
This issue description is a bit out of date. According to http://www.tornadoweb.org/en/stable/httpserver.html#http-server
That's very similar to what nginx can do (you just can't customize the header to look at, it's just |
*sigh* yeah looks like I had a severe case of brain-lag - FWIW setting Also: Cloudflare supports its own header as well as |
The issue description is still valid. The |
I'm initiating my server using this: |
You can pass it e.g. using
|
The
HTTPRequest.remote_ip
field is intended to contain a trustworthy equivalent of the TCP-level remote address, so it accepts only a singleX-Forwarded-For
hop, and only when configured to do so. For some purposes (e.g. geolocation), it is useful to take whatever IP address the client claims to be using even through a chain of untrusted proxies. There should be some method to return the first public IP address fromX-Forwarded-For
.The text was updated successfully, but these errors were encountered: