我在网络视图中有一个iframe,可使用以下内容从android应用的资产中加载脚本:-
<script src='file:///android_asset/trusted-iframe-script.js'></script>
现在,我想在iframe上使用内容安全策略,这样就无法加载其他脚本。为此,我在iframe CSP中添加了以下内容
script-src: 'file:///android_asset/trusted-iframe-script.js';
由于chrome忽略了文件uri,因此无法使用。
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的正确方法?
简而言之,对于沙盒iframe无法做到这一点。
Chrome CSP不允许将文件网址作为脚本src列入白名单。您可以使用指令文件:(不带任何网址),并且如果未对iframe进行沙箱测试,则可以使用该指令文件。但这是一个坏主意,因为
答:我的iframe已沙盒化,并且
B.这是一个未记录的关键字,可能随时停止工作。
我还尝试为内容创建一个Blob网址,而不是将其传递给iframe,但这也行不通,除非您在iframe沙盒属性上设置了allow-same-origin。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句