Skip to content
Open
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
4 changes: 4 additions & 0 deletions cypress/dockerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
16 changes: 15 additions & 1 deletion lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace OC\User;

use OC;
Expand Down Expand Up @@ -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,
Expand All @@ -83,6 +86,11 @@ public function __construct(
) {
}

private function getThrottler(): IThrottler {
$this->throttler ??= Server::get(IThrottler::class);
return $this->throttler;
}

/**
* @param IProvider $provider
*/
Expand Down Expand Up @@ -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 ')) {
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
Loading