Skip to content

Commit c11414b

Browse files
committed
Fix JWTEventListener cookie name resolution crashing on invalid dummy token
Call createCookie with a valid JWT placeholder at construction time and cache the cookie name, rather than calling createCookie('x') on every response (which throws because 'x' is not a valid JWT format in newer lexik versions).
1 parent 9a1ca3d commit c11414b

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/EventListener/Jwt/JWTEventListener.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
final class JWTEventListener implements ResetInterface
3030
{
3131
private ?string $token = null;
32+
private readonly string $jwtCookieName;
3233

3334
public function __construct(
3435
private readonly RoleHierarchy $roleHierarchy,
3536
private readonly JWTCookieProvider $cookieProvider,
3637
private readonly MercureAuthorization $mercureAuthorization,
3738
private readonly ?CwaCollectorData $collectorData = null,
3839
) {
40+
$this->jwtCookieName = $cookieProvider->createCookie('header.payload.signature')->getName();
3941
}
4042

4143
public function onJWTAuthenticationSuccess(AuthenticationSuccessEvent $event): void
@@ -78,9 +80,8 @@ public function onKernelResponse(ResponseEvent $event): void
7880

7981
// Record whether a JWT cookie was present on the incoming request
8082
$request = $event->getRequest();
81-
$cookieName = $this->cookieProvider->createCookie('x')->getName();
82-
if ($request->cookies->has($cookieName)) {
83-
$this->collectorData?->recordJwtCookiePresent($cookieName);
83+
if ($request->cookies->has($this->jwtCookieName)) {
84+
$this->collectorData?->recordJwtCookiePresent($this->jwtCookieName);
8485
}
8586

8687
if (!empty($token)) {

0 commit comments

Comments
 (0)