Skip to content
Merged
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
2 changes: 2 additions & 0 deletions lib/private/AppFramework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ public function getHeader(string $name): string {
'CONTENT_TYPE' => true,
'CONTENT_LENGTH' => true,
'REMOTE_ADDR' => true,
'PHP_AUTH_USER' => true,
'PHP_AUTH_PW' => true,
];

if (isset($specialKeys[$elementName]) && isset($this->server[$elementName])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ public function beforeController(Controller $controller, string $methodName): vo

$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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ public function testAttribute() {
#[PasswordConfirmationRequired]
public function testSSO() {
}

#[PasswordConfirmationRequired(strict: true)]
public function testAuthHeader() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,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);
Comment on lines +229 to +236

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can be simplified to just call the method without a catch and assertion.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was just following the schema that is used in the file already.

}
}
Loading