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
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$part &= $bitmask; and $orig &= $bitmask; would also work but is hard to read.


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