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

Command icon 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

elc created an issue. See original summary.

  • elc committed 412902eb on 3.x
    fix: #3643845 Add tests for the CSRF route exclusion and handle a...

  • elc committed 1dceb4eb on 2.x
    fix: #3643845 Add tests for the CSRF route exclusion and handle a...
elc’s picture

Assigned: elc » Unassigned
Status: Needs work » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.