sillsdev / languageforge-lexbox

Lexbox, SIL linguistic data hub
MIT License
7 stars 2 forks source link

if you log out you can click the back button and see the previous logged in page #1258

Closed hahn-kev closed 5 hours ago

hahn-kev commented 1 day ago

Describe the bug When you log out your local cache should be cleared and clicking back should not be able to take you to a page with sensitive data

To Reproduce

  1. login as admin
  2. be on the admin dashboard (page probably doesn't matter)
  3. log out
  4. from the login page, click the browser back button
  5. you can see the admin dashboard again even though you should be logged out

Expected behavior trying to go back should just redirect you back to the login page. Additionally we should figure out where the data is coming from that is being displayed when you go back as the cache should have also been cleared.

myieye commented 1 day ago

The browser is simply pulling things out of its cache.

We clear the GQL cache and invalidate SvelteKit stuff (by simply doing a full page load), but we never clear the browser cache, because we can't.

So, I think the only bullet-proof way to handle this is to disable the browser cache (for relevant requests) e.g.:

response.headers.set('Cache-Control', 'no-store, no-cache, must-revalidate, private');
response.headers.set('Pragma', 'no-cache');
response.headers.set('Expires', '0');

Any other solution will have holes, but they might still be worth considering E.g.:

  1. On logout, we could explicitly set the cookie in the browser to something (e.g. "INVALID") and check for that value on authenticated pages, redirecting back to the login if we detect it.
  2. We could play with browser history, so that the back button doesn't work (e.g. insert an item that always redirects to the login) but that's sort of pointless, because the back button isn't the only way to navigate browser history.
hahn-kev commented 1 day ago

I wonder if we can just store something in memory and when they navigate back we should receive a navigate event which we can react to. But maybe that's over designing it.

myieye commented 1 day ago

Actually, I just found the right header to tell the browser to clear its cache: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Clear-Site-Data#browser_compatibility

I'm pretty sure it's exactly what we want