Angular4 Content-Security-Protocol 拒绝加载字体

标签 angular google-chrome content-security-policy

我刚从 Angular1.6 -> 4 升级,我有点被 Content-Security-Protocol 错误困住了:

http://localhost:4200/:1 GET http://localhost:4200/ 404 (Not Found)
localhost/:1 Refused to load the font 'data:font/woff;base64,d09GRgABAAAAAIt0ABEAAAABQDwAAQABAAAAAAAAAAAAAAAAAAAAACwKGBmIIpVWLACJWGwAUVjI2KwAiNEswkKAwIrswsQAwIrsxEWAwIrWbIEKAZFUkSzCxAEAisA' 
because it violates the following Content Security Policy directive: "default-src 'self'". Note that 'font-src' was not explicitly set, so 'default-src' is used as a fallback.

就像我尽我所能,让我也发布我的 JSON 文件!有人可以帮我了解到底发生了什么,为什么它不起作用以及其他可能的解决方案吗?而且,我还没有用 manifest.JSON 尝试过它....我在这个项目上有一定的经验,所以任何帮助都将不胜感激!

<!doctype html>
<html lang="en">
<head>
  <meta http-equiv="Content-Security-Policy" content="
        default-src 'none';
        style-src 'self' 'unsafe-inline';
        font-src * data:;
        " />
  <meta charset="utf-8">
  <title>Comp</title>
  <base href="/">


  <!-- Latest compiled and minified CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

  <!-- jQuery library -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

  <!-- Latest compiled JavaScript -->
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
  <app-root></app-root>
</body>
</html>

包.JSON :

{
  "name": "comp",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve && node app.js",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.0.0",
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.0.0",
    "@angular/compiler-cli": "^4.2.6",
    "@angular/core": "^4.0.0",
    "@angular/forms": "^4.0.0",
    "@angular/http": "^4.0.0",
    "@angular/platform-browser": "^4.0.0",
    "@angular/platform-browser-dynamic": "^4.0.0",
    "@angular/router": "^4.0.0",
    "core-js": "^2.4.1",
    "module": "^1.2.5",
    "mongodb": "^2.2.30",
    "mongoose": "^4.11.1",
    "mongoose-middleware": "^1.0.0",
    "ng2-dnd": "^4.2.0",
    "rxjs": "^5.1.0",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "^1.2.0",
    "@angular/language-service": "^4.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/mongodb": "^2.2.7",
    "@types/node": "^8.0.10",
    "body-parser": "^1.17.2",
    "codelyzer": "~3.1.2",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.5.0",
    "typescript": "~2.4.1"
  }
}

最佳答案

感谢@sideshowbarker 的评论:

sounds like you have Content-Security-Policy header with a stricter policy than what you’re trying to set with that meta element in the document. You can’t set a less-strict policy that way. You need to change the header value instead. See stackoverflow.com/questions/42960811/ … and stackoverflow.com/questions/44732431/

错误是由模块内更严格的 CSP 引起的,因此请尝试在 .ts 文件中禁用模块导入,这就是我所做的。

祝你好运!

关于Angular4 Content-Security-Protocol 拒绝加载字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45059376/

相关文章:

javascript - Chrome 扩展程序和 Jenkins URL

javascript - 在 Angular 中将图像转换为文件类型

javascript - 如何通过可观察量组合来自两个端点的数据?

javascript - 如何使用 javascript 或 jquery 在客户端机器上创建 xml 文件

google-chrome - 当我打开网络检查器时,Chrome 正在缩小视口(viewport)

javascript - Chrome 扩展 “Refused to load the script because it violates the following Content Security Policy directive”

angular - 如何从 parent 向 child 发出事件?

angular - 如何检测 Angular 中的死代码或未使用的代码?

javascript - Chrome 扩展 : how to trap/handle content-script errors globally?

security - <a> 标签的内容安全策略/子资源完整性?