Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix the thorrtler whitelist bitmask
Before we actually didn't check each bit of the bitmask. Now we do.

Signed-off-by: Roeland Jago Douma <[email protected]>
  • Loading branch information
rullzer authored and Backportbot committed Feb 12, 2019
commit 096498c0335b5e7461d9d2e4bb1874a42ebef83f
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