3

I've made a web app that stores persistent user data in localStorage. I've enabled HTTPS on my site, and I'd really like to flip the switch on HSTS. However, as far as I can tell, localStorage considers http://example.com and https://example.com to be different, so if existing users are redirected to the HTTPS version of my site, they can no longer access their data (though it still exists).

Long term, I want to build a new version of this app that offers more options for data storage. But in the short term, all I can think of is having a transition period where users at the http version are asked to migrate their data via some other (unknown) mechanism that both versions can access.

Is this a fair assessment of my options? Is there a way for https://example.com to access the localStorage of http://example.com? If not, is there anywhere I can put user data such that both versions can access it but other sites can't? Or should I ask them to download their data and re-upload it? That doesn't see ideal from a UX or (user) security standpoint.

Note that this web app doesn't interact with a server at all; everything happens with localStorage and the client.

jimjamslam
  • 1,988
  • 1
  • 18
  • 32

1 Answers1

1

Unfortunately there does not seem to be any way to directly retrieve localStorage contents for the less secure http copy of the site from the https site. reference

The workaround I have seen is to use an iframe loading a special page on the insecure site similar to this answer. The general theory is to have code in the iframe that sends messages using postMessage with localStorage data back to the secure page.

Unfortunately this approach does not allow you to disable http entirely, because otherwise your iframed http copy would not load.

Mobius
  • 2,871
  • 1
  • 19
  • 29
  • Mmmm, yeah. It seems like I could keep HSTS off for a while, hide the usual interface for HTTP users and have a button for them to populate HTTPS storage this way before transferring over with an 'update your bookmarks' sort of deal. Thanks! – jimjamslam Oct 01 '17 at 04:39