Skip to content

Commit

Permalink
Remove X-Download-Options default header
Browse files Browse the repository at this point in the history
Since X-Download-Options header is only used by the soon deprecated Internet Explorer, it makes sense to remove this header as a default one.
  • Loading branch information
sabljak committed Jan 6, 2022
1 parent a8d088f commit 486be06
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
4 changes: 1 addition & 3 deletions actionpack/test/dispatch/response_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,13 @@ def test_only_set_charset_still_defaults_to_text_html
end
end

test "read x_frame_options, x_content_type_options, x_xss_protection, x_download_options and x_permitted_cross_domain_policies, referrer_policy" do
test "read x_frame_options, x_content_type_options, x_xss_protection, x_permitted_cross_domain_policies and referrer_policy" do
original_default_headers = ActionDispatch::Response.default_headers
begin
ActionDispatch::Response.default_headers = {
"X-Frame-Options" => "DENY",
"X-Content-Type-Options" => "nosniff",
"X-XSS-Protection" => "0",
"X-Download-Options" => "noopen",
"X-Permitted-Cross-Domain-Policies" => "none",
"Referrer-Policy" => "strict-origin-when-cross-origin"
}
Expand All @@ -352,7 +351,6 @@ def test_only_set_charset_still_defaults_to_text_html
assert_equal("DENY", resp.headers["X-Frame-Options"])
assert_equal("nosniff", resp.headers["X-Content-Type-Options"])
assert_equal("0", resp.headers["X-XSS-Protection"])
assert_equal("noopen", resp.headers["X-Download-Options"])
assert_equal("none", resp.headers["X-Permitted-Cross-Domain-Policies"])
assert_equal("strict-origin-when-cross-origin", resp.headers["Referrer-Policy"])
ensure
Expand Down
1 change: 0 additions & 1 deletion guides/source/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,6 @@ config.action_dispatch.default_headers = {
'X-Frame-Options' => 'SAMEORIGIN',
'X-XSS-Protection' => '0',
'X-Content-Type-Options' => 'nosniff',
'X-Download-Options' => 'noopen',
'X-Permitted-Cross-Domain-Policies' => 'none',
'Referrer-Policy' => 'strict-origin-when-cross-origin'
}
Expand Down
6 changes: 6 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
* Remove default `X-Download-Options` header

This header is currently only used by Internet Explorer which
will be discontinued in 2022 and since Rails 7 does not fully
support Internet Explorer this header should not be a default one.

*Harun Sabljaković*

Please check [7-0-stable](https://github.com/rails/rails/blob/7-0-stable/railties/CHANGELOG.md) for previous changes.
10 changes: 10 additions & 0 deletions railties/lib/rails/application/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,16 @@ def load_defaults(target_version)
end
when "7.1"
load_defaults "7.0"

if respond_to?(:action_dispatch)
action_dispatch.default_headers = {
"X-Frame-Options" => "SAMEORIGIN",
"X-XSS-Protection" => "0",
"X-Content-Type-Options" => "nosniff",
"X-Permitted-Cross-Domain-Policies" => "none",
"Referrer-Policy" => "strict-origin-when-cross-origin"
}
end
else
raise "Unknown version #{target_version.to_s.inspect}"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@
#
# Read the Guide for Upgrading Ruby on Rails for more info on each option.
# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html

# Remove the default X-Download-Options headers since it is used only by Internet Explorer.
# If you need to support Internet Explorer, add back `"X-Download-Options" => "noopen"`.
# Rails.application.config.action_dispatch.default_headers = {
# "X-Frame-Options" => "SAMEORIGIN",
# "X-XSS-Protection" => "0",
# "X-Content-Type-Options" => "nosniff",
# "X-Permitted-Cross-Domain-Policies" => "none",
# "Referrer-Policy" => "strict-origin-when-cross-origin"
# }

0 comments on commit 486be06

Please sign in to comment.