Skip to content

Commit 481343e

Browse files
committed
Merge PR rails#41769
2 parents ff6484b + 1f4714c commit 481343e

File tree

8 files changed

+60
-7
lines changed

8 files changed

+60
-7
lines changed

actionpack/test/controller/base_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def test_response_has_default_headers
133133
ActionDispatch::Response.default_headers = {
134134
"X-Frame-Options" => "DENY",
135135
"X-Content-Type-Options" => "nosniff",
136-
"X-XSS-Protection" => "1;"
136+
"X-XSS-Protection" => "0"
137137
}
138138

139139
response_headers = SimpleController.action("hello").call(

actionpack/test/controller/metal_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_response_does_not_have_default_headers
1515
ActionDispatch::Response.default_headers = {
1616
"X-Frame-Options" => "DENY",
1717
"X-Content-Type-Options" => "nosniff",
18-
"X-XSS-Protection" => "1;"
18+
"X-XSS-Protection" => "0"
1919
}
2020

2121
response_headers = SimpleController.action("hello").call(

actionpack/test/dispatch/response_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def test_only_set_charset_still_defaults_to_text_html
339339
ActionDispatch::Response.default_headers = {
340340
"X-Frame-Options" => "DENY",
341341
"X-Content-Type-Options" => "nosniff",
342-
"X-XSS-Protection" => "1;",
342+
"X-XSS-Protection" => "0",
343343
"X-Download-Options" => "noopen",
344344
"X-Permitted-Cross-Domain-Policies" => "none",
345345
"Referrer-Policy" => "strict-origin-when-cross-origin"
@@ -351,7 +351,7 @@ def test_only_set_charset_still_defaults_to_text_html
351351

352352
assert_equal("DENY", resp.headers["X-Frame-Options"])
353353
assert_equal("nosniff", resp.headers["X-Content-Type-Options"])
354-
assert_equal("1;", resp.headers["X-XSS-Protection"])
354+
assert_equal("0", resp.headers["X-XSS-Protection"])
355355
assert_equal("noopen", resp.headers["X-Download-Options"])
356356
assert_equal("none", resp.headers["X-Permitted-Cross-Domain-Policies"])
357357
assert_equal("strict-origin-when-cross-origin", resp.headers["Referrer-Policy"])

guides/source/configuring.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,16 @@ Accepts a string for the HTML tag used to wrap attachments. Defaults to `"action
17381738
- `config.active_record.partial_inserts`: `false`
17391739
- `config.active_storage.variant_processor`: `:vips`
17401740
- `config.action_controller.wrap_parameters_by_default`: `true`
1741+
- `config.action_dispatch.default_headers`:
1742+
1743+
{
1744+
"X-Frame-Options" => "SAMEORIGIN",
1745+
"X-XSS-Protection" => "0",
1746+
"X-Content-Type-Options" => "nosniff",
1747+
"X-Download-Options" => "noopen",
1748+
"X-Permitted-Cross-Domain-Policies" => "none",
1749+
"Referrer-Policy" => "strict-origin-when-cross-origin"
1750+
}
17411751

17421752
#### For '6.1', defaults from previous versions below and:
17431753

@@ -1822,6 +1832,16 @@ Accepts a string for the HTML tag used to wrap attachments. Defaults to `"action
18221832
- `config.active_storage.video_preview_arguments`: `"-y -vframes 1 -f image2"`
18231833
- `config.active_storage.variant_processor`: `:mini_magick`
18241834
- `config.action_controller.wrap_parameters_by_default`: `false`
1835+
- `config.action_dispatch.default_headers`:
1836+
1837+
{
1838+
"X-Frame-Options" => "SAMEORIGIN",
1839+
"X-XSS-Protection" => "1; mode=block",
1840+
"X-Content-Type-Options" => "nosniff",
1841+
"X-Download-Options" => "noopen",
1842+
"X-Permitted-Cross-Domain-Policies" => "none",
1843+
"Referrer-Policy" => "strict-origin-when-cross-origin"
1844+
}
18251845

18261846
### Configuring a Database
18271847

guides/source/security.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ Every HTTP response from your Rails application receives the following default s
10361036
```ruby
10371037
config.action_dispatch.default_headers = {
10381038
'X-Frame-Options' => 'SAMEORIGIN',
1039-
'X-XSS-Protection' => '1; mode=block',
1039+
'X-XSS-Protection' => '0',
10401040
'X-Content-Type-Options' => 'nosniff',
10411041
'X-Download-Options' => 'noopen',
10421042
'X-Permitted-Cross-Domain-Policies' => 'none',
@@ -1062,7 +1062,7 @@ config.action_dispatch.default_headers.clear
10621062
Here is a list of common headers:
10631063

10641064
* **X-Frame-Options:** _`SAMEORIGIN` in Rails by default_ - allow framing on same domain. Set it to 'DENY' to deny framing at all or remove this header completely if you want to allow framing on all websites.
1065-
* **X-XSS-Protection:** _`1; mode=block` in Rails by default_ - use XSS Auditor and block page if XSS attack is detected. Set it to '0;' if you want to switch XSS Auditor off(useful if response contents scripts from request parameters)
1065+
* **X-XSS-Protection:** _`0` in Rails by default_ - [deprecated legacy header](https://owasp.org/www-project-secure-headers/#x-xss-protection), set to '0' to disable problematic legacy XSS auditors.
10661066
* **X-Content-Type-Options:** _`nosniff` in Rails by default_ - stops the browser from guessing the MIME type of a file.
10671067
* **X-Content-Security-Policy:** [A powerful mechanism for controlling which sites certain content types can be loaded from](https://w3c.github.io/webappsec-csp/)
10681068
* **Access-Control-Allow-Origin:** Used to control which sites are allowed to bypass same origin policies and send cross-origin requests.

railties/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
* Change default `X-XSS-Protection` header to disable XSS auditor
2+
3+
This header has been deprecated and the XSS auditor it triggered
4+
has been removed from all major modern browsers (in favour of
5+
Content Security Policy) that implemented this header to begin with
6+
(Firefox never did).
7+
8+
[OWASP](https://owasp.org/www-project-secure-headers/#x-xss-protection)
9+
suggests setting this header to '0' to disable the default behaviour
10+
on old browsers as it can introduce additional security issues.
11+
12+
Added the new behaviour as a framework default from Rails 7.0.
13+
14+
*Christian Sutter*
15+
116
* Scaffolds now use date_field, time_field and datetime_field instead of
217
date_select, time_select and datetime_select; thus providing native date/time pickers.
318

railties/lib/rails/application/configuration.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ def load_defaults(target_version)
198198
load_defaults "6.1"
199199

200200
if respond_to?(:action_dispatch)
201+
action_dispatch.default_headers = {
202+
"X-Frame-Options" => "SAMEORIGIN",
203+
"X-XSS-Protection" => "0",
204+
"X-Content-Type-Options" => "nosniff",
205+
"X-Download-Options" => "noopen",
206+
"X-Permitted-Cross-Domain-Policies" => "none",
207+
"Referrer-Policy" => "strict-origin-when-cross-origin"
208+
}
201209
action_dispatch.return_only_request_media_type_on_content_type = false
202210
action_dispatch.cookies_serializer = :json
203211
end

railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults_7_0.rb.tt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,15 @@
107107
# `String` to `Digest::UUID.uuid_v3` or `Digest::UUID.uuid_v5` method calls.
108108
#
109109
# See https://guides.rubyonrails.org/configuring.html#config-active-support-use-rfc4122-namespaced-uuids for
110-
# more information
110+
# more information.
111111
# Rails.application.config.active_support.use_rfc4122_namespaced_uuids = true
112+
113+
# Change the default headers to disable browsers' flawed legacy XSS protection.
114+
# Rails.application.config.action_dispatch.default_headers = {
115+
# "X-Frame-Options" => "SAMEORIGIN",
116+
# "X-XSS-Protection" => "0",
117+
# "X-Content-Type-Options" => "nosniff",
118+
# "X-Download-Options" => "noopen",
119+
# "X-Permitted-Cross-Domain-Policies" => "none",
120+
# "Referrer-Policy" => "strict-origin-when-cross-origin"
121+
# }

0 commit comments

Comments
 (0)