Problem/Motivation
The changes made in issue https://www.drupal.org/project/drupal/issues/144538 do not work quite correctly.
When creating a logout link, the token parameter is always outdated. Even if it is changed from the default using $this->csrfToken->get('user/logout'), in $this->csrfToken->validate($request->query->get('token', '') , $path) we always get false because $seed = $this->sessionMetadata->getCsrfTokenSeed() constantly returns different values for every request and at the time of checking the token from the link is already out of date. We always get a confirmation form to log out.
Steps to reproduce
Use the debugger to check for $seed values from CsrfAccessCheck->access (line 65) CsrfTokenGenerator->validate $seed from line 85 on multiple page reloads. For example, it can be clicking the logout button on the main page.
Comments
Comment #2
cilefen commentedI don't understand whether this bug report is about Drupal Core unaltered or with custom code. If there is custom code, could you please share bug reproduction code?
Have you have called
\Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoutewithuser.logoutto generate the link?Comment #3
pifagorThe custom code just preparing the link for logout.
"Have you have called \Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute with user.logout" - yes, but as I wrote before, the token is regenerated constantly, and despite using generateFromRoute, it is constantly out of date in csrfToken->validate.
Comment #4
cilefen commentedI am moving this to the development branch in case there is a merge request.
Can you author a failing test for this?
Comment #5
catch@pifagor in what kind of context is the link being rendered? This sounds like a render caching issue.
CSRF tokens are rendered via a placeholder/lazy builder
(see
from RouteProcessorCsrf
However, if the placeholder rendering itself gets cached somehow, or is used in a different context like e-mail, then you end up with invalid CSRF links.