-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Ability to get remote IP from a request #642
Comments
Remote IP can be obtained from request transport, see this part of documentation:
|
Awesome, thanks! |
Worth to note (just for case) that if you have proxy in front, you'd better check headers first for forwarded peer IP. |
Maybe it would make sense to have a method that would check headers fallback to peer IP? |
It depends on your proxy configuration. You can have standard |
@kxepal Indeed, when it's your code. But imagine amount of unnecessary copy-parsing because of that? Unless aiohttp targets to be low-level HTTP library, I would expect it to implement standard and RFCed methods. |
Forwarding headers should be used only if all connections to the aiohttp server made through trusted forwarding proxy, otherwise users will be able to impersonate someone else IP by just setting aiohttp doesn't know anything about forward proxy configuration and I don't think automatic fallback can be easily handled (e.g. for non-trivial cases, like when all connections from specific IP (of SSL forward proxy) are forwarded connections, and all other connections are direct connections from end users). |
@rutsky But shouldn't it be easy to implement verification? E.g.:
|
Client IP lookup really depends on your service implementation/configuration. |
aiohttp already has complex logic for determining http scheme: https://github.com/KeepSafe/aiohttp/blob/master/aiohttp/web_reqrep.py#L131-L144 |
@popravich Could you further explain? I believe |
I'm just saying that if you're putting information about proxies into your application (read |
Regarding |
Yes, @popravich is right. |
Volunteers are welcome. |
@asvetlov I'm going to work on it. What should be the right behavior for this function in case when it cannot figure out client IP? Returning None or raising an exception? |
Let's take a look on use cases: in what cases server cannot figure out client IP at all? I can imagine only single situation: aiohttp is behind a reverse proxy, connected by UNIX socket and no I have no strong preference but inclining to raising an error: it is very rare case and users most likely will never expect it in their code. Returning |
Another issue would be an incorrect value of a header. In other hand, it's probably job of the proxy to take care of those. |
@Kentzo There could be no proxy to blame. Assume you have aiohttp served directly to the world and some client sent |
Superseded by #1134 |
Sometimes it is desired to know an IP, e.g. for google re-captcha.
The text was updated successfully, but these errors were encountered: