The Symfony profiler is the first place to look at when something doesn't work as expected in your application. Symfony 8.2 makes it more useful when debugging authentication and HTTP requests, and easier to use for everybody.
Reasons for Skipped Authenticators
When a firewall has several authenticators, the security panel of the profiler
lists all of them and tells you which ones supported the request. For the ones
that didn't, the panel only said "This authenticator did not support the
request" and you had to find out why: a JSON login request sent without the
right Content-Type header, a login form posted to the wrong path, etc.
In Symfony 8.2, authenticators explain why they skipped the request:
All built-in authenticators give their reasons, and so do the authenticators
that extend AbstractLoginFormAuthenticator. In your own
custom authenticators, add the reason before returning false in the
supports() method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// src/Security/TenantAuthenticator.php
namespace App\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator;
use Symfony\Component\Security\Http\SecurityRequestAttributes;
class TenantAuthenticator extends AbstractAuthenticator
{
public function supports(Request $request): ?bool
{
if (!$request->headers->has('X-Tenant')) {
$request->attributes
->get(SecurityRequestAttributes::UNSUPPORTED_REASONS)
?->add('the "X-Tenant" header is missing');
return false;
}
return true;
}
// ...
}
This request attribute only exists while the profiler is collecting data. In production, the nullsafe operator skips the call, so explaining your authenticators costs nothing.
Reasons for Deauthenticated Users
Symfony reloads the user from the session at the beginning of each request. If the user has changed (e.g. the password or the roles are different), Symfony deauthenticates them. This was hard to debug because the profiler only said "There is no security token."
In Symfony 8.2, the security panel shows who was deauthenticated and why:
The same information is available in the TokenDeauthenticatedEvent, which
now provides the getReason() and getProviderClasses() methods. Use them,
for example, to log unexpected logouts in production:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
// src/EventListener/DeauthenticationLogger.php
namespace App\EventListener;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\Security\Http\Event\TokenDeauthenticatedEvent;
final class DeauthenticationLogger
{
public function __construct(
private LoggerInterface $logger,
) {
}
#[AsEventListener]
public function onTokenDeauthenticated(TokenDeauthenticatedEvent $event): void
{
$this->logger->notice('User "{user}" was deauthenticated because {reason}.', [
'user' => $event->getOriginalToken()->getUserIdentifier(),
// e.g. 'the user has changed'
'reason' => $event->getReason() ?? 'of an unknown reason',
// the user providers that detected the change
'providers' => $event->getProviderClasses(),
]);
}
}
Duration and Size of HTTP Client Requests
When a page is slow because of the HTTP requests that it makes, you need to
know how long each request took and how much data it transferred. The
HttpClient component already collected that information, but the profiler
showed it inside the collapsed info dump of each response.
In Symfony 8.2, each response shows its duration and its transferred sizes
(↑ for the uploaded data and ↓ for the downloaded data) next to the
status code:
The panel and the web debug toolbar also display a new Total time metric, which is the sum of the durations of all requests. Concurrent requests are counted in full, so this value can be higher than the time that your application actually waited for them.
AJAX Requests Made While the Page Loads
The web debug toolbar lists the AJAX requests made by the page, with a link to the profile of each of them. However, the toolbar is injected at the end of the page, so it missed the requests that started before it was ready. This is common in applications whose scripts fetch data while the page is loading:
1 2 3 4 5 6 7
<head>
{# ... #}
<script>
fetch('/api/cart');
fetch('/api/recommendations');
</script>
</head>
In Symfony 8.2, the code that tracks fetch() and XMLHttpRequest calls is
injected before the first script of the page, so the toolbar lists those
early requests too:
This works for regular responses. Streamed responses keep the previous behavior.
Excluding Requests from the Profiler
Some requests are just noise in the profiler: health checks, monitoring probes,
favicon.ico or the /.well-known/... file that Chrome DevTools requests
again and again. Symfony 8.2 adds two options to exclude requests from being
profiled, by their path and by the status code of their response:
1 2 3 4 5 6 7 8 9 10 11
# config/packages/web_profiler.yaml
when@dev:
framework:
profiler:
excluded_paths:
- '^/\.well-known/'
- '^/health$'
excluded_http_codes:
404: ~ # all 404 responses
405: '^/api' # 405 responses under this path
400: ['^/api', '^/webhooks'] # 400 responses under these paths
The paths are regular expressions without delimiters. They are case-sensitive
and matched against the URL-decoded path of the request. Symfony doesn't exclude
any request by default, but the recipe for new applications already excludes
the /.well-known/ and /favicon.ico paths in the dev environment.
Keyboard and Screen Reader Accessible Panels
The profiler is a tool that you use many times a day, so it must be usable by everybody. Symfony 8.2 makes the panels of the profiler accessible with a keyboard and with a screen reader:
- Tabs follow the ARIA tabs pattern: the left and right arrow keys move between tabs, the whole group is a single tab stop and disabled tabs are exposed as unavailable;
- Toggles that only display an icon (such as the chevrons that expand and collapse contents) are now real buttons that you can focus, with an accessible name and their expanded state;
- The field tree of the Forms panel follows the ARIA tree view pattern:
the up and down arrow keys move between fields, the right and left arrow keys
expand and collapse them,
HomeandEndjump to the first and last field, andEnterorSpaceselect a field.
Symfony 8.2 accessibility improvements in action in the Forms panel of the profiler, with the city field of a nested address form focused and selected using only the keyboard: