【发布时间】:2021-01-21 23:45:45
【问题描述】:
当我注意到我的应用程序中使用的 iframe 没有在 ios 上正确加载时,我正在为 android 和 ios 开发一个 cordova 应用程序。事实证明,尽管从 web 服务器正确设置了 frame-ancestors HTTP 标头,但如果通过文件系统打开,safari 将错误地拒绝加载 iframe。
Refused to load http://to-delete-test.azurewebsites.net/ because it does not appear in the frame-ancestors directive of the Content Security Policy.
测试页面的 CSP Header 是:
Content-Security-Policy: frame-ancestors * data: blob: filesystem: about: ws: wss:
显示此错误的示例 HTML 文件(必须从文件系统加载):
<!DOCTYPE html>
<html lang="en">
<head>
<style>
* {
margin: 0; padding: 0; box-sizing: border-box;
}
iframe {
height: 100vh; width: 100%;
}
</style>
</head>
<body>
<iframe src="http://to-delete-test.azurewebsites.net"></iframe>
</body>
</html>
有没有办法可以修改页眉以允许通过 iframe 加载我的网站?
【问题讨论】:
-
我不知道“通过文件系统打开”是什么意思,但我知道
frame-ancestors指令肯定是does not supportdata:blob:和ws:、wss:方案源。看起来about:和filesystem:也不支持。无论如何,您的frame-ancestors应该没有任何限制。检查 Dev Tool -> Network -> Response Header 你实际拥有什么 CSP。 -
@granty 感谢您的回复。 “通过文件系统打开”是指打开从设备文件系统提供的 html 文件,因此 URL 类似于
file:///path/to/file/index.html。在 iOS 或 OSX 上的 safari 中,如果有frame-ancestorsCSP 标头,则无论标头的值是什么,即使包含*,帧似乎都不会加载。 Cordova 应用程序从其文件系统加载网页,因此似乎无法安全地允许 Cordova 应用程序从框架加载,同时还限制其他站点在框架中加载页面。
标签: cordova safari content-security-policy