X-Frame-Options 标头在防止恶意框架方面有多有用?
将 X-Frame-Options DENY
添加到响应标头有助于防止网页的恶意框架,作为一种解决方案,它肯定比客户端 JavaScript 解决方案更好。
但它到底有多有用呢?所有(现代)浏览器都支持它,意图劫持您网站的黑客是否可以绕过它?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
EricLaw 的页面 维护支持浏览器的列表。
目前主流桌面浏览器版本均支持;旧版本和利基市场,而某些移动浏览器则没有。因此,您可能还想包含一个反框架
,以设置
top.location
(并在出现反框架的情况下首先删除页面内容) -busting;请参阅这个问题了解原因)。当您想要有选择地允许框架时,您可能更喜欢使用脚本方法而不是 X-Frame-Options。
X-Frame-Options
不允许“白名单”,因此您不能允许 Google 图片流量但不允许其他流量。无论哪种方式,IE6-7 仍然允许攻击者构建您的页面并禁用框架破坏程序。不幸的是,有问题的
属性在
X-Frame-Options
之前就已存在。您可以尝试添加
来尝试使任何导航突破传统框架(或者在存在反框架破坏者的情况下不起作用),但这无法帮助您抵御看不见的 iframe 覆盖攻击。EricLaw's page maintains a list of supporting browsers.
Current verions of the major desktop browsers all support it; older versions and niche and some mobile browsers don't. So you will probably want to include an anti-framing
<script>
as well, to settop.location
(and remove the page content first in case of anti-frame-busting; see this question for why).You might prefer the script approach to
X-Frame-Options
when you want to selectively allow framing.X-Frame-Options
does not permit ‘whitelisting’, so you can't eg allow Google Images traffic but not others.Either way, IE6-7 will still allow attackers to frame your page and disable the frame-buster. Unfortunately the questionable
<iframe security>
attribute existed beforeX-Frame-Options
. You could try adding<base target="_top">
to try to make any navigation break out traditional framing (or just not work, in the presence of anti-frame-busters), but this can't help you against invisible-iframe-overlay attacks.