content_security_policy.rb 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. policy.frame_src 'www.youtube.com', 'player.vimeo.com'
  31. end
  32. # If you are using UJS then enable automatic nonce generation
  33. Rails.application.config.content_security_policy_nonce_generator = ->(_request) { SecureRandom.base64(16) }
  34. # Report CSP violations to a specified URI
  35. # For further information see the following documentation:
  36. # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
  37. # Rails.application.config.content_security_policy_report_only = true