gpt4 book ai didi

javascript - 哪个更安全 - iframe 或 CORS - 用于创建用于嵌入第 3 方网站的小部件?

转载 作者:搜寻专家 更新时间:2023-11-01 04:25:08 24 4
gpt4 key购买 nike

在构建旨在嵌入第 3 方网站的小部件时,似乎有两种关于如何实现的思想流派:

  • 使用iframe
  • 使用主页的DOM

当使用iframe方法时,跨域请求不是问题,因为服务器认为请求来自它自己的页面。

当使用主页的 DOM 时,跨域请求是一个问题,服务器需要使用适当的 CORS header 进行响应才能正常工作。

这两种方法哪种更安全,在实现这两种方法时应该考虑哪些安全问题?

最佳答案

您可能会发现这篇文章很有趣 - How to protect widgets from forged requests :

You don't want this [widget] to be vulnerable to CSRF so you write an iframe to the page. Based on the origin inheritance rules the parent site won't be able to read the CSRF token. However what about clickjacking (or likejacking )? Because of CSRF you must be within an iframe and there for the x-frame-options cannot help, and the same holds true for frame-busters

IFrame 方法的负面影响

DOM 方法的负面影响

  • 易受 CSRF 攻击.
  • 您服务器上的 CORS header 将允许访问整个世界或预先注册的整个站点。虽然这本身并不存在漏洞,但必须小心确保没有敏感信息可用(例如用户数据)。没有办法仅限制对您的小部件的访问 - 您将授予对整个 Origin(即协议(protocol)、域和端口)的访问权限。
  • 当您操作 DOM 时,可以从小部件之外的页面其余部分访问这些对象。

总结

最终取决于您的小部件的功能。父站点在用户上下文中自动提交表单或单击小部件上的按钮的结果是什么?如果有喜欢或 +1 按钮,托管页面可能会在用户不知情或未同意的情况下通过向您注册喜欢/+1 来欺诈性地宣传他们的网站。这将适用于两种方法,只是攻击方法不同(即 CSRF 或点击劫持)。

上面帖子中接受的答案有针对 CSRF 与点击劫持的解决方案:

Clicking on the widget needs to open a pop-up window containing a new page -- an iframe is not good enough, it must be a new window -- which is entirely under the control of your web application. Confirm the action, whatever it is, on that page.

Yes, this is somewhat inelegant, but the present Web security architecture doesn't give you any better options.

总而言之,IFrame 方法似乎具有更高的整体安全性,并且在交互时实现弹出窗口可降低点击劫持风险。

关于javascript - 哪个更安全 - iframe 或 CORS - 用于创建用于嵌入第 3 方网站的小部件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25236746/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com