Skip to content
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

Need clarification on trusted hops #232

Closed
nabheet opened this issue May 17, 2024 · 1 comment
Closed

Need clarification on trusted hops #232

nabheet opened this issue May 17, 2024 · 1 comment

Comments

@nabheet
Copy link

nabheet commented May 17, 2024

I am not sure I understand trusted hops here: https://github.com/pgjones/hypercorn/blob/main/src/hypercorn/middleware/proxy_fix.py#L77

If I just have one nginx reverse proxy in front of my web server cluster, is this value 1 or 2. I am using Cloud Run which is putting two IPs in the x-forwarded-for http header. Since it is picking the last value, that is not the client. So I guess in my case, I need to use trusted_hops = 2.

Also, how do I get it to log the client IP? as the remote ip using the %(h)s format string still gives me the reverse proxy IP and not the real client IP.

@pgjones
Copy link
Owner

pgjones commented May 26, 2024

Hopefully d264794 makes this clearer. In your case it should like two proxies set the header before Hypercorn, so the value should be trusted_hops = 2.

Also, how do I get it to log the client IP? as the remote ip using the %(h)s format string still gives me the reverse proxy IP and not the real client IP.

Hypercorn logs before the middleware makes the proxy fix changes (middleware is for the ASGI app). %({x-forwarded-for})i gives the full header.

@pgjones pgjones closed this as completed May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants