嵌入YouTube视频的CSP

问题描述

我刚刚开始在Chrome上嵌入我的youtube视频(86.0.4240.193-最近更新,这可能就是我刚刚看到此内容的原因)开始看到这些-这些仅是“报告”,因此这些视频仍然显示100张错误是不对的!这就是我所看到的:

[Report Only] Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'strict-dynamic' 'unsafe-inline' https: 'report-sample' 'nonce-t9IE7nI2leo7qKxsm7d80g=='".

这是我的iFrame-

<iframe id="video-iframe" width="500" height="281" src="https://www.youtube.com/embed/HIDDENVIDEO" frameborder="0" allowfullscreen ></iframe>

我无法弄清楚CSP应该是什么-这是我发现可以明显解决其问题的一个-

<iframe id="video-iframe" width="500" height="281" src="https://www.youtube.com/embed/HIDDENVIDEO" frameborder="0" allowfullscreen csp="script-src 'self' https://www.google-analytics.com/ https://www.youtube.com/ https://s.ytimg.com/; object-src 'self'; child-src https://www.youtube.com/* https://s.ytimg.com/"></iframe>

没什么-我只看到:拒绝显示...。

非常感谢任何帮助。

我刚刚检查了developers.google.com/youtube/iframe_api_reference#Examples页,并且看到了同样的东西-当然这不应该发生,对吧?

enter image description here

解决方法

如您所见,此错误不是由您的CPS触发的-您没有'nonce-t9IE7nI2leo7qKxsm7d80g=='"令牌。此错误出现在Google的<iframe>中,完全是Google的内部交易。

事实是,以前的多个Chrome版本都有一个错误和did not block eval表达式。
在Chrome版本86中,他们修复了此错误,并通过设置“仅报告”标头并对其进行虚假调用来评估此错误,以评估报告。

CSP for Youtube非常简单,不需要'unsafe-eval',因为所有工作都在隔离的iframe中进行。

顺便说一句,您的CSP具有error-路径部分不允许使用*。并且请注意<iframe csp=-如果服务器与您的CSP不同,则内容将被阻止。
但这<iframe csp=之所以发挥了作用,是因为Chrome浏览器又发生了一次错误-如果Content-Security-Policy标头存在,它将忽略Content-Security-Policy-Report-Only。