Skip to content

[SecurityBundle] Link to the profile the token was (de)authenticated #57692

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

Merged
merged 1 commit into from
Jul 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener;
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
Expand Down Expand Up @@ -195,6 +196,27 @@ public function collect(Request $request, Response $response, ?\Throwable $excep
}

$this->data['authenticators'] = $this->firewall ? $this->firewall->getAuthenticatorsInfo() : [];

if ($this->data['listeners'] && !($this->data['firewall']['stateless'] ?? true)) {
$authCookieName = "{$this->data['firewall']['name']}_auth_profile_token";
$deauthCookieName = "{$this->data['firewall']['name']}_deauth_profile_token";
$profileToken = $response->headers->get('X-Debug-Token');

$this->data['auth_profile_token'] = $request->cookies->get($authCookieName);
$this->data['deauth_profile_token'] = $request->cookies->get($deauthCookieName);

if ($this->data['authenticated'] && !$this->data['auth_profile_token']) {
$response->headers->setCookie(new Cookie($authCookieName, $profileToken));

$this->data['deauth_profile_token'] = null;
$response->headers->clearCookie($deauthCookieName);
} elseif(!$this->data['authenticated'] && !$this->data['deauth_profile_token']) {
$response->headers->setCookie(new Cookie($deauthCookieName, $profileToken));

$this->data['auth_profile_token'] = null;
$response->headers->clearCookie($authCookieName);
}
}
}

public function reset(): void
Expand Down Expand Up @@ -339,6 +361,16 @@ public function getAuthenticators(): array|Data
return $this->data['authenticators'];
}

public function getAuthProfileToken(): string|Data|null
{
return $this->data['auth_profile_token'] ?? null;
}

public function getDeauthProfileToken(): string|Data|null
{
return $this->data['deauth_profile_token'] ?? null;
}

public function getName(): string
{
return 'security';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@
<span class="value">{{ source('@WebProfiler/Icon/' ~ (collector.authenticated ? 'yes' : 'no') ~ '.svg') }}</span>
<span class="label">Authenticated</span>
</div>

{% if collector.authProfileToken %}
<div class="metric">
<span class="value">
<a href="{{ path('_profiler', {token: collector.authProfileToken, panel: 'security'}) }}">
{{- collector.authProfileToken -}}
</a>
</span>
<span class="label">From</span>
</div>
{% endif %}
</div>

<table>
Expand Down Expand Up @@ -219,7 +230,15 @@
</table>
{% elseif collector.enabled %}
<div class="empty">
<p>There is no security token.</p>
<p>
There is no security token.
{% if collector.deauthProfileToken %}
It was removed in
<a href="{{ path('_profiler', {token: collector.deauthProfileToken, panel: 'security'}) }}">
{{- collector.deauthProfileToken -}}
</a>.
{% endif %}
</p>
</div>
{% endif %}
</div>
Expand Down
Loading