Skip to content

Commit 9c92e62

Browse files
committed
Use config.load_defaults for rails 7 with overrides
https://github.com/rails/rails/blob/d437ae311f1b9dc40b442e40eb602e020cec4e49/railties/lib/rails/application/configuration.rb#L92 * belongs_to_required_by_default must be overridden or seeding fails * Partial inserts cause test failures in ui-classic, content, and amazon provider * Once we remove unsafe-inline, then we can set this to the default, 0. Since we still use unsafe-inline, we still use X-XSS-Protection. * Allow deprecations to be found and fixed Fixes #23172
1 parent 932afa7 commit 9c92e62

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

config/application.rb

+21-2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ class Application < Rails::Application
8686

8787
# Disable ActionCable's request forgery protection
8888
# This is basically matching a set of allowed origins which is not good for us
89+
# Note, similarly named forgery protections in action controller are set to true
90+
# https://github.com/rails/rails/blob/d437ae311f1b9dc40b442e40eb602e020cec4e49/railties/lib/rails/application/configuration.rb#L115C12-L115C69
91+
# 5.0 sets: action_controller.forgery_protection_origin_check = true
92+
# 5.2 sets: action_controller.default_protect_from_forgery = true
8993
config.action_cable.disable_request_forgery_protection = false
9094
# Matching the origin against the HOST header is much more convenient
9195
config.action_cable.allow_same_origin_as_host = true
@@ -106,8 +110,23 @@ class Application < Rails::Application
106110

107111
config.autoload_paths += config.eager_load_paths
108112

109-
# config.load_defaults 6.1
110-
# Disable defaults as ActiveRecord::Base.belongs_to_required_by_default = true causes MiqRegion.seed to fail validation on belongs_to maintenance zone
113+
# FYI, this is where load_defaults is defined as of 7.2:
114+
# https://github.com/rails/rails/blob/d437ae311f1b9dc40b442e40eb602e020cec4e49/railties/lib/rails/application/configuration.rb#L92
115+
config.load_defaults 7.0
116+
117+
# TODO: this is the only change we had from defaults in 7.0. See secure_headers.rb. It's 0 in defaults.
118+
config.action_dispatch.default_headers["X-XSS-Protection"] = "1; mode=block"
119+
120+
# TODO: Find and fixed any deprecated behavior. Opt in later.
121+
config.active_support.remove_deprecated_time_with_zone_name = false
122+
config.active_support.disable_to_s_conversion = false
123+
124+
# TODO: If disabled, causes cross repo test failures in content, ui-classic and amazon provider
125+
config.active_record.partial_inserts = true
126+
127+
# Disable this setting as it causes MiqRegion.seed to fail validation on belongs_to maintenance zone.
128+
# TODO: We should fix this so we don't need to carry this override.
129+
config.active_record.belongs_to_required_by_default = false
111130

112131
# NOTE: If you are going to make changes to autoload_paths, please make
113132
# sure they are all strings. Rails will push these paths into the

config/initializers/secure_headers.rb

+9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
config.x_content_type_options = "nosniff"
1111
# X-XSS-Protection
1212
# X-Permitted-Cross-Domain-Policies
13+
14+
# TODO: This was deprecated and disabled in rails 7. Using content security policy is the desired behavior going forward:
15+
# https://github.com/rails/rails/commit/1f4714c3f798df227222f531141880b8e1b4170a
16+
# https://github.com/rails/rails/blob/d437ae311f1b9dc40b442e40eb602e020cec4e49/railties/lib/rails/application/configuration.rb#L227
17+
# Once we remove unsafe-inline, then we can set this to the default, 0. Since we still use unsafe-inline, we still use X-XSS-Protection.
18+
# From: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection
19+
# "The HTTP X-XSS-Protection response header was a feature of Internet Explorer, Chrome and Safari that stopped pages from loading when
20+
# they detected reflected cross-site scripting (XSS) attacks. These protections are largely unnecessary in modern browsers when sites
21+
# implement a strong Content-Security-Policy that disables the use of inline JavaScript ('unsafe-inline')."
1322
config.x_xss_protection = "1; mode=block"
1423
config.referrer_policy = "no-referrer-when-downgrade"
1524
# Content-Security-Policy

0 commit comments

Comments
 (0)