【发布时间】:2018-03-12 11:22:36
【问题描述】:
使用 Angular4 设置 content-security-policy 时出现以下错误。
错误:
拒绝连接 'ws://localhost:4200/sockjs-node/812/lxo2oeas/websocket' 因为它 违反以下内容安全策略指令:“default-src 'self' 'unsafe-eval'"。请注意,'connect-src' 没有明确设置, 所以 'default-src' 被用作后备。
未捕获的 TypeError:event.data.indexOf 不是 receiveMessage (out.js:4) 处的函数
这是我的代码:
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Security-Policy"
content="default-src 'self' 'unsafe-eval';
style-src 'self' 'unsafe-inline';
script-src 'self' http://localhost:4200 'unsafe-inline' 'unsafe-eval';">
<meta charset="utf-8">
<title>Myapp</title>
<base href="/">
<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>
在这里我需要设置content-security-policy,但出现这些错误。
【问题讨论】:
标签: angular content-security-policy