我正在运行webinspect应用程序来检测我的应用程序上的安全威胁。检测到的威胁之一是(跨帧脚本),我已经通过添加(X帧选项)标头来修正它(SAMEORIGIN)。现在,当我重新运行网络检查时,它仍然检测到(跨帧脚本),并报告了以下消息:
在将此页加载到框架内时,未观察到一种有效的破坏帧的技术。
我使用了很多块破坏代码,但同样的问题仍然存在。我曾尝试过下列街区杀手:
第一次尝试:
<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;
}发布于 2016-11-01 14:03:56
定义一个“有效的”。
虽然您所呈现的三个JavaScript片段确实有效,但您有没有考虑过阻止这种情况的方法?
例如,在iframe (攻击者将控制的)中,添加带有空值的sandbox属性:
<iframe src="Inner.html" sandbox="">https://www.w3.org/wiki/HTML/Elements/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来自您的站点(可能还有另一个漏洞)。如果您不打算在您的站点上执行iframes,您最好使用更安全的X-Frame-Options: DENY选项。
我认为这就是HPE的预期。
内容安全策略(CSP)帧-祖先指令
另一个选项是使用frame-ancestors指令,在Header‘Content’中使用'none‘值。这将防止(在受支持的浏览器中)任何域对内容进行框架化。建议设置此设置,除非确定了特定的框架需要。
大资源
您可以在OWASP的点击防御备忘单上找到更多关于点击拦截的信息。
https://stackoverflow.com/questions/40339429
复制相似问题