-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Request] Ignore invalid IP addresses sent by proxies #16736
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
Conversation
@@ -858,7 +858,8 @@ public function testGetClientIpsForwardedProvider() | |||
// $expected $remoteAddr $httpForwarded $trustedProxies | |||
return array( | |||
array(array('127.0.0.1'), '127.0.0.1', 'for="_gazonk"', null), | |||
array(array('_gazonk'), '127.0.0.1', 'for="_gazonk"', array('127.0.0.1')), | |||
array(array('127.0.0.1'), '127.0.0.1', 'for="_gazonk"', array('127.0.0.1')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case is modified, but returning something different that an IP address here looks broken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have this test case. See line above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no trusted proxy on the previous test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right.
} | ||
} | ||
|
||
// Now the IP chain contains only untrusted proxies and the client IP | ||
return $clientIps ? array_reverse($clientIps) : array($ip); | ||
return $clientIps ? array_reverse($clientIps) : array($firstTrustedIp); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't this now be able to return array(null)
in some cases though ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GromNaN Any thoughts about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the REMOTE_ADDR header contains an invalid IP address maybe.
Thank you @GromNaN. |
…mNaN) This PR was submitted for the 2.8 branch but it was merged into the 2.3 branch instead (closes #16736). Discussion ---------- [Request] Ignore invalid IP addresses sent by proxies | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | ? | Deprecations? | no | Tests pass? | yes | Fixed tickets | #15525 | License | MIT | Doc PR | n/a The [RFC 7239](https://tools.ietf.org/html/rfc7239#section-6.2) allows other values that IP addresses to be passed in `Forwarded`header and [Nginx can add `unknown` to the `X-Forwarded-For`header](http://www.squid-cache.org/Doc/config/forwarded_for/). To prevent these invalid IP addresses from being returned as "Client IP", this PR ensure that they are excluded. Commits ------- 6578806 [Request] Ignore invalid IP addresses sent by proxies
The RFC 7239 allows other values that IP addresses to be passed in
Forwarded
header and Nginx can addunknown
to theX-Forwarded-For
header.To prevent these invalid IP addresses from being returned as "Client IP", this PR ensure that they are excluded.