-
Notifications
You must be signed in to change notification settings - Fork 127
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
Fix IPv6 non-specified ranges unexpectedly allowed #1830
Conversation
Hi @Jimadine ! Thank you so much for both, reporting this issue and submitting this PR to fix it. We'll review the PR soon, and if everything looks good, get this fix in for the next release. When you get a chance, would you be able to sign our Contributor Agreement? Here's a link with details about it agreement — |
You're very welcome! 😄
I've just this moment emailed my signed agreement to [email protected] |
@Jimadine yup, we received it. Thanks! |
@Jimadine I just looked at your changes and this fix makes sense to me. I noticed that our syntax checks are failing (probably indentation related), and we like to keep our commit message header to 50 characters but the rest looks good! Would you be able to fix those? If not, I'm happy to add a commit fixing those and then accept the changes! |
Hi @anvit - I have amended the commit message and fixed the indentation. Hopefully the syntax checks will pass now 😃. |
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.
@Jimadine unfortunately syntax checks are still failing. I found the lines it was complaining about and flagged them in the review.
lib/filter/QubitLimitIp.class.php
Outdated
ip2long($limit[0]) <= $addressLong | ||
&& ip2long($limit[1]) >= $addressLong | ||
(strlen($addressBinary) == strlen($firstInRangeBinary)) | ||
&& ($addressBinary >= $firstInRangeBinary && $addressBinary <= $lastInRangeBinary) | ||
) { | ||
return true; | ||
} | ||
} | ||
} |
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.
Syntax checks seem to be failing due to missing new line before return statement. Please add an empty new line before the return here.
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.
After adding the extra blank line, CS fixer complained about it:
root@ubuntu-focal:/usr/share/nginx/atom# php composer.phar php-cs-fixer fix /usr/share/nginx/atom/lib/filter/QubitLimitIp.class.php -v
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]?
> php-cs-fixer: php-cs-fixer 'fix' '/usr/share/nginx/atom/lib/filter/QubitLimitIp.class.php'
PHP CS Fixer 3.59.3 7th Gear by Fabien Potencier, Dariusz Ruminski and contributors.
PHP runtime: 7.4.3-4ubuntu2.23
Running analysis on 1 core sequentially.
You can enable parallel runner and speed up the analysis! Please see usage docs for more information.
Loaded config default from "/usr/share/nginx/atom/.php-cs-fixer.dist.php".
Using cache file ".php-cs-fixer.cache".
Paths from configuration file have been overridden by paths provided as command arguments.
1/1 [...] 100%
1) lib/filter/QubitLimitIp.class.php (no_extra_blank_lines)
Fixed 1 of 1 files in 0.125 seconds, 18.00 MB memory used
root@ubuntu-focal:/usr/share/nginx/atom# git diff lib/filter/QubitLimitIp.class.php
diff --git a/lib/filter/QubitLimitIp.class.php b/lib/filter/QubitLimitIp.class.php
index 592277d..cb0dbf6 100644
--- a/lib/filter/QubitLimitIp.class.php
+++ b/lib/filter/QubitLimitIp.class.php
@@ -90,7 +90,6 @@ class QubitLimitIpFilter extends sfFilter
(strlen($addressBinary) == strlen($firstInRangeBinary))
&& ($addressBinary >= $firstInRangeBinary && $addressBinary <= $lastInRangeBinary)
) {
-
return true;
}
}
...so I went with the CS fixer fix to remove it, and now the syntax check passes 🚀
lib/filter/QubitLimitIp.class.php
Outdated
return false; | ||
} | ||
|
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.
Syntax checker also asks to remove this empty line.
@anvit - thank you for identifying what needs to be changed 😄. When I ran PHP CS fixer with the default rules, it made the following change:
But it didn't make the changes you've identified. I'm wondering if that's because there are customisations to the rules. I can see a rule in
Do you have any thoughts on why PHP CS fixer isn't identifying/fixing those lines for me? No worries if not; I can make the changes manually. |
@Jimadine Hmm… I'm not entirely sure but my guess is that the rules aren't being picked up? I usually run it via the composer script like this |
@anvit - I don't usually do AtoM development, so I downloaded the latest version of PHP and php-cs-fixer.phar to a folder on my Windows machine. My testing has been on our Ubuntu 20.04 VMWare test server. I tend to use Vagrant a lot, though more for deployment testing purposes. For this purpose, I've spun up a Vagrant Ubuntu 20.04 box with PHP 7.4, installed the composer dependencies with
So in addition to removing line 99 that you identified, it wants a new line at line 97, before the I'm not sure why I'm seeing these discrepancies. I have installed the latest Composer version I see the syntax checking has failed on my fork again 😞. |
@anvit - I think all should be well now - see my comment. One for a new issue perhaps, but it might be helpful to add the
It's not ideal that there's no line number reference, but at least it's something. |
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.
@Jimadine Thank you! Your last commit fixed the syntax check issues!
As reported in #1821.
As alluded to in the issue text, I am entirely happy for someone to pull my changes apart and rewrite. We are already using the modified
QubitLimitIp.class.php
in production, and it meets our basic needs.For the future: it would be a good idea to also validate the input box content so that the administrator adding IPs/ranges can be sure what they have entered meets the required format. I've created a simple example of how this could be done in Javascript, but it could be implemented differently e.g. entirely server-side.