Skip to content

Commit 004f7fa

Browse files
authored
Merge pull request nextcloud#14149 from nextcloud/fix/throttler_bitmask
Fix the thorrtler whitelist bitmask
2 parents 44f6303 + f1ea56b commit 004f7fa

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/private/Security/Bruteforce/Throttler.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ private function isIPWhitelisted($ip) {
177177
$part = ord($addr[(int)($i/8)]);
178178
$orig = ord($ip[(int)($i/8)]);
179179

180-
$part = $part & (15 << (1 - ($i % 2)));
181-
$orig = $orig & (15 << (1 - ($i % 2)));
180+
$bitmask = 1 << (7 - ($i % 8));
181+
182+
$part = $part & $bitmask;
183+
$orig = $orig & $bitmask;
182184

183185
if ($part !== $orig) {
184186
$valid = false;

tests/lib/Security/Bruteforce/ThrottlerTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,27 @@ public function dataIsIPWhitelisted() {
100100
],
101101
true,
102102
],
103+
[
104+
'10.10.10.10',
105+
[
106+
'whitelist_0' => '10.10.10.11/31',
107+
],
108+
true,
109+
],
110+
[
111+
'10.10.10.10',
112+
[
113+
'whitelist_0' => '10.10.10.9/31',
114+
],
115+
false,
116+
],
117+
[
118+
'10.10.10.10',
119+
[
120+
'whitelist_0' => '10.10.10.15/29',
121+
],
122+
true,
123+
],
103124
[
104125
'dead:beef:cafe::1',
105126
[
@@ -127,6 +148,14 @@ public function dataIsIPWhitelisted() {
127148
],
128149
true,
129150
],
151+
[
152+
'dead:beef:cafe::1111',
153+
[
154+
'whitelist_0' => 'dead:beef:cafe::1100/123',
155+
156+
],
157+
true,
158+
],
130159
[
131160
'invalid',
132161
[],

0 commit comments

Comments
 (0)