qrest: resolve client IP from X-Forwarded-For behind trusted proxies - #392
Merged
Conversation
Behind a reverse proxy (Traefik, nginx, an ingress controller) the qrest-access log records the proxy's socket address, losing the real caller. A new optional trusted-proxy-cidrs property on the qrest QBean (comma-separated CIDRs) fixes that: when the socket peer is inside a trusted CIDR, the logged remote becomes the rightmost X-Forwarded-For entry not itself in the trusted set — the client as witnessed by the outermost trusted proxy. Forwarded headers from any other peer are never believed (a direct caller cannot forge its logged identity), an all-trusted chain yields its leftmost entry, a missing/garbage header falls back to the socket peer, and a malformed CIDR fails deployment loudly instead of silently trusting the wrong network. Unset property = previous behavior, byte for byte.
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.
The
qrest-accesslog records the socket peer, which behind a reverse proxy (Traefik, nginx, an ingress controller) is the proxy — the real caller's address is lost.This adds an optional
trusted-proxy-cidrsproperty to theqrestQBean (comma-separated CIDRs, e.g.10.42.0.0/16, 127.0.0.1/32). When set and the socket peer falls inside a trusted CIDR, the logged remote becomes the rightmostX-Forwarded-Forentry not itself in the trusted set — i.e. the client as witnessed by the outermost trusted proxy.Security properties, all covered by tests:
RestSessionTest.forwardedHeaderFromUntrustedPeerIsIgnored).Unset property = previous behavior, byte for byte.
:modules:qrest:testandjavadocgreen.