diff --git a/lib/private/AppFramework/Http/Request.php b/lib/private/AppFramework/Http/Request.php index f3d4d221fa075..c3a9346386d07 100644 --- a/lib/private/AppFramework/Http/Request.php +++ b/lib/private/AppFramework/Http/Request.php @@ -272,6 +272,8 @@ public function getHeader(string $name): string { case 'CONTENT_TYPE': case 'CONTENT_LENGTH': case 'REMOTE_ADDR': + case 'PHP_AUTH_USER': + case 'PHP_AUTH_PW': if (isset($this->server[$name])) { return $this->server[$name]; } diff --git a/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php b/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php index 2393fb82eb394..f6f60ff96608d 100644 --- a/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php @@ -78,11 +78,12 @@ public function beforeController(Controller $controller, string $methodName) { $reflectionMethod = new ReflectionMethod($controller, $methodName); if ($this->isPasswordConfirmationStrict($reflectionMethod)) { - $authHeader = $this->request->getHeader('Authorization'); - if (!str_starts_with(strtolower($authHeader), 'basic ')) { + $password = $this->request->getHeader('PHP_AUTH_PW'); + + if ($password === '') { throw new NotConfirmedException('Required authorization header missing'); } - [, $password] = explode(':', base64_decode(substr($authHeader, 6)), 2); + $loginName = $this->session->get('loginname'); $loginResult = $this->userManager->checkPassword($loginName, $password); if ($loginResult === false) { diff --git a/tests/lib/AppFramework/Middleware/Security/Mock/PasswordConfirmationMiddlewareController.php b/tests/lib/AppFramework/Middleware/Security/Mock/PasswordConfirmationMiddlewareController.php index cd1cdaa49ca33..8b6cec1fccd37 100644 --- a/tests/lib/AppFramework/Middleware/Security/Mock/PasswordConfirmationMiddlewareController.php +++ b/tests/lib/AppFramework/Middleware/Security/Mock/PasswordConfirmationMiddlewareController.php @@ -35,4 +35,8 @@ public function testAttribute() { #[PasswordConfirmationRequired] public function testSSO() { } + + #[PasswordConfirmationRequired(strict: true)] + public function testAuthHeader() { + } } diff --git a/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php index c1c7e587fd256..f0d63b09e31b6 100644 --- a/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php @@ -208,4 +208,34 @@ public function testSSO(): void { $this->assertSame(false, $thrown); } + + public function testAuthHeader(): void { + $this->reflector->reflect($this->controller, __FUNCTION__); + + $this->user->method('getBackendClassName') + ->willReturn('fictional_backend'); + $this->userSession->method('getUser') + ->willReturn($this->user); + + $this->session->method('get') + ->with('loginname') + ->willReturn('user'); + + $this->request->method('getHeader') + ->with('PHP_AUTH_PW') + ->willReturn('password'); + + $this->userManager->expects($this->once()) + ->method('checkPassword') + ->with('user', 'password'); + + $thrown = false; + try { + $this->middleware->beforeController($this->controller, __FUNCTION__); + } catch (NotConfirmedException) { + $thrown = true; + } + + $this->assertSame(false, $thrown); + } }