Skip to content

Commit 40b25fd

Browse files
David Heinemeier Hanssonkamipo
andauthored
Suggest a CSP that's compatible with Turbo + import map (rails#43227)
* Suggest a CSP that's compatible with Turbo + import map Need to have session-based nonces for that. * Update railties/lib/rails/generators/rails/app/templates/config/initializers/content_security_policy.rb.tt Co-authored-by: Ryuta Kamizono <[email protected]> * Update content_security_policy.rb.tt Co-authored-by: Ryuta Kamizono <[email protected]>
1 parent eda60f2 commit 40b25fd

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,23 @@
44
# For further information see the following documentation
55
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
66

7-
# Rails.application.config.content_security_policy do |policy|
8-
# policy.default_src :self, :https
9-
# policy.font_src :self, :https, :data
10-
# policy.img_src :self, :https, :data
11-
# policy.object_src :none
12-
# policy.script_src :self, :https
13-
# policy.style_src :self, :https
14-
# # Specify URI for violation reports
15-
# # policy.report_uri "/csp-violation-report-endpoint"
7+
# Rails.application.configure do
8+
# config.content_security_policy do |policy|
9+
# policy.default_src :self, :https
10+
# policy.font_src :self, :https, :data
11+
# policy.img_src :self, :https, :data
12+
# policy.object_src :none
13+
# policy.script_src :self, :https
14+
# policy.style_src :self, :https
15+
# # Specify URI for violation reports
16+
# # policy.report_uri "/csp-violation-report-endpoint"
17+
# end
18+
#
19+
# # Generate session nonces for permitted importmap and inline scripts
20+
# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
21+
# config.content_security_policy_nonce_directives = %w(script-src)
22+
#
23+
# # Report CSP violations to a specified URI. See:
24+
# # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
25+
# # config.content_security_policy_report_only = true
1626
# end
17-
18-
# If you are using UJS then enable automatic nonce generation
19-
# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
20-
21-
# Set the nonce only to specific directives
22-
# Rails.application.config.content_security_policy_nonce_directives = %w(script-src)
23-
24-
# Report CSP violations to a specified URI
25-
# For further information see the following documentation:
26-
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
27-
# Rails.application.config.content_security_policy_report_only = true

0 commit comments

Comments
 (0)