Stealing the users back button with the History API (2013)
ryanseddon.com
ryanseddon.com
It exists primarily to support SPAs that have hard links for different specific resource views but never actually navigate the user off the single page - the History API allows these sites to drop some breadcumbs so that users can return to different visual states they observed on their screen while never actually navigating....
That all said - I think there are much better ways to accomplish this using, I believe (it's been a bit) location.Url updates that cause micro-reloads... however if your webapp is a 300 pound gorilla this approach is significantly less appealing due to the obvious breaks in user flow.
I don't know the solution, but I wish I could get a normal web, and then have a dedicated generic app sandbox that I can point at a particular app on the 'net.
Step 1: Redirect middleware checks for a cookie say 'A'
Step 2: If no cookie, set cookie and redirect to main content.
Step 3: User presses back button, comes to redirect middleware which sees cookie 'A' and this time it redirects to another shady website.
On Chrome based browsers, I see this error -
[Report Only] Refused to load the script 'https://ryanseddon.com/dist/app.bundle.js' because it violates the following Content Security Policy directive: "script-src 'self' 'sha256-MdC6fOvaO+dJENLQhOoRht9sHSJ++GoMxjtC5lOpUww=' 'strict-dynamic' https: 'unsafe-inline' 'report-sample'". 'strict-dynamic' is present, so host-based whitelisting is disabled. Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.1. User goes to example.com.
2. The site immediately replaces the history state with example.com#history.
3. The site pushes a new history state example.com
At this point your history looks like
…
google.com
example.com#history
example.com <— you are here
4. The user clicks their back button and you’re taken to example.com#history5. The JS sees the hash and does a location.replace (i.e. navigate to) to some unrelated URL.
Obviously it can be used intentionally to hijack your session history, but it’s also surprisingly easy to do by mistake unless your state management is effectively designed for concurrency (which the API isn’t, but it encourages the same kinds of bad patterns).