Skip to content

Commit 40d0cb0

Browse files
committed
Destroying a session clears the browser cache for the site
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
1 parent e7c0592 commit 40d0cb0

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

railties/lib/rails/generators/rails/authentication/templates/app/controllers/concerns/authentication.rb.tt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@ module Authentication
4949
Current.session.destroy
5050
cookies.delete(:session_id)
5151
end
52+
53+
def clear_site_data
54+
response.headers["Clear-Site-Data"] = '"cache","storage"'
55+
end
5256
end

railties/lib/rails/generators/rails/authentication/templates/app/controllers/sessions_controller.rb.tt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class SessionsController < ApplicationController
1616

1717
def destroy
1818
terminate_session
19+
clear_site_data
1920
redirect_to new_session_path
2021
end
2122
end

0 commit comments

Comments
 (0)