Currently module using destination service that fired always in \Drupal\masquerade\Controller\SwitchController::getRedirectResponse()
Also module does not properly check that HTTP_REFERER is external

Proposed to create JS destination for masquerade links and use code destination behavior

Comments

andypost created an issue. See original summary.

realgt’s picture

this issue is happening for me as well, when you unmasquerade the redirect takes you back to <front> page instead of previous page (although i don't propose the js destination solution)

realgt’s picture

affects 8.x-2.0-beta4

realgt’s picture

StatusFileSize
new1.03 KB

heres a patch that allowed unmasquerade redirect to function correctly

realgt’s picture

StatusFileSize
new917 bytes

updated patch fixes paths

realgt’s picture

StatusFileSize
new917 bytes

update to remove trailing whitespace

andypost’s picture

From security POV the referrer header is insecure and surely can't be used instead of destination

interdruper’s picture

Status: Active » Needs work

IMHO, src/Controller/SwitchController.php would need a little refactoring. Right now the referer is ignored, since destination always is valid and it contains the url defined in the route 'masquerade.unmasquerade', that is:

/unmasquerade?token=...

If the refererer exists, an additional parameter would be required, that is:

/unmasquerade?token=...&destination=/referer/path

murz’s picture

As an alternative, we can fill "&destination" parameter on /unmasquerade link at frontend via JS, for keep this link cacheable globally, not per-url. And maybe even do this at "onClick" event.

pelicani’s picture

Note : another patch is available that handles this situation really well ...
https://www.drupal.org/project/masquerade/issues/3158235
this patch handles the referrer without adding a destination to the url.

solideogloria’s picture

Status: Needs work » Closed (duplicate)

Closing as a duplicate of the other issue.

#3158235: MasqueradeBlock & getRedirectResponse improvements

Patch #4 of the linked issue works nicely.