You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.6 KiB

  1. # Define an application-wide content security policy
  2. # For further information see the following documentation
  3. # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
  4. if Rails.env.production?
  5. assets_host = Rails.configuration.action_controller.asset_host || "https://#{ENV['WEB_DOMAIN'] || ENV['LOCAL_DOMAIN']}"
  6. data_hosts = [assets_host]
  7. if ENV['S3_ENABLED'] == 'true'
  8. attachments_host = ENV['S3_ALIAS_HOST'] || ENV['S3_CLOUDFRONT_HOST'] || ENV['S3_HOSTNAME'] || "s3-#{ENV['S3_REGION'] || 'us-east-1'}.amazonaws.com"
  9. elsif ENV['SWIFT_ENABLED'] == 'true'
  10. attachments_host = ENV['SWIFT_OBJECT_URL']
  11. else
  12. attachments_host = nil
  13. end
  14. data_hosts << attachments_host unless attachments_host.nil?
  15. Rails.application.config.content_security_policy do |p|
  16. p.base_uri :none
  17. p.default_src :none
  18. p.frame_ancestors :none
  19. p.script_src :self, assets_host
  20. p.font_src :self, assets_host
  21. p.img_src :self, :data, :blob, *data_hosts
  22. p.style_src :self, :unsafe_inline, assets_host
  23. p.media_src :self, :data, *data_hosts
  24. p.frame_src :self, :https
  25. p.worker_src :self, assets_host
  26. p.connect_src :self, :blob, Rails.configuration.x.streaming_api_base_url, *data_hosts
  27. p.manifest_src :self, assets_host
  28. end
  29. end
  30. # Report CSP violations to a specified URI
  31. # For further information see the following documentation:
  32. # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
  33. # Rails.application.config.content_security_policy_report_only = true