content_security_policy.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Be sure to restart your server when you modify this file.
  2. # Define an application-wide content security policy
  3. # For further information see the following documentation
  4. # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
  5. # Rails.application.config.content_security_policy do |policy|
  6. # policy.default_src :self, :https
  7. # policy.font_src :self, :https, :data
  8. # policy.img_src :self, :https, :data
  9. # policy.object_src :none
  10. # policy.script_src :self, :https
  11. # policy.style_src :self, :https
  12. # # Specify URI for violation reports
  13. # # policy.report_uri "/csp-violation-report-endpoint"
  14. # end
  15. Rails.application.config.content_security_policy do |policy|
  16. base_uri = proc do
  17. next if !Rails.env.production?
  18. next if !Setting.get('system_init_done')
  19. http_type = Setting.get('http_type')
  20. fqdn = Setting.get('fqdn')
  21. "#{http_type}://#{fqdn}"
  22. end
  23. policy.base_uri :self, base_uri
  24. policy.default_src :self, :ws, :wss, 'https://log.zammad.com', 'https://images.zammad.com'
  25. policy.font_src :self, :data
  26. policy.img_src '*', :data
  27. policy.object_src :none
  28. policy.script_src :self, :unsafe_eval, :unsafe_inline, :strict_dynamic
  29. policy.style_src :self, :unsafe_inline
  30. end
  31. # If you are using UJS then enable automatic nonce generation
  32. Rails.application.config.content_security_policy_nonce_generator = ->(_request) { SecureRandom.base64(16) }
  33. # Report CSP violations to a specified URI
  34. # For further information see the following documentation:
  35. # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
  36. # Rails.application.config.content_security_policy_report_only = true