在不同环境下添加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
相关推荐:
背景信息: Gitlab Wiki API 是一组用于对Gitlab项目Wiki页面进行创建、编辑、列表、删除等功能的接口。 漏洞描述: 该API在处理外部输入时未做有效过滤,导致攻击者构造特定的恶意请求,可以在目标服务器 …
美国司法部监察长办公室发表报告称,去年黑客利用 Raspberry Pi 入侵了 JPL 的网络。 事故发生在 2018 年 4 月,JPL 的某位出于未知目的把一个 Raspberry Pi 连接到网络中,这个单板电脑与外界互联网的网络 …
webview组件的接口函数addJavascriptInterface存在远程代码执行漏洞,远程攻击者利用此漏洞能实现本地java和js的交互,可以对Android移动终端进行网页挂马从而控制受影响设备。 确保只在访问可信页面数据时 …
Google Project Zero安全团队研究员 Tavis Ormandy 披露了一个微软尚未修复的 Windows 10 0day 漏洞。 Project Zero 的漏洞披露截至时间是 90 天,微软也承诺在 90 天里修复漏洞,但未能兑现,所以在第 91 …
检查行所绑定的行布局文件中是否使用了EditText,如果有的话将EditText的focusable 属性设为false。
拿起手机扫一扫即可带走我!