Problem/Motivation
On a project using the module, users are sometimes loosing the destination parameter during the course of the 'email_tfa_email_tfa_verify_login'.
So far, my undersanding is that it is related to Lines 160 and 162 of email_tfa\src\Form\EmailTfaVerifyLoginForm.php
// save the destination in the $form_state to be used on submit.
$form_state->set('destination', $this->getRequest()->query->get('destination'));
// remove the destination from the query string.
$this->getRequest()->query->remove('destination');
The first part doesn't seem to work in some cases :
$form_state->set('destination', $this->getRequest()->query->get('destination'));
So the second, removing the destination, is actually killing it.
Is removing the query string obligatory ?
Also L 262 :
$form_state->setRedirect(
'entity.user.canonical',
['user' => $user->id()]
);
Why redirecting to the user profile if there are no destination ?
Some projects don't exploit much the user profile page. The frontpage would be a more relevant option in IMHO.
I would say that more people would want to land on the frontpage instead of the profile page after signing in.
Steps to reproduce
I've not yet clearly identified the reason why in some cases "$form_state->set('destination', $this->getRequest()->query->get('destination'));" doens't seem to apply.
Proposed resolution
Avoid removing the query string :
// $this->getRequest()->query->remove('destination');
And in the submitForm changing the Redirect to the frontpage.
Remaining tasks
If you agree with these changes, I can provide a patch.
User interface changes
none
API changes
none
Data model changes
none
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | email_tfa-3620695-403-post-destination.patch | 1.46 KB | dalin |
Issue fork email_tfa-3620695
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 #2
tritof commentedComment #3
tritof commentedComment #4
tritof commentedComment #6
dalinFound the root cause — the destination is only ever read from the query string, but in the 403 login flow it arrives in the POST body.
Steps to reproduce (any site where the 403 page is set to /user/login, TFA enabled for the account):
actionis the denied URL itself.DefaultExceptionHtmlSubscriber::makeSubrequest()adds the destination to the POST parameters of the sub-request ($sub_request->isMethod('GET') ? $sub_request->query : $sub_request->request) — not the query string.EmailTfaLoginForm::buildForm()only checks$this->getRequest()->query->get('destination'), so the destination is silently dropped and after entering the email code you land on/user/{uid}instead of the page you were originally denied on./user/login?destination=...work fine, which is why this looks intermittent: it only breaks when the login form is reached through a 403.Fix:
buildForm()should read the destination from either bag:and stash it in
$form_stateas before. Everything downstream (the verify-form redirect and the final RedirectResponseSubscriber handling) already works once the destination survives that first hop.Patch attached (email_tfa-3620695-403-post-destination.patch, applies to 2.0.7), verified end-to-end against a scripted login flow.
NOTE: I did not change the fallback destination to
<front>. This is a problem with just Core even without this module. If you don't want this you can fix with a simple alter hook or redirect. If we do want to fix it should be in a separate issue to add a config UI for it.Comment #8
abdulaziz zaidThanks, @dalin! Tested on Drupal 11 and confirmed the fix works. Committed to 3.0.x.