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
|
|
|
|
# Repetimos la default para poder saber cuál es la política en falta
|
|
|
|
policy.script_src :self
|
|
|
|
policy.font_src :self
|
|
|
|
# TODO: Permitimos cargar imágenes remotas?
|
2020-02-07 23:38:56 +00:00
|
|
|
# XXX: Los íconos de Trix se cargan vía data:
|
|
|
|
policy.img_src :self, :data
|
2020-02-06 16:11:17 +00:00
|
|
|
# Ya no usamos applets!
|
|
|
|
policy.object_src :none
|
|
|
|
if Rails.env.development?
|
|
|
|
policy.connect_src :self,
|
|
|
|
'http://localhost:3035',
|
|
|
|
'ws://localhost:3035'
|
|
|
|
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
|