-
-
Notifications
You must be signed in to change notification settings - Fork 387
Open
Labels
Description
Scenario
- Enable CSRF in Symfony
- Without being logged in, browse a page with a Symfony form
- Fill the form then submit it
- Go to /login, login normally then go back to the form with your browser and re-submit it
Actual behaviour (without Live component)
- Form error is correctly displayed with HTTP 422 and "Invalid CSRF token" message.
Actual behaviour (with form in a Live component)
- Error 500 is thrown and a popup appears with the exception
Error is thrown here :
ux/src/LiveComponent/src/EventListener/LiveComponentSubscriber.php
Lines 112 to 117 in d993b12
if ( | |
$this->container->has(CsrfTokenManagerInterface::class) | |
&& $metadata->get('csrf') | |
&& !$this->container->get(CsrfTokenManagerInterface::class)->isTokenValid(new CsrfToken(LiveControllerAttributesCreator::getCsrfTokeName($componentName), $request->headers->get('X-CSRF-TOKEN')))) { | |
throw new BadRequestHttpException('Invalid CSRF token.'); | |
} |
This issue occurs because CSRF are reset on each login/logout (which is normal behaviour)
I think we need to find a better way to handle this, since in prod environnements this leads to a 500 error to end users.
nediamnediam