5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-24 13:26:21 +00:00
panel/config/initializers/content_security_policy.rb

41 lines
1.7 KiB
Ruby
Raw Permalink Normal View History

2019-08-29 17:54:19 +00:00
# frozen_string_literal: true
# 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
2020-02-06 16:11:17 +00:00
Rails.application.config.content_security_policy do |policy|
policy.default_src :self
# XXX: Varios scripts generan estilos en línea
policy.style_src :self, :unsafe_inline, :https
2020-02-06 16:11:17 +00:00
# Repetimos la default para poder saber cuál es la política en falta
policy.script_src :self
policy.font_src :self, :https
2020-02-07 23:38:56 +00:00
# XXX: Los íconos de Trix se cargan vía data:
2020-11-05 22:19:02 +00:00
policy.img_src :self, :data, :https, :blob
2020-02-06 16:11:17 +00:00
# Ya no usamos applets!
policy.object_src :none
2021-02-10 16:17:37 +00:00
# webpack-dev-server
2020-02-06 16:11:17 +00:00
if Rails.env.development?
policy.connect_src :self,
2021-02-10 16:17:37 +00:00
"https://#{ENV.fetch('SUTTY', 'sutty.local')}:3035",
"wss://#{ENV.fetch('SUTTY', 'sutty.local')}:3035"
2020-02-06 16:11:17 +00:00
end
2019-08-29 17:54:19 +00:00
2020-02-06 16:11:17 +00:00
# Specify URI for violation reports
policy.report_uri "https://api.#{ENV.fetch('SUTTY_WITH_PORT', 'sutty.nl')}/v1/csp_reports.json"
end
2019-08-29 17:54:19 +00:00
# If you are using UJS then enable automatic nonce generation
2020-02-06 16:11:17 +00:00
# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
2019-08-29 17:54:19 +00:00
# Set the nonce only to specific directives
2020-02-06 16:11:17 +00:00
# Rails.application.config.content_security_policy_nonce_directives = %w(script-src)
2019-08-29 17:54:19 +00:00
# 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
2020-02-06 16:11:17 +00:00
Rails.application.config.content_security_policy_report_only = false