Resolve the real client IP behind a trusted reverse proxy - #192
Open
williamthome wants to merge 4 commits into
Open
Resolve the real client IP behind a trusted reverse proxy#192williamthome wants to merge 4 commits into
williamthome wants to merge 4 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Behind an HTTP-terminating reverse proxy the socket peer is the proxy, so
roadrunner_req:client_ip/1reports the proxy for every request and the per-peerrate_limitbucket collapses onto a single key. The newreal_iplistener option opts into nginx-realip-style resolution: the immediate peer must itself matchtrusted_proxiesbefore any forwarded header is honored, then the chain is walked right-to-left, skipping trusted proxies, to the first untrusted address. A client that bypasses the proxy has its own header ignored, so it cannot spoof its address. The resolved address feeds bothclient_ip/1and the rate-limit key, and composes withproxy_protocol(the PROXY-reported address becomes the immediate hop). CIDRs are pre-compiled at listener init to{Family, NetPrefix, Shift}, so the per-request check is a shift and a compare.RFC 9110 §5.3 makes repeated field lines equivalent to the single comma-joined value, so a proxy that emits the chain as separate header lines resolves identically to one that combines it.