Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use replaceState for better browser history experience #967

Merged

Conversation

selaux
Copy link
Contributor

@selaux selaux commented Apr 4, 2017

Rationale: Currently, when we get to the login callback, the callback url with and without the hash will be counted as two different browser history entries. This leads to the user not having the possibility to navigate back as the history entry that includes the hash will always trigger the authentication procedure again. Additionally I don't like the idea of tokens appearing in my browser history, because this way an attacker could steal them from there (although they will only be valid for a limited amount of time).

Implementation: Replace window.location.hash = '' with window.history.replaceState( so it will not create an additional history entry, but replace the existing one that includes the hash.

What do you think?

@selaux selaux changed the title Use replaceState so tokens dont show up in browser history Use replaceState for better browser history experience Apr 4, 2017
@luisrudge
Copy link
Contributor

luisrudge commented Apr 4, 2017

I don't see two history entries when I log in on Chrome. 🤔 What browser are you testing?

@selaux
Copy link
Contributor Author

selaux commented Apr 4, 2017

Tested on Firefox and Chrome, but maybe I didn't describe it correctly and maybe this is a special case that we have. I will try to build a minimal example to showcase the issue.

@selaux
Copy link
Contributor Author

selaux commented Apr 4, 2017

Okay, so you can find the minimal example here. You are right, it actually works in Chrome and some other Browsers, but I tested in Firefox and there the issue appears.

Successful Login: Login with '[email protected]' and 'Test1234'

After login it will redirect you to this page.

  • Expected History:
    • Either: Login Page, this page
    • Or: Login Page, Login Callback without hash, this page
    • Or: Login Callback without hash, this page (this is the result in Chrome, IE11)
  • Got: Login Page, Login Callback with hash, Login Callback without hash, this page (tested in Firefox, Safari)

I hope this makes things more clear and you can reproduce.

@luisrudge
Copy link
Contributor

Yeah. Thanks for the PR!

@luisrudge luisrudge added this to the v10-Next milestone Apr 4, 2017
@luisrudge luisrudge merged commit 1539e05 into auth0:master Apr 4, 2017
@selaux
Copy link
Contributor Author

selaux commented Apr 4, 2017

Cool, thank you!

@selaux
Copy link
Contributor Author

selaux commented Apr 4, 2017

Thinking back on it you might also need to consider browser support. E.g. IE9 does not support this, for the browsers we support its ok.

@luisrudge
Copy link
Contributor

I saw that, but we don't support IE9, so that's ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants