content_security_policy.rb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
  2. # Be sure to restart your server when you modify this file.
  3. # Define an application-wide content security policy
  4. # For further information see the following documentation
  5. # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
  6. # Rails.application.config.content_security_policy do |policy|
  7. # policy.default_src :self, :https
  8. # policy.font_src :self, :https, :data
  9. # policy.img_src :self, :https, :data
  10. # policy.object_src :none
  11. # policy.script_src :self, :https
  12. # policy.style_src :self, :https
  13. # # If you are using webpack-dev-server then specify webpack-dev-server host
  14. # policy.connect_src :self, :https, "http://localhost:3035", "ws://localhost:3035" if Rails.env.development?
  15. # # Specify URI for violation reports
  16. # # policy.report_uri "/csp-violation-report-endpoint"
  17. # end
  18. Rails.application.config.content_security_policy do |policy|
  19. base_uri = proc do
  20. next if !Rails.env.production?
  21. next if !Setting.get('system_init_done')
  22. http_type = Setting.get('http_type')
  23. fqdn = Setting.get('fqdn')
  24. "#{http_type}://#{fqdn}"
  25. end
  26. policy.base_uri :self, base_uri
  27. policy.default_src :self, :ws, :wss, 'https://log.zammad.com', 'https://images.zammad.com'
  28. policy.font_src :self, :data
  29. policy.img_src '*', :data
  30. policy.object_src :none
  31. policy.script_src :self, :unsafe_eval, :strict_dynamic
  32. policy.style_src :self, :unsafe_inline
  33. policy.frame_src 'www.youtube.com', 'player.vimeo.com'
  34. end
  35. # If you are using UJS then enable automatic nonce generation
  36. Rails.application.config.content_security_policy_nonce_generator = ->(_request) { SecureRandom.base64(16) }
  37. # Set the nonce only to specific directives
  38. Rails.application.config.content_security_policy_nonce_directives = %w[script-src]
  39. # Report CSP violations to a specified URI
  40. # For further information see the following documentation:
  41. # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
  42. # Rails.application.config.content_security_policy_report_only = true