【问题标题】:heroku app on firefox won't load javascripts due to content security policy由于内容安全策略,firefox 上的 heroku 应用程序不会加载 javascripts
【发布时间】:2020-05-28 13:21:01
【问题描述】:

我有一个新应用部署到 heroku。在 chrome 上它按预期工作,但在 Firefox 中,我在控制台中收到以下错误(并且更像它):

Content Security Policy: The page’s settings blocked the loading of a resource at inline (“script-src”).

这不仅仅是一个烦恼——因为它阻止了 javascripts 的加载,所以该网站基本上不能在 FF 上使用,这显然是一个很大的问题。正如我的研究建议的那样,我无法修改 heroku 上的标题。

做什么?

【问题讨论】:

    标签: javascript ruby heroku sinatra content-security-policy


    【解决方案1】:

    您可以在 Rails 应用层本身中配置您的内容安全策略,因此无需更改 Heroku 配置,如下所示:

    # config/initializers/content_security_policy.rb
    
    Rails.application.config.content_security_policy do |policy|
      policy.default_src :self, :https
      policy.font_src    :self, :https, :data
      policy.img_src     :self, :https, :data
      policy.object_src  :none
      policy.script_src  :self, :https
      policy.style_src   :self, :https, :unsafe_inline
      policy.report_uri  "/csp-violation-report-endpoint"
    end
    

    您可以根据需要进行更改。更多详情可以查看here

    【讨论】:

    • 谢谢!我正在使用 sinatra,但我想肯定有类似的配置选项可用
    猜你喜欢
    • 2022-01-08
    • 1970-01-01
    • 2020-07-21
    • 2020-02-19
    • 2014-11-10
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    相关资源
    最近更新 更多