安全网络检查员不认为我的破坏框架是有效的

Security web inspector is not recognizing my frame busting as an effective one

本文关键字:框架 有效 我的 安全网 网络 检查员 不认为 安全      更新时间:2023-09-26

我正在运行webinspect应用程序来检测我的应用程序上的安全威胁。检测到的威胁之一是(跨帧脚本),我通过添加(X-Frame-Options)标头为(SAMEORIGIN)来修复它。现在,当我重新运行webinspect时,它仍然检测到(跨帧脚本),并报告以下消息:

加载时没有观察到有效的帧破坏技术这个页面在一个框架内

我已经使用了很多块分解代码,但同样的问题仍然存在。我试过下面的block杀手:

第一次尝试:

 <style> html{display:none;} </style> 
   <script>    
    if(self == top) {
    document.documentElement.style.display = 'block';} 
    else {
    top.location = self.location; } 
</script>

第二次尝试:

if (top != self) { top.location.replace(self.location.href); }

第三次尝试:

if(top.location!=self.locaton) {
  parent.location = self.location;
}

定义"effective one"

虽然你展示的三个JavaScript片段确实有效,但你有没有想过如何阻止它?

例如,在iframe(攻击者将控制)中,添加带有空值的sandbox属性:

<iframe src="Inner.html" sandbox="">

iframe文档

下面是我做的一个示例测试:

Outer.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Outer Html</title>
    </head>
    <body>
        <h1>Outer Html</h1>
        <p>
            Outer Html
        </p>
        <iframe src="Inner.html" width="400" height="300" sandbox="">
            <p>Your browser does not support iframes.</p>
        </iframe>
    </body>
</html>

Inner.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Inner Html</title>
   <script>    
    if (top != self) { top.location.replace(self.location.href); }
</script>
    </head>
    <body>
        <h1>Inner Html</h1>
        <p>
            Inner Html
        </p>
    </body>
</html>

X-Frame-Options

如果你使用X-Frame-Options和JavaScript代码来确保你不在一个帧中,为什么不将值设置为DENY而不是SAMEORIGIN呢?

使用SAMEORIGIN,您的攻击面较小,只有iframe来自您的站点(可能有另一个漏洞)才会成功。如果你不打算在你的网站上做iframe,你不妨选择更安全的X-Frame-Options: DENY

我认为这就是HPE Fortify WebInspect所期望的。

内容安全策略(CSP)框架祖先指令

另一个选项是使用frame-ancestors指令,在HTTP头信息"Content-Security-Policy"中设置"none"值。这将防止(在支持的浏览器中)任何域对内容进行框架化。建议使用此设置,除非确定了框架的特定需要。

大资源

你可以在OWASP的点击劫持防御小抄中找到更多关于预防点击劫持的信息