Skip to content

Commit

Permalink
Merge pull request #14152 from nextcloud/backport/14149/stable14
Browse files Browse the repository at this point in the history
[stable14] Fix the thorrtler whitelist bitmask
  • Loading branch information
rullzer authored Feb 12, 2019
2 parents 7192688 + cb0b6ce commit 0ff8c30
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/private/Security/Bruteforce/Throttler.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@ private function isIPWhitelisted($ip) {
$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;
Expand Down
29 changes: 29 additions & 0 deletions tests/lib/Security/Bruteforce/ThrottlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,27 @@ public function dataIsIPWhitelisted() {
],
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',
[
Expand Down Expand Up @@ -127,6 +148,14 @@ public function dataIsIPWhitelisted() {
],
true,
],
[
'dead:beef:cafe::1111',
[
'whitelist_0' => 'dead:beef:cafe::1100/123',

],
true,
],
[
'invalid',
[],
Expand Down

0 comments on commit 0ff8c30

Please sign in to comment.