html - <object> 元素在什么沙箱中运行?这个沙箱可以配置吗?

标签 html security iframe browser sandbox

我运行一个显示用户生成的 SVG 的网站。它们不受信任,因此需要进行沙箱处理。

我目前使用 <object> 嵌入这些 SVG元素。 (与 <img> 不同,这允许加载外部字体。并且与使用 <iframe> 不同, <object> 会调整大小以适应 SVG 的内容大小。 See this discussion. )

但是,我不知道在使用<object>时这些SVG是否被适本地沙箱化了。 。 <iframe>权限模型相当清晰,例如<iframe sandbox="allow-scripts">禁止除运行脚本之外的任何操作。但是 <object> 的沙箱/权限模型是什么?元素?

  • 当我使用 <object> 嵌入页面时,该页面默认可以做什么?例如。它可以访问哪些cookie?和 <iframe> 一样吗没有 sandbox属性?
  • 在同一域中托管用户内容 SVG 有何影响?我应该将它们托管在 foobarusercontent.com 上吗? ?
  • <object> 是吗?标签支持相当于 sandbox属性?是否有另一种方法来设置 <object> 的权限?
  • 哪些规范描述了 <object> 的安全模型?

最佳答案

When I embed a page using <object>, what can that page do by default? E.g. what cookies can it access? Is it the same as an <iframe> without the sandbox attribute?

是的(至少在某些浏览器中)。该对象可以访问与包含它的源相同的 cookie(但不能访问包含它的源)。

您可以使用 svg 文件对此进行测试:

<svg xmlns="http://www.w3.org/2000/svg" width="400" height="110">
  <rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)" />
  <script>alert(document.cookie)</script>
</svg>

您可以包括:

<script>document.cookie="test=test";</script>
<object data=./x.svg></object>

这适用于 Firefox(但不适用于 Chrome,它显然会阻止对象中的 JavaScript;尽管我不确定此行为是否已记录,并且我不会出于安全目的而依赖它)。

如果data属性引用不同的域,您将无法访问嵌入页面的 cookie(通过 topparent ;至少在 Firefox 中)。

What are the implications of hosting the user content SVGs on the same domain? Should I instead host them on foobarusercontent.com?

是的,这会将用户的操作限制在来源 foobarusercontent.com (这可能适合也可能不适合您的使用)。

Does the <object> tag support an equivalent of the sandbox attribute? Is there another way to set permissions for an <object>?

据我所知,还没有(另请参阅 mozilla ,它没有列出任何相关标签)。

What specifications describe the security model for <object>?

我不知道这方面的标准。因此,在将用户提供的数据嵌入 object 时我会非常小心。 。将数据托管在指定域上是一个好主意。解析数据并过滤恶意(与 JavaScript 相关)标签和属性也很好(如果可以接受)。确保用户可以在该域上运行 JavaScript(即没有身份验证 cookie;我也不允许将 .js 文件上传到该域,因为这将允许安装 serviceworkers,这将允许攻击者登录用户访问的 URL,因此可能会泄露域中托管的(私有(private))文件。

关于html - <object> 元素在什么沙箱中运行?这个沙箱可以配置吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71209830/

相关文章:

javascript - 我不知道如何将 iframe 链接到按钮

javascript - 如果 jQuery 动态加载,jQuery 的 ajax() 不起作用

javascript - 加载 JavaScript/CSS 文件

html - 将 HTML 转换为 doc(x) 和/或 PDF

php - 形成邮政安全。确保它不是来自外部来源

javascript - 在使用 JSON.parse 之前应该如何清理不受信任的 JSON?

angularjs - Firebase:它足够安全吗?

iframe - iframe中加载的内容会影响Google Analytics(分析)“页面加载时间”吗?

html - 拆分进度条

html - Chrome : inline-block, padding-right 和 right click 错误