在不同环境下添加X-Frame-Options保护的方法

首先我们来看一段关于框架劫持的安全说明。

The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a<frame>, <iframe> or <object> . Sites can use this to avoid clickjacking attacks, by ensuring that their content is not embedded into other sites.

Using X-Frame-Options
There are three possible values for X-Frame-Options:

DENY
The page cannot be displayed in a frame, regardless of the site attempting to do so.
SAMEORIGIN
The page can only be displayed in a frame on the same origin as the page itself.
ALLOW-FROM uri
The page can only be displayed in a frame on the specified origin.
In other words, if you specify DENY, not only will attempts to load the page in a frame fail when loaded from other sites, attempts to do so will fail when loaded from the same site. On the other hand, if you specify SAMEORIGIN, you can still use the page in a frame as long as the site including it in a frame is the same as the one serving the page.

文章里写到,在未设置相关的框架保护下,容易导致页面劫持,但是设置了框架的保护后并采用上述的三种保护方法中的任一种后,安全漏洞就得到了缓解,但是不同的平台有不同的方法。

Apache:

在配置文件中增加:

Header always append X-Frame-Options SAMEORIGIN

即可

Nginx:

同样在配置文件中增加:

add_header X-Frame-Options SAMEORIGIN

即可。

Tomcat:

这个比较特别,需要在页面里指定,当然也可以在web.xml里配,但是相当地复杂。

如在每个页面里增加:

response.addHeader( "X-Frame-Options", "SAMEORIGIN" )

xml的配置请看:https://www.owasp.org/index.php/Clickjacking_Protection_for_Java_EE。

IIS:

增加配置:

<system.webServer>
...

<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="SAMEORIGIN" />
</customHeaders>
</httpProtocol>

...
</system.webServer>

即可。

HAProxy:

增加:

rspadd X-Frame-Options:\ SAMEORIGIN

即可。

好了,请开始配置吧。

参考内容:

https://www.owasp.org/index.php/Clickjacking_Protection_for_Java_EE
https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options
http://stackoverflow.com/questions/6666423/overcoming-display-forbidden-by-x-frame-options
相关推荐:
Xshell 是一款非常出色的免费SSH客户端。它功能强悍,具备标签式的环境,动态端口转发,自定义键的映射关系,用户定义的按钮,支持VB脚本,支持UNICODE,支持SSH1、 SSH2, 以及Microsoft Windows 平台的TEL …
MindManager,中文商标译作C,俗称“脑图”,是一款创造、管理和交流思想的通用标准的绘图软件,由美国Mindjet公司开发,界面可视化,有着直观、友好的用户界面和丰富的功能, 这将帮助您有序地组织您的思维 …
将本机80端口的请求转发到8080端口 #shell#iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080 如果需要本机也可以访问,则需要配置OUTPUT链 #shell#iptables -t nat -A OUTPUT …
当你的控制台上找不到错误或者看不懂错误的时候,点 Project-->clean,清空下项目就会没问题。
OhSoft的主要产品oCam是一个功能强大的视频录制程序,可以录制视频,通过您的个人电脑在显示器上播放。 长期以来,世界上有很多人使用这个解决方案,所以这个方案得到了优化。该解决方案可以有效地录制包括 …
拿起手机扫一扫即可带走我!