An invalid or already used one-time login link counts as a skipped TFA setup

Validate the one-time login link in TfaOneTimeLoginEventSubscriber::redirectOneTimeLogin() before the branches for accounts without TFA set up and for login plugins. Like core, refuse a link that reached the time out also when the account never logged in. A link that core refuses then no longer counts as a skipped TFA setup and no longer shows "You have logged in on a trusted system."

testInvalidOneTimeLoginLinkDoesNotCountAsSkip() opens an invalid link as often as skipping is allowed, then expects a valid link to log the user in with 2 attempts left and the next one with 1. testInvalidOneTimeLoginLinkWithLoginPlugin() expects an invalid link not to reach the login plugin, and a valid link to still log in through it. Both fail without the fix and pass with it on Drupal 10.6.22 and 11.4.13.

In TfaOneTimeLoginEventSubscriberTest, four tests now use a valid link, because the branches they test run after the link check, and the request time moves inside the time out of the default link. The data set for an account that never logged in now expects an expired link to be refused.

On Drupal 11.4, TfaOneTimeLoginEventSubscriberTest already errors on 2.x in four data sets of testLinkValidationLogic() (pipeline 969670), because user_pass_rehash() needs the OneTimeAuthentication service there. With this change, the four tests above and three of those data sets reach that call and error the same way. The data set for an expired link of an account that never logged in passes, because the link is refused before that call. On Drupal 10.6.22 the class passes.

Closes #3642275

AI disclosure: This contribution was human-driven, AI-assisted and human-reviewed.

Merge request reports

Loading
Loading