From 86b79462492c6c26ecfd850b43744a7afc0e3222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 24 Nov 2026 17:32:47 +0100 Subject: [PATCH 1/2] fix: Trigger same logic as login failure when Bearer token is not valid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/User/Session.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php index 46897845cbdf8..339c13bfe4800 100644 --- a/lib/private/User/Session.php +++ b/lib/private/User/Session.php @@ -4,6 +4,7 @@ * SPDX-FileCopyrightText: 2016 ownCloud, Inc. * SPDX-License-Identifier: AGPL-3.0-only */ + namespace OC\User; use OC; @@ -70,6 +71,8 @@ class Session implements IUserSession, Emitter { /** @var User $activeUser */ protected $activeUser; + private ?IThrottler $throttler = null; + public function __construct( private Manager $manager, private ISession $session, @@ -83,6 +86,11 @@ public function __construct( ) { } + private function getThrottler(): IThrottler { + $this->throttler ??= Server::get(IThrottler::class); + return $this->throttler; + } + /** * @param IProvider $provider */ @@ -829,6 +837,7 @@ private function validateTokenLoginName(?string $loginName, IToken $token): bool * @return boolean */ public function tryTokenLogin(IRequest $request) { + $throttler = $this->getThrottler(); $authHeader = $request->getHeader('Authorization'); $tokenFromCookie = false; if (str_starts_with($authHeader, 'Bearer ')) { @@ -846,10 +855,13 @@ public function tryTokenLogin(IRequest $request) { return false; } + $remoteAddress = $request->getRemoteAddress(); + $currentDelay = $throttler->sleepDelayOrThrowOnMax($remoteAddress, 'login'); + try { $dbToken = $this->tokenProvider->getToken($token); } catch (InvalidTokenException $e) { - // Can't really happen but better safe than sorry + $this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, '', $token); return false; } @@ -859,9 +871,11 @@ public function tryTokenLogin(IRequest $request) { } if (!$this->loginWithToken($token)) { + $this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, $dbToken->getUID(), $token); return false; } if (!$this->validateToken($token)) { + $this->handleLoginFailed($throttler, $currentDelay, $remoteAddress, $dbToken->getUID(), $token); return false; } From ff2e747379dbaec1cfc85228a4f9ee1cc8172730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 1 Dec 2026 16:31:11 +0100 Subject: [PATCH 2/2] chore: Disable bruteforce protection for cypress tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- cypress/dockerNode.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cypress/dockerNode.ts b/cypress/dockerNode.ts index 3ff87051f738d..67d4666c31ed0 100644 --- a/cypress/dockerNode.ts +++ b/cypress/dockerNode.ts @@ -144,6 +144,10 @@ export const configureNextcloud = async function() { // Speed up test and make them less flaky. If a cron execution is needed, it can be triggered manually. await runExec(container, ['php', 'occ', 'background:cron'], true) + // Disable bruteforce protection to not run into it + await runExec(container, ['php', 'occ', 'config:system:set', 'auth.bruteforce.protection.enabled', '--value', 'false', '--type', 'boolean'], true) + await runExec(container, ['php', 'occ', 'config:system:set', 'ratelimit.protection.enabled', '--value', 'false', '--type', 'boolean'], true) + // Checking apcu const distributed = await runExec(container, ['php', 'occ', 'config:system:get', 'memcache.distributed']) const local = await runExec(container, ['php', 'occ', 'config:system:get', 'memcache.local'])