Skip to content

Commit e53fe86

Browse files
committed
fix: Pass an array instead of concatenation for user+password unique identifier
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 9c9cac6 commit e53fe86

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

‎apps/dav/lib/Connector/LegacyPublicAuth.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected function validateUserPass($username, $password) {
6161
try {
6262
$share = $this->shareManager->getShareByToken($username);
6363
} catch (ShareNotFound $e) {
64-
$this->throttler->registerUniqueAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress(), $username . $password);
64+
$this->throttler->registerUniqueAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress(), [$username, $password]);
6565
return false;
6666
}
6767

@@ -95,12 +95,12 @@ protected function validateUserPass($username, $password) {
9595
throw new NotAuthenticated('Cannot authenticate over ajax calls');
9696
}
9797

98-
$this->throttler->registerUniqueAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress(), $username . $password);
98+
$this->throttler->registerUniqueAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress(), [$username, $password]);
9999
return false;
100100
} elseif ($share->getShareType() === IShare::TYPE_REMOTE) {
101101
return true;
102102
} else {
103-
$this->throttler->registerUniqueAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress(), $username . $password);
103+
$this->throttler->registerUniqueAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress(), [$username, $password]);
104104
return false;
105105
}
106106
}

‎apps/dav/lib/Connector/Sabre/PublicAuth.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ protected function validateUserPass($username, $password) {
173173
try {
174174
$share = $this->getShare();
175175
} catch (ShareNotFound $e) {
176-
$this->throttler->registerUniqueAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress(), $username . $password);
176+
$this->throttler->registerUniqueAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress(), [$username, $password]);
177177
return false;
178178
}
179179

@@ -205,13 +205,13 @@ protected function validateUserPass($username, $password) {
205205
throw new NotAuthenticated('Cannot authenticate over ajax calls');
206206
}
207207

208-
$this->throttler->registerUniqueAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress(), $username . $password);
208+
$this->throttler->registerUniqueAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress(), [$username, $password]);
209209
return false;
210210
} elseif ($share->getShareType() === IShare::TYPE_REMOTE) {
211211
return true;
212212
}
213213

214-
$this->throttler->registerUniqueAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress(), $username . $password);
214+
$this->throttler->registerUniqueAttempt(self::BRUTEFORCE_ACTION, $this->request->getRemoteAddress(), [$username, $password]);
215215
return false;
216216
}
217217

‎lib/private/User/Session.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ public function logClientIn($user,
483483
private function handleLoginFailed(IThrottler $throttler, int $currentDelay, string $remoteAddress, string $user, ?string $password) {
484484
$this->logger->debug("Login failed: '" . $user . "' (Remote IP: '" . $remoteAddress . "')", ['app' => 'core', 'exception' => new \Exception()]);
485485

486-
$throttler->registerUniqueAttempt('login', $remoteAddress, $user . ($password ?? ''), ['user' => $user]);
486+
$throttler->registerUniqueAttempt('login', $remoteAddress, [$user, $password], ['user' => $user]);
487487
$this->dispatcher->dispatchTyped(new LoginFailed($user, $password));
488488

489489
if ($currentDelay === 0) {

‎tests/lib/User/SessionTest.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ public function testLogClientInNoTokenPasswordWith2fa(): void {
525525
$this->throttler
526526
->expects($this->once())
527527
->method('registerUniqueAttempt')
528-
->with('login', '192.168.0.1', 'johndoe', ['user' => 'john']);
528+
->with('login', '192.168.0.1', ['john','doe'], ['user' => 'john']);
529529
$this->dispatcher
530530
->expects($this->exactly(2))
531531
->method('dispatchTyped')
@@ -655,7 +655,7 @@ public function testLogClientInNoTokenPasswordNo2fa(): void {
655655
$this->throttler
656656
->expects($this->once())
657657
->method('registerUniqueAttempt')
658-
->with('login', '192.168.0.1', 'johndoe', ['user' => 'john']);
658+
->with('login', '192.168.0.1', ['john','doe'], ['user' => 'john']);
659659

660660
$this->dispatcher
661661
->expects($this->exactly(2))
@@ -1564,7 +1564,7 @@ public function testLogClientInThrottlerUsername(): void {
15641564
$this->throttler
15651565
->expects($this->once())
15661566
->method('registerUniqueAttempt')
1567-
->with('login', '192.168.0.1', 'johnI-AM-A-PASSWORD', ['user' => 'john']);
1567+
->with('login', '192.168.0.1', ['john','I-AM-A-PASSWORD'], ['user' => 'john']);
15681568
$this->dispatcher
15691569
->expects($this->exactly(2))
15701570
->method('dispatchTyped')
@@ -1627,7 +1627,7 @@ public function testLogClientInThrottlerEmail(): void {
16271627
$this->throttler
16281628
->expects($this->once())
16291629
->method('registerUniqueAttempt')
1630-
->with('login', '192.168.0.1', 'john@foo.barI-AM-A-PASSWORD', ['user' => 'john@foo.bar']);
1630+
->with('login', '192.168.0.1', ['john@foo.bar','I-AM-A-PASSWORD'], ['user' => 'john@foo.bar']);
16311631
$this->dispatcher
16321632
->expects($this->exactly(2))
16331633
->method('dispatchTyped')

0 commit comments

Comments
 (0)