forked from ledermann/pingcrm
-
Notifications
You must be signed in to change notification settings - Fork 9
/
content_security_policy.rb
44 lines (34 loc) · 1.72 KB
/
content_security_policy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Be sure to restart your server when you modify this file.
# Define an application-wide content security policy
# For further information see the following documentation
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
Rails.application.config.content_security_policy do |policy|
policy.default_src :none
policy.font_src :self
policy.img_src :self, :data
policy.object_src :none
policy.form_action :self
policy.manifest_src :self
if Rails.env.development?
# If you are using webpack-dev-server then specify webpack-dev-server host
policy.connect_src :self, "http://#{ViteRuby.config.host_with_port}", "ws://#{ViteRuby.config.host_with_port}"
# Inertia.js uses inline scripts to display error modal in development
policy.script_src :self, :unsafe_eval, "http://#{ViteRuby.config.host_with_port}", :unsafe_inline, 'https://polyfill.io'
else
policy.connect_src :self
policy.script_src :self, :blob
end
# @inertiajs/progress uses inline styles
policy.style_src :self, :unsafe_inline
policy.base_uri :self
# Specify URI for violation reports
# policy.report_uri "/csp-violation-report-endpoint"
end
# If you are using UJS then enable automatic nonce generation
# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
# Set the nonce only to specific directives
# Rails.application.config.content_security_policy_nonce_directives = %w(script-src)
# Report CSP violations to a specified URI
# For further information see the following documentation:
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
# Rails.application.config.content_security_policy_report_only = true