Chrome 63 似乎忽略或中断 worker-src CSP headers

Chrome 63 seems to ignore or break on worker-src CSP headers

错误

我正在开发几个使用网络工作者的应用程序,但使用最新的 Chrome V63.0.3230.132

这是我在控制台上看到的错误消息:

[Report Only] Refused to create a worker from 'http://localhost:8080/d04af186322390d53036.worker.js' because it violates the following Content Security Policy directive: "worker-src 'none'".

我也注意到 some other sites 的行为方式相同。

显然,如何创建该 worker 并不重要。 我在使用 worker-loader 的 React 应用程序中尝试过它,但也在我手动创建它的纯 JS 演示中尝试过。错误保持不变。

我试过的

我已经准备好所有 CSP headers,并且还用 the correct CSP entry 更新了我的 manifest.json 文件,但无济于事。

所有其他浏览器都工作正常。

有人可以确认或解释这种行为吗?

Upd:在这种情况下,问题的根源在于安装并启用了 uMatrix 插件。即使插件关闭,问题仍然存在。因此,有两种方法可以解决这些令人困惑的错误:

  • 在浏览器的 Extension/Plugins 菜单中完全禁用 uMatrix。在 uMatrix 中使用内置的 "turn off" 按钮将无济于事。
  • 随它去吧,忽略警告。

详情在这里https://github.com/gorhill/uMatrix/issues/926#issuecomment-359905357


首次回复历史。

Xceno,你确认Chrome真的加载worker失败了吗?

我看到了完全相同的错误,但是......软件确实有效。也许这只是 Chrome.

的误报错误

这是我的代码以及我在控制台中看到的内容

navigator.serviceWorker.register('/sw.js').then(function(registration) {
    console.log('ServiceWorker registration successful with scope: ', registration.scope);
    // ... some other code
}

控制台输出:

defer.js:36 [Report Only] Refused to create a worker from 'https://.../sw.js' because it violates the following Content Security Policy directive: "worker-src 'none'".
defer.js:37 ServiceWorker registration successful with scope:  https://.../

在我的案例中,软件实际上已成功安装并按设计工作。

正如承诺的那样——这是 headers。我无法将它们作为评论。如您所见,我没有明确的 CSP headers,唯一与安全相关的是 x-content-type-optionsx-frame-options。就是这样。希望能有所帮助。

content-type: text/html; charset=UTF-8
cache-control: must-revalidate, no-cache, private
x-ua-compatible: IE=edge
content-language: en
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
expires: Sun, 19 Nov 1978 05:00:00 GMT
vary: Accept-Encoding
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 3e91b05aabb05540-ORD
content-encoding: br
x-firefox-spdy: h2