Registry Mirror
Skip to content

Conversation

@skjnldsv

Copy link
Copy Markdown
Member

I don't see why that would happen, but this should help us investigate #53472

@skjnldsv skjnldsv self-assigned this Jun 13, 2025
@skjnldsv
skjnldsv requested a review from a team as a code owner June 13, 2025 15:09
@skjnldsv
skjnldsv requested review from artonge, icewind1991 and provokateurin and removed request for a team June 13, 2025 15:09
@skjnldsv skjnldsv added bug 3. to review Waiting for reviews labels Jun 13, 2025
@skjnldsv
skjnldsv force-pushed the fix/PasswordConfirmationMiddleware-empty-header branch from 0999b67 to ed731d8 Compare June 13, 2025 15:21
…nfirmationMiddleware

Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
@skjnldsv
skjnldsv force-pushed the fix/PasswordConfirmationMiddleware-empty-header branch from ed731d8 to 85070ea Compare June 13, 2025 15:29
if ($this->isPasswordConfirmationStrict($reflectionMethod)) {
$authHeader = $this->request->getHeader('Authorization');
// If no Authorization header is set, we cannot confirm the password
if (empty($authHeader) || !str_starts_with($authHeader, 'Basic ')) {

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.

Suggested change
if (empty($authHeader) || !str_starts_with($authHeader, 'Basic ')) {
if (!str_starts_with($authHeader, 'Basic ')) {

A string is always returned, so this is enough

$authHeader = $this->request->getHeader('Authorization');
// If no Authorization header is set, we cannot confirm the password
if (empty($authHeader) || !str_starts_with($authHeader, 'Basic ')) {
throw new \Exception('Missing or invalid Authorization header', Http::STATUS_BAD_REQUEST);

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.

Suggested change
throw new \Exception('Missing or invalid Authorization header', Http::STATUS_BAD_REQUEST);
throw new \Exception('Missing or invalid Authorization header', Http::STATUS_UNAUTHORIZED);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, this is on purpose to differentiate.
We expect an auth header, if it'snot here, this is a bad request

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.

But if you don't send the header at all, you will also get an empty string. I think HTTP semantics wise 401 is correct, but I get why you want to use 400.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Which is ok? I actually wanna catch the lack of header ! 🙂‍↕️

@come-nc come-nc Jun 19, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you need to add an afterException method to the middleware to translate its exception into an response (so that is has the HTTP code you want).
For that you should use your own Exception class and test against it in afterException.
See

public function afterException($controller, $methodName, \Exception $exception): Response {
for an example

@skjnldsv skjnldsv closed this Jul 1, 2025
@skjnldsv
skjnldsv deleted the fix/PasswordConfirmationMiddleware-empty-header branch July 1, 2025 07:16
@skjnldsv

skjnldsv commented Jul 1, 2025

Copy link
Copy Markdown
Member Author

Superseded by 8b0a3a7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants