针对问题:
防止网页被Frame,虽然我也不知道有啥好Frame的(我理解是在some-hack-web.com上Frame淘宝的页面,然后在密码框之类的控件上加一个隐藏的Frame,然后账号密码信息直接发送到some-hack-web.com而不是淘宝)
解决方案:
在web.xml中加入一个Filter:
<filter>
<filter-name>httpHeaderSecurity</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
<init-param>
<param-name>antiClickJackingOption</param-name>
<param-value><strong>SAMEORIGIN</strong></param-value> //可以根据需要,DENY不允许任何网页嵌入,SAMEORIGIN只允许同域名,ALLOW-FROM uri只允许指定URI
</init-param>
</filter>
<filter-mapping>
<filter-name>httpHeaderSecurity</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>加入前,Http请求的响应是:
加入后,Http请求的相应是:
测试环境:tomcat7.0.70成功,但是7.0.62不行,如果在7.0.62的web.xml中加入,则webapp起不来。
实际测试:
例如汽车之家,貌似页面返回没有这个选项,因此可以被嵌入iframe中,测试代码:
<html>
<head>
</head>
<body>
<iframe width=900 height=500 src="http://account.autohome.com.cn/"><iframe>
</body>
</html>页面:
屏蔽iframe的效果:(我没找到哪个著名的网站加了这个参数,下面这个例子frame了我们自己的内网应用)
本文介绍了一种防止网页被恶意嵌入Frame的方法。通过在web.xml文件中配置HttpHeaderSecurityFilter过滤器,并设置antiClickJackingOption参数为SAMEORIGIN,可以限制网页仅在同一域名下被嵌入。此方法已在Tomcat7.0.70环境下验证有效。

被折叠的 条评论
为什么被折叠?



