-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Implementing trusted_proxies CIDR notation capability for IPv6 #12535
Conversation
- IIpAddress - AbstractIpAddress - IpAddressV4 - IpAddressV6 - IpAddressFactory Signed-off-by: Oliver Wegner <void1976@gmail.com>
Signed-off-by: Oliver Wegner <void1976@gmail.com>
…0/trusted-proxies-ipv6-cidr
Signed-off-by: Oliver Wegner <void1976@gmail.com>
Signed-off-by: Oliver Wegner <void1976@gmail.com>
…0/trusted-proxies-ipv6-cidr
Signed-off-by: Oliver Wegner <void1976@gmail.com>
Signed-off-by: Oliver Wegner <void1976@gmail.com>
Signed-off-by: Oliver Wegner <void1976@gmail.com>
Signed-off-by: Oliver Wegner <void1976@gmail.com>
Signed-off-by: Oliver Wegner <void1976@gmail.com>
Signed-off-by: Oliver Wegner <void1976@gmail.com>
Signed-off-by: Oliver Wegner <void1976@gmail.com>
Signed-off-by: Oliver Wegner <void1976@gmail.com>
…0/trusted-proxies-ipv6-cidr
as this is now being done by classes in OC\Net Signed-off-by: Oliver Wegner <void1976@gmail.com>
Signed-off-by: Oliver Wegner <void1976@gmail.com>
Signed-off-by: Oliver Wegner <void1976@gmail.com>
Signed-off-by: Oliver Wegner <void1976@gmail.com>
Signed-off-by: Oliver Wegner <void1976@gmail.com>
…0/trusted-proxies-ipv6-cidr
@olivermg, thank you for your great contribution 👍 |
Signed-off-by: Oliver Wegner <void1976@gmail.com>
8f73159
to
f82f4fb
Compare
…/trusted-proxies-ipv6-cidr
…0/trusted-proxies-ipv6-cidr
@@ -136,12 +140,14 @@ public function __construct(array $vars= [], | |||
ISecureRandom $secureRandom = null, | |||
IConfig $config, | |||
CsrfTokenManager $csrfTokenManager = null, | |||
string $stream = 'php://input') { | |||
string $stream = 'php://input', | |||
IIpAddressFactory $ipAddressFactory = null) { |
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.
Any particular reason why this is nullable?
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.
Not from an application logic point of view and I really don't like it this way. However, making it a mandatory argument will force me to touch quite a few lines of code elsewhere (most in tests though).
$ egrep -rn 'new ([\\[:alnum:]]+\\)?Request[^[:alnum:]]' apps tests lib contribute ocs* ocm-provider settings resources themes config core | grep -v Sabre | wc -l
96
I had initially been happy that there were only two locations in the code that really instantiate Request
, but I had not found all of them in production code (e.g. in base.php
) and had also not taken the tests into account.
It'll take some time for me to put that additional effort into 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.
It'll take some time for me to put that additional effort into this.
Unfortunately this is the correct way to do this. Otherwise this is bound to fail someone in the future that assumes the argument is optional.
* @return string | ||
*/ | ||
protected function getCidrRegex(): string { | ||
return '/^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\/([0-9]{1,2})$/'; |
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 regex matches invalid IPv4 subnets: https://regex101.com/r/tjtE95/1 (same for IPv6 in the IpAddressV6
class).
As IP address are numbers, I think you could use numerical comparison and avoid relying on regexes (that will most certainly be incorrect in a way or another). I'm not really into PHP so I'm not sure what's the best way to do that (to be honest it bugs me that this is not part of the standard library).
Also, I think it would be useful to warn the administrator when they put a wrong value in the configuration (thus using another "parsing" method).
I am unsure about this pr. The way we implement the logic looks quite complex compared to https://github.com/symfony/http-foundation/blob/master/IpUtils.php. There is only a little chance that his logic (is ipv4 or is ipv6) changes in the near future (e.g. add ipvX). @ChristophWurst what should we do? 🤔 |
I can second that. |
Due to lack of activity I will close this PR for now. |
This PR aims to enhance the capabilities for specifying IP addresses in CIDR notation in the
trusted_proxies
config param (refer to issue #6550 and PR #12036 for more info):Request
might benefit in the futureconfig.sample.php
to reflect the new capabilities