从本地 (Angular) 中的响应 header 中删除 Content-Security-Policy

Remove Content-Security-Policy from response header in local (Angular)

我只有在 运行 我的本地应用程序时才会遇到问题。

看来我的 Content-Security-Policy 默认设置为 'none'

我最近从 Angular 7 迁移到 Angular 8 以使延迟加载更容易实现,但我不明白为什么这会将 CSP header默认 default-src 'none'

此外,它在一段时间内运行良好。

但是,当我在本地启动我的应用程序时,在响应 Header 中,我看到了这一行:

Content-Security-Policy: default-src 'none'

我还指出,开发和测试环境的响应 header 中不存在此行。

在本地响应header:

HTTP/1.1 404 Not Found
X-Powered-By: Express
Access-Control-Allow-Origin: *
Content-Security-Policy: default-src 'none'
X-Content-Type-Options: nosniff
Content-Type: text/html; charset=utf-8
Content-Length: 139
Date: Mon, 28 Oct 2019 16:14:09 GMT
Connection: keep-alive

在其他环境中,响应 header 不包含 Content-Security-Policy: default-src 'none' 行。

此外,我尝试将此行添加到我的 index.html 文件中:

<meta http-equiv="Content-Security-Policy" content="default-src 'self'"/>

但这并没有改变任何事情,它可能被 http 服务器(Webpack?)覆盖了。

我想在我的开发和测试环境中,我的 Apache 配置为不使用 CSP,因此 header 不包含 Content-Security-Policy

我怎样才能使它在本地相同?由于它是 Angular 8,我无法访问 Webpack 配置,我相信它是在 @angular-devkit/build-angular 中处理的。 (虽然,它可以通过插件访问,例如 custom-webpack 我读过,但我宁愿避免它)

我不认为 Angular 使用默认配置,其中 Content-Security-Policy: default-src 'none' 是默认策略。 (至少应该是self

最后,这是angular.json文件的一部分,用于构建的本地conf:

  "configurations": {
    "local": {
      "optimization": true,
      "outputHashing": "none",
      "sourceMap": true,
      "extractCss": true,
      "namedChunks": true,
      "aot": false,
      "extractLicenses": true,
      "vendorChunk": false,
      "buildOptimizer": false
    },

如果另一个配置文件(tsconfig、package...)在这里有用,请告诉我。

好的,看来这是由 --deployUrl 构建选项引起的。

我从我的 angular.json 文件中删除了它,重建后错误消失了。 所以我猜测 Angular 在存在部署 url 时添加了一个限制性 CSP header。