,--------------------- parent https://MyParentSite.com ------------------------,
|Content-Security-Policy: frame-src 'self' https://MyChildSite.com |
| * aboved CSP do allow <iframe src="https://MyChildSite.com" |
| |
| |
| <iframe src="https://MyChildSite.com" allow="geolocation"> |
| |
| ,-------------------- nested https://MyChildSite.com --------------------, |
| |Content-Security-Policy: frame-src 'self' https://MyChildSite.com | |
| | 1. aboved CSP do nothing, it will apply to subnested iframes only | |
| | | |
| | 2. allow="geolocation" -> allow="geolocation https://MyChildSite.com" | |
| | which is EQUAL to: | |
| | Feature-Policy: geolocation https://MyChildSite.com | |
| | | |
| | Therefore header: | |
| | | |
| |Feature-Policy: geolocation 'self' https://MyParentSite.com | |
| | will failed to allow https://MyParentSite.com, iframe can not extend | |
| | permissions, given by parent document, see para 2. above. | |
| | As result within iframe you will have only: | |
| | Feature-Policy: geolocation https://MyChildSite.com | |
| | | |
| |________________________________________________________________________| |
| |
| </iframe> |
!______________________________________________________________________________|
为什么allow="geolocation"
->allow="geolocation https://MyChildSite.com
请参阅允许 = 属性中的指令,如果没有指定键,则该指令将来自src=
属性。
将功能策略权限传递到嵌套浏览上下文中有一些细节。iframe 不能委派自己(或子嵌套 iframe)比父文档授予的更多权限。
如果你有一个在 iframe 中运行的脚本,你可以使用featurePolicy.getAllowlistForFeature接口来获取所有允许来源的列表并查看发生了什么。
您的问题与内容安全策略无关,我认为您甚至在浏览器控制台中都没有任何 CSP 违规。
解决方案是在allow=
属性中明确指定允许的来源:
<iframe src="https://MyChildSite.com" allow="geolocation 'self' https://MyParentSite.com"></iframe>
或者,您可以删除allow=
属性(或设置 allow='*'):
<iframe src="https://MyChildSite.com"></iframe>
并Feature-Policy: geolocation 'self' https://MyParentSite.com
在 iframe 中使用来设置权限。
PS:能否请您在问题中添加“功能政策”标签,这将有助于其他人。