Skip to content

[Security] Display authenticators laziness and exception in the profiler #57382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,12 @@
<tr>
<th>Authenticator</th>
<th>Supports</th>
<th>Lazy</th>
<th>Authenticated</th>
<th>Duration</th>
<th>Passport</th>
<th>Badges</th>
<th>Exception</th>
</tr>
</thead>

Expand All @@ -361,7 +363,8 @@
<tr>
<td class="font-normal">{{ profiler_dump(authenticator.stub) }}</td>
<td class="no-wrap">{{ source('@WebProfiler/Icon/' ~ (authenticator.supports ? 'yes' : 'no') ~ '.svg') }}</td>
<td class="no-wrap">{{ authenticator.authenticated is not null ? source('@WebProfiler/Icon/' ~ (authenticator.authenticated ? 'yes' : 'no') ~ '.svg') : '' }}</td>
<td class="no-wrap">{{ authenticator.lazy is not null ? source('@WebProfiler/Icon/' ~ (authenticator.lazy ? 'yes' : 'no') ~ '.svg') }}</td>
<td class="no-wrap">{{ authenticator.authenticated is not null ? source('@WebProfiler/Icon/' ~ (authenticator.authenticated ? 'yes' : 'no') ~ '.svg') }}</td>
<td class="no-wrap">{{ authenticator.duration is null ? '(none)' : '%0.2f ms'|format(authenticator.duration * 1000) }}</td>
<td class="font-normal">{{ authenticator.passport ? profiler_dump(authenticator.passport) : '(none)' }}</td>
<td class="font-normal">
Expand All @@ -373,6 +376,7 @@
(none)
{% endfor %}
</td>
<td class="font-normal">{{ authenticator.exception ? profiler_dump(authenticator.exception) : '(none)' }}</td>
</tr>

{% if loop.last %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ final class TraceableAuthenticator implements AuthenticatorInterface, Interactiv
private ?float $duration = null;
private ClassStub|string $stub;
private ?bool $authenticated = null;
private ?bool $lazy = null;
private ?AuthenticationException $exception = null;

public function __construct(private AuthenticatorInterface $authenticator)
{
Expand All @@ -56,12 +58,18 @@ static function (BadgeInterface $badge): array {
},
$this->passport?->getBadges() ?? [],
),
'lazy' => $this->lazy,
'exception' => $this->exception,
];
}

public function supports(Request $request): ?bool
{
return $this->authenticator->supports($request);
$supports = $this->authenticator->supports($request);

$this->lazy = null === $supports;

return $supports;
}

public function authenticate(Request $request): Passport
Expand All @@ -88,6 +96,7 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token,
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
{
$this->authenticated = false;
$this->exception = $exception->getPrevious() instanceof AuthenticationException ? $exception->getPrevious() : $exception;

return $this->authenticator->onAuthenticationFailure($request, $exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public function authenticate(RequestEvent $event): void
'duration' => 0,
'authenticated' => null,
'badges' => [],
'lazy' => null,
'exception' => null,
];
}

Expand Down
Loading