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

[Request] Ignore invalid IP addresses sent by proxies #16736

Closed
wants to merge 1 commit into from

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Nov 28, 2015

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 allows other values that IP addresses to be passed in Forwardedheader and Nginx can add unknown to the X-Forwarded-Forheader.

To prevent these invalid IP addresses from being returned as "Client IP", this PR ensure that they are excluded.

@@ -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')),
Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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);
Copy link
Member

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 ?

Copy link
Member

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?

Copy link
Member Author

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.

@fabpot
Copy link
Member

fabpot commented Jan 25, 2016

Thank you @GromNaN.

fabpot added a commit that referenced this pull request Jan 25, 2016
…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
@fabpot fabpot closed this Jan 25, 2016
@fabpot fabpot mentioned this pull request Feb 3, 2016
@GromNaN GromNaN deleted the unknown-ip-15525 branch February 3, 2016 14:29
This was referenced Feb 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants