Skip to content

Add return_to behaviour to 404 -> login flow - #4916

Merged
ukutaht merged 16 commits into
masterfrom
return_to
Jan 14, 2025
Merged

ukutaht merged 16 commits into
masterfrom
return_to

Conversation

@ukutaht

@ukutaht ukutaht commented Dec 17, 2024

Copy link
Copy Markdown
Contributor

Changes

It's quite annoying at the moment to:

  1. Receive a link to a dashboard (maybe with filters)
  2. Get 404
  3. Go to login
  4. Enter credentials
  5. Be redirected to /sites instead of the original link

This PR implements a return_to query param used in login flow, including when 2fa challenge is presented. This way the user lands on the intended page.

We currently have a session-based login_dest variable but it only works for known routes which dashboards are not. It could have been extended for this use-case but I felt like using query params is better when session state isn't strictly necessary.

@ukutaht
ukutaht requested review from a team, aerosol and zoldar December 17, 2024 14:54
@zoldar zoldar added the preview label Dec 18, 2024
@github-actions

Copy link
Copy Markdown
Preview environment👷🏼‍♀️🏗️
PR-4916

@zoldar zoldar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - left some minor suggestions. Before the final 🦭 I'll take it for a short spin on preview app though.

@apata apata left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ukutaht I'm a bit concerned that as-is this can be used to craft malicious links.
https://pr-4916.review.plausible.io/login?return_to=https:%2F%2Fexample.com%2Fhack%2Fplausible.io
If on the return URL is a copy of the Plausible login page, the user may naively enter their details again, inadvertently sharing their details with a hacker.

@zoldar

zoldar commented Dec 18, 2024

Copy link
Copy Markdown
Contributor

@apata good point. The return_to URL could be sanitized before final redirect, scraping any with non-matching host part.

@ukutaht

ukutaht commented Dec 18, 2024

Copy link
Copy Markdown
Contributor Author

I'm a bit concerned that as-is this can be used to craft malicious links.

Thanks, that's a good point! I've taken a stab at it here. A few points about this commit:

  • It changes the Phoenix.Controller.redirect function call to use to: argument over external: which only allows local redirects
  • When an external URL is provided to redirect it will crash with a 500. Should be rare but still bad UX that I wanted to avoid. So I added a small validation our side as well which will ignore return_to unless it starts with a "/"
  • Note that it's still possible to craft a malicious URL that starts with a double slash "//", and in that case we will 500 but I don't expect this to happen often if at all
  • @zoldar is there any reason we've been using external over `to? I'm not sure why we would need to redirect to an external URL here...

@apata
apata self-requested a review December 19, 2024 08:29
@zoldar

zoldar commented Dec 19, 2024

Copy link
Copy Markdown
Contributor

@ukutaht

Ad 5. this was originally a workaround for issue with internal redirects failing when there's a url encoded UTF8 character in the path (the domain of the site, in particular): #3560 - phoenix was validating the "to" URLs a bit overzealously. The phoenix version we currently are on (1.7.14) has this behavior changed via phoenixframework/phoenix@4ca6ca2. This should no longer be an issue and we should be able to get back to using internal "to" redirects.

@apata

apata commented Dec 19, 2024 •

Copy link
Copy Markdown
Contributor

I'm happy with that, @ukutaht! But because this feature allows redirecting to a page that has itself url search params (https://pr-4916.review.plausible.io/login?return_to=/sites%3Ffoo%3Dbar), any other open redirect vulnerability that we might have would still be exploitable. Before we release it, we should double check that we don't have any.

Edit: From my side, I couldn't find any other redirects that take user input.

@ukutaht

ukutaht commented Dec 30, 2024

Copy link
Copy Markdown
Contributor Author

Thanks both @zoldar @apata. If it's good to go from your side @apata please change your review to approved so this can be merged :)

@apata

apata commented Jan 2, 2025

Copy link
Copy Markdown
Contributor

Sorry for the wait, @ukutaht! I think I was actually expecting to see a fix on the failing CI checks, but then I forgot about the whole thing for the holidays.

@ukutaht
ukutaht added this pull request to the merge queue Jan 14, 2025
Merged via the queue into master with commit 6833fd5 Jan 14, 2025
@ukutaht
ukutaht deleted the return_to branch January 14, 2025 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants