diff --git a/lib/private/AppFramework/Http/Request.php b/lib/private/AppFramework/Http/Request.php index 5f0b8873080e3..5e5daf0a2d3d0 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 316ed84ea3f84..248f3bba9a368 100644 --- a/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php +++ b/lib/private/AppFramework/Middleware/Security/PasswordConfirmationMiddleware.php @@ -83,11 +83,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 4eca6beb08b07..f3c5ff1e973f1 100644 --- a/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/PasswordConfirmationMiddlewareTest.php @@ -202,4 +202,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); + } }