is_valid_ip: accept RFC 3986 bracketed IPv6 in X-Forwarded-For#3667
Open
HrachShah wants to merge 1 commit into
Open
is_valid_ip: accept RFC 3986 bracketed IPv6 in X-Forwarded-For#3667HrachShah wants to merge 1 commit into
HrachShah wants to merge 1 commit into
Conversation
Some load balancers (e.g. Fortigate) emit IPv6 addresses in X-Forwarded-For in the URI-reference bracketed form, e.g. '[2620:0:d60:ac1a::10]'. The existing is_valid_ip check calls getaddrinfo, which rejects the bracketed form with EAI_NONAME, so these forwarded addresses were silently dropped and the request fell back to the connection peer. Strip the brackets inside is_valid_ip so the bracketed form is accepted and validated as a normal IPv6 address, and unwrap the brackets in _apply_xheaders so the stored remote_ip is always the bare address. Fixes tornadoweb#3561.
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.
What
is_valid_ip(used to validateX-Forwarded-For/X-Real-IPheaders in
_apply_xheaders) callsgetaddrinfo, which rejects theRFC 3986 URI-reference bracketed IPv6 form (e.g.
[2620:0:d60:ac1a::10])with
EAI_NONAME. Load balancers such as Fortigate emit IPv6 in thisform, so the forwarded address was silently dropped and the request
fell back to the connection peer.
Strip the brackets inside
is_valid_ipso the bracketed form isaccepted and validated as a normal IPv6 address, and unwrap the
brackets in
_apply_xheadersso the storedremote_ipis alwaysthe bare address.
Fixes #3561.