Chrome 神秘的CSP违规

aurhwmvo  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(126)

我正在创建一个Chrome扩展。当我在本地测试它时,我可以采取一些导致CSP违规的操作:

Refused to run the JavaScript URL because it violates the following Content Security Policy directive: "script-src https://apis.google.com 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

但是,我的代码没有任何内联JavaScript!错误控制台指向我的HTML的第一行,即<!DOCTYPE html>,作为罪魁祸首:

Stack Trace
html/popup.html:1 (anonymous function)

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=600, height=600, initial-scale=1.0">
  <link rel="stylesheet" href="../css/bootstrap-3.3.7-dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="../css/font-awesome-4.7.0/css/font-awesome.min.css">
  <script src="https://apis.google.com/js/api.js"></script>
  <script src="../go/go.js"></script>
</head>
<body style="width: 500px; height: 600px">
  <div> ...

文档中没有其他<script>标记。go.js文件是使用gopherjs从golang编译而来的。
这是怎么回事?如何找出导致此CSP违规的原因?

jfewjypa

jfewjypa1#

<script src="https://apis.google.com/js/api.js"></script>这就是原因。在manifest.json中,尝试添加以下内容:

"content_security_policy": "script-src 'self' 'unsafe-eval' https://apis.google.com; object-src 'self'",

相关问题