javascript - 在 Safari 上的安全沙盒 iframe 中读取 blob?

标签 javascript iframe https safari content-security-policy

下面的这段代码在所有运行 http 的浏览器中都能正常工作
但是当我在 Safari 中使用 https 运行它时,这是行不通的。
它在 Chrome 中使用 http 和 https 都可以正常工作...

<iframe sandbox="allow-scripts" srcdoc="
  <script>
    var blob = new Blob(['abc']);
    var fr = new FileReader();
    fr.readAsText(blob);
    fr.onerror = () => document.body.innerText = 'fail'
    fr.onload = () => document.body.innerText = fr.result
  </script>
"></iframe>

我猜这不是沙箱限制而是 content security policy可以通过正确的 csp 上下文解决的事情

我将其托管在静态页面上,因此我无法通过 header 解决它 但是元标记也可以正常工作...

<meta http-equiv='Content-Security-Policy' content=' <duno> '>

所以这是我的问题:我需要使用什么 csp 才能允许读取 iframe 中的 blob?

我还创建了一个 fiddle为此

最佳答案

您永远无法使用 CSP 指令制定比已从其他地方应用的 CSP 政策创建的任何政策更自由的政策。例如,您不能使用在文档中使用 meta 指定的更自由的策略来覆盖更严格的 CSP header 。

参见 the stuff about multiple policies in the CSP spec :

The impact is that adding additional policies to the list of policies to enforce can only further restrict the capabilities of the protected resource.

因此,就 CSP 在这个 blob-with-iframe-sandbox-allow-script 案例中甚至完全相关的程度而言,如果您将其视为默认情况下自行应用限制性 CSP 策略的浏览器,我不会想象您可以使用 CSP header 或 meta 元素来放宽限制 — 相反,您只能使用 header 或 meta 元素来实现进一步的限制。

无论如何,有兴趣看看您对 https://bugs.webkit.org/show_bug.cgi?id=170075 的回复.

关于javascript - 在 Safari 上的安全沙盒 iframe 中读取 blob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43019482/

相关文章:

javascript - 使用 Angular JS 和 Cordova 上传表单数据和图像

javascript - 如何将功能关联到 google maps api 中的自定义控件?

html - 关于 iframe 和水平滚动的另一个问题

html - 如何在我的 html 页面中使用多个 iFrame?

ssl - 已部署网站上的重新加载页面显示 404 未找到,而本地主机有效

javax.net.ssl.SSLException : Certificate for <> doesn't match any of the subject alternative names: [] 异常

javascript - 时间选择器单击一次不显示时间

Javascript数组排序问题

javascript - 由于 cookie 的 "SameSite"和 "Secure"设置,Google Analytics 在 IFrame 中被阻止

ssl - 错误 SSL NET::ERR_CERT_DATE_INVALID 即使 SSL 尚未过期