Skip to content

Commit fd3ec9a

Browse files
flavorjonesmrpasquini
authored andcommitted
Authentication generator controller clears browser cache at logout
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 after logging out. [^1]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Clear-Site-Data
1 parent 5f1b41d commit fd3ec9a

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

railties/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
* The authentication generator's `SessionsController` sets the `Clear-Site-Data` header on logout.
2+
3+
By default the header will be set to `"cache","storage"` to help prevent data leakage after
4+
logout via the browser's "back/forward cache".
5+
6+
*Mike Dalessio*
7+
18
* Introduce `RAILS_MASTER_KEY` placeholder in generated ci.yml files
29

310
*Steve Polito*

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

+4
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

+1
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)