diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2019-02-12 09:46:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-12 09:46:21 +0100 |
commit | 0ff8c309d331e0881bdaad24e20495ff40f02f4c (patch) | |
tree | 4e08bc1bb0c7cd59b0031e501f71087da2884f7b | |
parent | 7192688c98a1b5715bc9af43f8197e9cf31e25db (diff) | |
parent | cb0b6cedd1a19f205134bf2b84698cd74e9f7428 (diff) | |
download | nextcloud-server-0ff8c309d331e0881bdaad24e20495ff40f02f4c.tar.gz nextcloud-server-0ff8c309d331e0881bdaad24e20495ff40f02f4c.zip |
Merge pull request #14152 from nextcloud/backport/14149/stable14
[stable14] Fix the thorrtler whitelist bitmask
-rw-r--r-- | lib/private/Security/Bruteforce/Throttler.php | 6 | ||||
-rw-r--r-- | tests/lib/Security/Bruteforce/ThrottlerTest.php | 29 |
2 files changed, 33 insertions, 2 deletions
diff --git a/lib/private/Security/Bruteforce/Throttler.php b/lib/private/Security/Bruteforce/Throttler.php index 3282121d967..ec56b4f7ee2 100644 --- a/lib/private/Security/Bruteforce/Throttler.php +++ b/lib/private/Security/Bruteforce/Throttler.php @@ -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; diff --git a/tests/lib/Security/Bruteforce/ThrottlerTest.php b/tests/lib/Security/Bruteforce/ThrottlerTest.php index dac12a00dcd..da386db9d2d 100644 --- a/tests/lib/Security/Bruteforce/ThrottlerTest.php +++ b/tests/lib/Security/Bruteforce/ThrottlerTest.php @@ -101,6 +101,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', [ 'whitelist_0' => '192.168.0.0/16', @@ -128,6 +149,14 @@ class ThrottlerTest extends TestCase { true, ], [ + 'dead:beef:cafe::1111', + [ + 'whitelist_0' => 'dead:beef:cafe::1100/123', + + ], + true, + ], + [ 'invalid', [], false, |