Problem/Motivation
#3483281: User logout without CSRF token redirect to 404 skips the 404 conversion for routes handled by CsrfExceptionSubscriber, and that situation is not covered by functional tests.
The check calls hasRequirement() on the route object. RouteMatch::getRouteObject() can return NULL, which causes "Call to a member function hasRequirement() on null". Core's CsrfExceptionSubscriber::on403() checks for a NULL route first.
3.x already has the NULL check, but neither branch has tests for it.
Steps to reproduce
Run the event subscriber with an access denied exception and a route match that has no route object. A fatal error is thrown.
Proposed resolution
- Add a functional test. A logged in user requests /user/logout without a CSRF token. The test checks for a redirect to the logout confirm form. It also checks that other pages under /user still return 404.
- Return early only when a route exists and has the CSRF requirement and option.
- Add a unit test case for a missing route.
Remaining tasks
- Patch
- Review
- Merge
User interface changes
None
API changes
None
Data model changes
None
Generated with the help of an LLM.
Issue fork m4032404-3643845
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #6
elc commented