Problem/Motivation

When generating a URL for a form redirection via Url::fromRoute('user.logout') I can see that the code is generating a url with a placeholder token which happens in processOutbound function in RouteProcessorCsrf.php. This happens because the urlGenerator used is MetadataBubblingUrlGenerator.php which always calls generateFromRoute with TRUE for collect_bubbleable_metadata so never uses the real token in the URL. When then using this URl to instruct a form redirect the placeholder token is never replaced with the correct token. I need to be able to just call generateFromRoute from the UrlGenerator.php file but this service is not public so i'm not sure what the solution is here.

Steps to reproduce

$form_state->setRedirectUrl(Url::fromRoute('user.logout'));

You will see it tries and redirects to the url with the placeholder token which is invalid so instead of logging out it will take you out to the logout confirm screen instead as the token is invalid.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

reece.oliver created an issue. See original summary.

reece.oliver’s picture

Issue summary: View changes
reece.oliver’s picture

Issue summary: View changes
quietone’s picture

Version: 10.3.x-dev » 11.x-dev

Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.