我正在开发一个谷歌Chrome 打包应用程序,当我把沙盒放入manifest.json:
{
"manifest_version": 2,
"name": "WM32216",
"version": "2.1",
"minimum_chrome_version": "23",
"permissions":["webview", "https://ajax.googleapis.com/*"],
"sandbox":{
"pages":["index.html"]
},
"app": {
"background": {
"scripts": ["main.js"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
onclick我的锚标签上的事件有效,应用程序的流程已完成,除此之外,CSS样式表中的图标无法加载.
我error从控制台得到了一个
File not found ,
但那些只是字体所以对我来说很好,
最大的问题是,iframe中的视频无法播放,而且我在Font之前得到了额外的错误:
VIDEOJS:错误:(代码:4 MEDIA_ERR_SRC_NOT_SUPPORTED)无法加载媒体,因为服务器或网络出现故障或者格式不受支持.
不允许加载本地资源:blob:null/b818b32c-b762-4bd9 -...
当我删除manifest.json文件中的沙箱时,一切都很好,控制台中没有关于字体的错误,
但是,当我点击/单击我的锚点标记,其中有一个点击事件在js中加载一个新函数我得到以下控制台错误:
拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令:"default-src'self'blob:filesystem:chrome-extension-resource:".要么是'unsafe-inline'关键字,哈希('sha256 -...'),要么是nonce('nonce -...')来启用内联执行.另请注意,'script-src'未显式设置,因此'default-src'用作后备.
很抱歉很长的细节,
我只需要帮助,因为我已经在这里呆了3天了.
我正在向一个站点添加 CSP 标头,该站点在采用严格的策略之前还有很长的路要走。有相当多的内联脚本,因此我使用 nonce- 来允许特定的内联脚本。我发现它不适用于onload带有 src 的脚本标记的属性。这是一个例子:
// header:
Content-Security-Policy: script-src self https: 'nonce-d3adbe3fed'
<script async defer src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" nonce="d3adbe3fed" onload="console.log('onload', _.VERSION)"></script>
Run Code Online (Sandbox Code Playgroud)
完整的工作演示位于https://brave-pasteur-0d438b.netlify.com/
Chrome 给出以下错误:
Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src self https: 'nonce-d3adbe3fed'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
Run Code Online (Sandbox Code Playgroud)
该消息表明应该可以使用随机数启用内联事件处理程序,但据我所知,随机数仅适用于内联脚本。
这只是一个演示,但用例是一个异步/延迟跟踪脚本,它加载跟踪库,然后在onload处理程序中对加载的库进行跟踪调用。
是否可以在一个onload或其他事件处理程序属性上使用随机数,或者我需要更改我的实现吗?使用script-src 'unsafe-inline'orscript-src-attr 'unsafe-inline'不是一个选项,因为这些是我专门试图解决的漏洞。并且将处理程序的内容onload放入脚本标记后面的单独脚本中也不是一个选项,因为脚本是async deferred …