确保 iframe 内容无法通过 javascript 访问父级

发布于 2024-12-03 09:55:34 字数 616 浏览 1 评论 0原文

虽然我知道如果域、协议等不匹配,xss 规则应该适用于 iframed 内容,但我想知道是否有任何方法可以进一步确保 iframed 内容无法通过 javascript 访问父级。

例如,即使域端口和协议确实匹配。

基本思想是这样的:

1)domain.com 包含多个包含第三方广告的 iframe

2)包含横幅代码的 iframe 托管在 ads.domain.com 上

3)在大多数情况下,第 3 方广告是通过某些东西加载的例如,在 ads.domain.com 上托管的框架内:

<script type="text/javascript" src="http://www.3rd-party-ad-provider.....

我们是否可以采取任何进一步的步骤来最终实现如下场景:

第 3 方 <有访问权限> ads.domain.com <无法访问> domain.com(家长持有广告 iframe),

甚至欢迎仅在最新浏览器上兼容的步骤。有什么可以改善这一点的。我们看到相当多的 js 错误泄漏,我假设至少其中一些是由错误的广告代码破坏父(最顶层)文档正文引起的。

谢谢!

while i know that xss rules should apply to iframed content if the domain, protocol etc do not match, i was wondering if there is any way to further ensure that iframed content cannot access the parent via javascript.

for example, even if the domain port and protcol DO match.

the basic idea is as such:

1) domain.com contains multiple iframes containing 3rd party advertisements

2) the iframes that contain the banner code are hosted on ads.domain.com

3) in most cases, the 3rd party advertisements are loaded via something like, inside the frames that are hosted on ads.domain.com:

<script type="text/javascript" src="http://www.3rd-party-ad-provider.....

is there any further steps we can take to end up with a scenario as follows:

3rd party < HAS ACCESS > ads.domain.com < NO ACCESS > domain.com (parent holding the ad iframes)

even steps that are only compatible on recent browsers are welcome. anything to improve this. we are seeing quite a bit of js errors leaking thru and i am assuming that at least some of it is caused by faulty ad code mangling the parent (top-est) document body.

merci!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遮云壑 2024-12-10 09:55:34

虽然我知道如果域、协议等不匹配,xss 规则应该适用于 iframed 内容,但我想知道是否有任何方法可以进一步确保 iframed 内容无法通过 javascript 访问父级。

没有什么可以跨浏览器工作或没有副作用。

第 3 方

有访问权限> ads.domain.com <无法访问> domain.com(持有广告 iframe 的父级)

同源策略可以做到这一点。

我们看到相当多的 js 错误泄漏,我假设至少其中一些错误是由错误的广告代码破坏父(最顶层)文档正文引起的。

如果 JS 在某个框架中出错,那么它仍然会出错。它不应该触及顶层框架,但浏览器会报告错误。

由于您正在处理第三方内容,因此您无法捕获错误。

您可以简单地对广告商采取强硬立场,拒绝未通过质量控制的广告。您必须权衡拒绝广告的成本与改善访问者体验的好处。

while i know that xss rules should apply to iframed content if the domain, protocol etc do not match, i was wondering if there is any way to further ensure that iframed content cannot access the parent via javascript.

Nothing that works cross-browser or without side effects.

3rd party < HAS ACCESS > ads.domain.com < NO ACCESS > domain.com (parent holding the ad iframes)

The same origin policy does that.

we are seeing quite a bit of js errors leaking thru and i am assuming that at least some of it is caused by faulty ad code mangling the parent (top-est) document body.

If JS errors in a frame, then it still errors. It shouldn't touch the top level frame, but browsers will report the errors.

Since you are dealing with third party content, you can't catch the errors.

You could simply take a hard line with the advertisers and reject adverts that don't pass quality control. You'll have to weigh the cost of turning adverts down with the benefits of the improved experience for visitors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文