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 apps/dav/lib/Connector/Sabre/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Exception;
use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
use OC\Authentication\TwoFactorAuth\Manager;
use OC\User\LoginException;
use OC\User\Session;
use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
use OCA\DAV\Connector\Sabre\Exception\TooManyRequests;
Expand Down Expand Up @@ -109,6 +110,9 @@ public function check(RequestInterface $request, ResponseInterface $response) {
return $this->auth($request, $response);
} catch (NotAuthenticated $e) {
throw $e;
} catch (LoginException $e) {
Server::get(LoggerInterface::class)->info($e->getMessage(), ['exception' => $e]);
throw new NotAuthenticated($e->getMessage(), 0, $e);
Comment on lines +113 to +115
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

When a LoginException bubbles up from validateUserPass()/auth(), the PHP session may still be open (validateUserPass() does not close the session on LoginException). This catch block converts the exception but doesn't close the session either, which can keep the session lock held longer than necessary and potentially slow down concurrent requests. Call $this->session->close() (ideally in a finally or at least before logging/throwing) on this path as well.

Copilot uses AI. Check for mistakes.
Comment on lines +114 to +115
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

Propagating the LoginException message to the client (via NotAuthenticated) can reveal account state (e.g. disabled vs. non-existent/wrong password), enabling user/account enumeration over WebDAV. Consider returning a generic NotAuthenticated message (consistent with other auth failures) while logging the detailed reason server-side.

Copilot uses AI. Check for mistakes.
} catch (Exception $e) {
$class = get_class($e);
$msg = $e->getMessage();
Expand Down
30 changes: 30 additions & 0 deletions apps/dav/tests/unit/Connector/Sabre/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
use OC\Authentication\TwoFactorAuth\Manager;
use OC\User\LoginException;
use OC\User\Session;
use OCA\DAV\Connector\Sabre\Auth;
use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
Expand Down Expand Up @@ -586,6 +587,35 @@ public function testAuthenticateValidCredentials(): void {
$this->assertEquals([true, 'principals/users/MyTestUser'], $response);
}

public function testCheckWithLoginExceptionThrowsNotAuthenticated(): void {
$this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class);
$this->expectExceptionMessage('User disabled');

$httpRequest = $this->createMock(RequestInterface::class);
$httpResponse = $this->createMock(ResponseInterface::class);
$this->userSession
->expects($this->any())
->method('isLoggedIn')
->willReturn(false);
$httpRequest
->expects($this->any())
->method('getHeader')
->willReturnMap([
['Authorization', 'basic dXNlcm5hbWU6cGFzc3dvcmQ='],
['X-Requested-With', null],
]);
$this->userSession
->expects($this->once())
->method('logClientIn')
->with('username', 'password')
->willThrowException(new LoginException('User disabled'));
$this->session
->expects($this->once())
->method('close');

$this->auth->check($httpRequest, $httpResponse);
}

public function testAuthenticateInvalidCredentials(): void {
$server = $this->createMock(Server::class);
$server->httpRequest = $this->createMock(Request::class);
Expand Down
Loading