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

Implementing trusted_proxies CIDR notation capability for IPv6 #12535

Closed
wants to merge 31 commits into from

Conversation

olivermg
Copy link
Member

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):

  • implement CIDR notation for IPv6
  • introduce an abstraction layer for representation of IP addresses/ranges and CIDR notation handling, so other classes than just Request might benefit in the future
  • update config.sample.php to reflect the new capabilities

- IIpAddress
- AbstractIpAddress
- IpAddressV4
- IpAddressV6
- IpAddressFactory

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>
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>
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>
@kesselb
Copy link
Contributor

kesselb commented Nov 19, 2018

@olivermg, thank you for your great contribution 👍

@kesselb kesselb added the 3. to review Waiting for reviews label Nov 19, 2018
@kesselb kesselb added this to the Nextcloud 16 milestone Nov 19, 2018
Signed-off-by: Oliver Wegner <void1976@gmail.com>
@olivermg olivermg force-pushed the feature/6550/trusted-proxies-ipv6-cidr branch from 8f73159 to f82f4fb Compare November 25, 2018 11:03
@@ -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) {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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})$/';

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).

This was referenced Mar 4, 2019
@MorrisJobke MorrisJobke mentioned this pull request Jul 15, 2019
28 tasks
@kesselb
Copy link
Contributor

kesselb commented Jul 15, 2019

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? 🤔
@MorrisJobke looks like Nextcloud 18 to me 🙈

@ChristophWurst
Copy link
Member

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).

I can second that.

@rullzer rullzer modified the milestones: Nextcloud 18, Nextcloud 19 Dec 9, 2019
This was referenced Apr 4, 2020
@ChristophWurst
Copy link
Member

Due to lack of activity I will close this PR for now.

@ChristophWurst ChristophWurst removed this from the Nextcloud 19 milestone Apr 15, 2020
@ChristophWurst ChristophWurst added 0. Needs triage Pending check for reproducibility or if it fits our roadmap and removed 2. developing Work in progress labels Apr 15, 2020
@MorrisJobke MorrisJobke deleted the feature/6550/trusted-proxies-ipv6-cidr branch April 15, 2020 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0. Needs triage Pending check for reproducibility or if it fits our roadmap enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants