Google chrome 如何在chrome中将CSP限制为文件:///URL?
我在webview中有一个iframe,它使用以下命令从android应用程序的资产加载脚本:-Google chrome 如何在chrome中将CSP限制为文件:///URL?,google-chrome,content-security-policy,Google Chrome,Content Security Policy,我在webview中有一个iframe,它使用以下命令从android应用程序的资产加载脚本:- <script src='file:///android_asset/trusted-iframe-script.js'></script> 这不起作用,因为文件uri被chrome忽略 The source list for Content Security Policy directive 'script-src' contains an invalid source:
<script src='file:///android_asset/trusted-iframe-script.js'></script>
这不起作用,因为文件uri被chrome忽略
The source list for Content Security Policy directive 'script-src' contains an invalid source: 'file:///android_asset/trusted-iframe-script.js'. It will be ignored.
Refused to load the script 'file:///android_asset/trusted-iframe-script.js' because it violates the following Content Security Policy directive: "script-src file:///android_asset/trusted-iframe-script.js".
我读过关于文件系统uri的文章,但这需要请求访问用户,但实际上我只需要访问自己的资产,而不是一般的文件系统。我也读过关于blob:url的文章,但这感觉类似于内联整个脚本
csp仅限于文件URL的正确方法是什么?csp URI没有引号-因此请尝试
script src:file:///android_asset/trusted-iframe-script.js;代码>
如果这不起作用,大多数Android浏览器现在都支持CSP2,它允许您为支持的脚本指定哈希值。如果CSP设置在包含您应该使用的iframe的“页面”上
子src:指令而不是脚本src:()
那么,我不想使用如何包含断言文件,您可以尝试:
- 子src:file:///android_asset/trusted-iframe-script.js
//我无法测试它
- 子src:filesystem:///android_asset/trusted-iframe-script.js
//并检查是否仍需要请求访问该用户
- 子src:
//这应该可以工作,但需要有一个受信任的服务器,并且应用程序必须连接到web(无明显条件)
简而言之,对于沙盒iframe,这是无法做到的
Chrome CSP不允许将文件URL作为脚本src列入白名单。您可以使用指令文件:(不带任何url),如果iframe没有沙盒,这将起作用。但这是个坏主意,因为
A.我的iframe是沙盒,并且
B.这是一个未记录的关键字,可能随时停止工作
我还尝试为内容创建一个blobURL,并将其传递给iframe,但除非在iframe沙盒属性上设置了allow-same-origin,否则这也不起作用
The source list for Content Security Policy directive 'script-src' contains an invalid source: 'file:///android_asset/trusted-iframe-script.js'. It will be ignored.
Refused to load the script 'file:///android_asset/trusted-iframe-script.js' because it violates the following Content Security Policy directive: "script-src file:///android_asset/trusted-iframe-script.js".