闭社主体 forked from https://github.com/tootsuite/mastodon
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.

34 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. base_host = Rails.configuration.x.web_domain
  5. assets_host = Rails.configuration.action_controller.asset_host
  6. assets_host ||= "http#{Rails.configuration.x.use_https ? 's' : ''}://#{base_host}"
  7. Rails.application.config.content_security_policy do |p|
  8. p.base_uri :none
  9. p.default_src :none
  10. p.frame_ancestors :none
  11. p.font_src :self, assets_host
  12. p.img_src :self, :https, :data, :blob, assets_host
  13. p.style_src :self, :unsafe_inline, assets_host
  14. p.media_src :self, :https, :data, assets_host
  15. p.frame_src :self, :https
  16. p.manifest_src :self, assets_host
  17. if Rails.env.development?
  18. webpacker_urls = %w(ws http).map { |protocol| "#{protocol}#{Webpacker.dev_server.https? ? 's' : ''}://#{Webpacker.dev_server.host_with_port}" }
  19. p.connect_src :self, :data, :blob, assets_host, Rails.configuration.x.streaming_api_base_url, *webpacker_urls
  20. p.script_src :self, :blob, :unsafe_inline, :unsafe_eval, assets_host
  21. else
  22. p.connect_src :self, :data, :blob, assets_host, Rails.configuration.x.streaming_api_base_url
  23. p.script_src :self, :blob, assets_host
  24. end
  25. end
  26. # Report CSP violations to a specified URI
  27. # For further information see the following documentation:
  28. # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
  29. # Rails.application.config.content_security_policy_report_only = true