关于X-Frame-Options

一,什么是X-Frame-Options ?

X-Frame-Options?HTTP 响应头是用来给浏览器指示允许一个页面可否在?<frame>,?<iframe>?或者?<object>中展现的标记。网站可以使用此功能,来确保自己网站的内容没有被嵌到别人的网站中去,也从而避免了点击劫持 (clickjacking) 的攻击。

二,使用方法:

X-Frame-Options有三种可配置值

X-Frame-Options: DENY
X-Frame-Options: SAMEORIGIN
X-Frame-Options: ALLOW-FROM https://example.com/

DENY
表示该页面不允许在 frame 中展示,即便是在相同域名的页面中嵌套也不允许。
SAMEORIGIN
表示该页面可以在相同域名页面的 frame 中展示。
ALLOW-FROM uri
表示该页面可以在指定来源的 frame 中展示。
注: 在网页中设置meta标签是无用的!例如,<meta http-equiv=”X-Frame-Options” content=”deny”>?是没有效果的。不要使用这种方式。需要在下面的配置实例中配置HTTP Header的方式来进行配置,X-Frame-Options才会起作用。

三,常见的生产环境配置

配置 nginx

配置 nginx 发送X-Frame-Options响应头,需要把下面这行添加到 ‘http’, ‘server’ 或者 ‘location’ 的配置中:

add_header X-Frame-Options SAMEORIGIN;

 

关于X-Frame-Options
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Scroll to top
0
Would love your thoughts, please comment.x
()
x