我有一个iframe标记,src是另一个服务器上的网页。我有能力修改两个网站的标题。在开始实现之前,我能够单击iframe中的一个按钮并检索GPS坐标。我相信有关的一些内容阻止了我的父站点运行地理定位API。
父网站代码:
<customHeaders>
<add name="Content-Security-Policy" value="frame-src 'self' https://MyChildSite.com" />
</customHeaders><html>
<iframe src="https://MyChildSite.com" allow="geolocation"></iframe>
</html>“儿童网站守则”:
<customHeaders>
<add name="Content-Security-Policy" value="frame-src 'self' https://MyParentSite.com" />
<add name="Feature-Policy" value="geolocation 'self' https://MyParentSite.com" />
</customHeaders><html>
<button onclick="getCoordinates()">Get GPS</button>
...list some stuff
</html>当我通过父站点单击子站点上的按钮时,我无法从坐标中得到预期的响应。有解决办法吗?
发布于 2020-10-29 10:09:06
,--------------------- 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请参阅在allow=属性中指定没有键的指令。将从src=属性获得原点。解决方案是在allow=属性中显式指定允许的源:
<iframe src="https://MyChildSite.com" allow="geolocation 'self' https://MyParentSite.com"></iframe>或者,您可以删除allow=属性(或设置allow='*'):
<iframe src="https://MyChildSite.com"></iframe>并在iframe中使用Feature-Policy: geolocation 'self' https://MyParentSite.com设置权限。
我可以要求你在你的问题上加上feature policy标签吗?这将在将来帮助其他人。
编辑
allow="*"不再起作用了,但必须按下面的allow="geolocation *"来说明
https://stackoverflow.com/questions/64582203
复制相似问题