Skip to content

Commit

Permalink
Destroying a session clears the browser cache for the site
Browse files Browse the repository at this point in the history
The "Clear-Site-Data" header[^1] is supported in most modern browsers,
and sending it when a user signs out prevents the browser from
displaying cached pages when a user hits the "back" button.

This helps prevent exposure of data if a user logs in to a site on a
public computer, for example.

[^1]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Clear-Site-Data
  • Loading branch information
flavorjones committed Jan 13, 2025
1 parent e7c0592 commit 40d0cb0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ module Authentication
Current.session.destroy
cookies.delete(:session_id)
end

def clear_site_data
response.headers["Clear-Site-Data"] = '"cache","storage"'
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SessionsController < ApplicationController

def destroy
terminate_session
clear_site_data
redirect_to new_session_path
end
end

0 comments on commit 40d0cb0

Please sign in to comment.