Merge pull request #14149 from nextcloud/fix/throttler_bitmask

Fix the thorrtler whitelist bitmask
This commit is contained in:
Roeland Jago Douma 2019-02-12 08:54:19 +01:00 committed by GitHub
commit 004f7fa8e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 2 deletions

View file

@ -177,8 +177,10 @@ class Throttler {
$part = ord($addr[(int)($i/8)]);
$orig = ord($ip[(int)($i/8)]);
$part = $part & (15 << (1 - ($i % 2)));
$orig = $orig & (15 << (1 - ($i % 2)));
$bitmask = 1 << (7 - ($i % 8));
$part = $part & $bitmask;
$orig = $orig & $bitmask;
if ($part !== $orig) {
$valid = false;

View file

@ -100,6 +100,27 @@ class ThrottlerTest extends TestCase {
],
true,
],
[
'10.10.10.10',
[
'whitelist_0' => '10.10.10.11/31',
],
true,
],
[
'10.10.10.10',
[
'whitelist_0' => '10.10.10.9/31',
],
false,
],
[
'10.10.10.10',
[
'whitelist_0' => '10.10.10.15/29',
],
true,
],
[
'dead:beef:cafe::1',
[
@ -127,6 +148,14 @@ class ThrottlerTest extends TestCase {
],
true,
],
[
'dead:beef:cafe::1111',
[
'whitelist_0' => 'dead:beef:cafe::1100/123',
],
true,
],
[
'invalid',
[],