在应用程序启动时显示内容安全策略

Show Content Security Policy at app startup

我正在尝试设置 CSP,Ember 正在做一些有趣的事情,很难描述。我正确地配置了一部分,而另一部分却失败了。或者突然,livereload被阻塞了。或者它说 script-src 未定义,然后退回到 default-src,这很好,如果它不是谎言的话。我知道 ember-cli-content-security-policy is processing CSP 允许 livereload 等等,但我不知道 when/how 这已经完成了。我想验证我配置的 CSP 是否在 ember-cli 处理中幸存下来,因为经过一个小时的调试我不再信任它了。

长话短说:我想在我的应用程序启动时看到 CSP,就在显示版本时。我不想看到我已配置的 CSP,但 Ember 正在使用的 CSP,可能相同也可能不同:这正是我想知道的。

我怎么知道Ember"show me the CSP that you are using"?

编辑

感谢@Bek 提供有关检查请求的提示 headers。

使用此配置(copy-pasted 来自 ember-cli-content-security-policy 自述文件):

ENV.contentSecurityPolicy = {
  'default-src': "'none'",
  'script-src': ["'self'", "https://cdn.mxpnl.com"], // Allow scripts from https://cdn.mxpnl.com
  'font-src': ["'self'", "http://fonts.gstatic.com"], // Allow fonts to be loaded from http://fonts.gstatic.com
  'connect-src': ["'self'", "https://api.mixpanel.com", "http://custom-api.local"], // Allow data (ajax/websocket) from api.mixpanel.com and custom-api.local
  'img-src': "'self'",
  'style-src': ["'self'", "'unsafe-inline'", "http://fonts.googleapis.com"], // Allow inline styles and loaded CSS from http://fonts.googleapis.com
  'media-src': null // `media-src` will be omitted from policy, browser will fallback to default-src for media resources.
}

我得到这些 headers:

Content-Security-Policy-Report-Only: default-src 'none'; script-src 'self',https://cdn.mxpnl.com,e,l,f,', ,',u,n,s,a,f,e,-,e,v,a,l,' localhost:49152 0.0.0.0:49152; font-src 'self',http://fonts.gstatic.com,e,l,f,'; connect-src 'self',https://api.mixpanel.com,http://custom-api.local,l,f,' ws://localhost:49152 ws://0.0.0.0:49152 http://undefined:16013/csp-report; img-src 'self'; style-src 'self','unsafe-inline',http://fonts.googleapis.com,l,f,'; media-src null; report-uri http://undefined:16013/csp-report;

看来ember-cli-content-security-policy确实在搞笑。不知道如何解决。我打开了一个 issue.

内容安全策略很简单header(附加到所有回复)从您的主机服务器发送,您可以随时检查它去chrome dev工具网络部分

I get these headers:
It seems that indeed ember-cli-content-security-policy is doing something funny. No idea how to solve that. I have opened an issue.

此问题出现在 v0.4.0 而不是 master(我想它已修复)所以现在您可以从 master

安装它
"ember-cli-content-security-policy": "rwjblue/ember-cli-content-security-policy#master",