有一个专门做演讲的网站,重庆网站建设公司有哪些,做图片视频的网站有哪些问题吗,中国互联网协会12321举报中心简介
X-Frame-Options HTTP 响应头用来给浏览器一个指示。该指示的作用为#xff1a;是否允许页面在 frame, /iframe 或者 object 中展现。 网站可以使用此功能#xff0c;来确保自己网站的内容没有被嵌套到别人的网站中去#xff0c;也从而避免了…简介
X-Frame-Options HTTP 响应头用来给浏览器一个指示。该指示的作用为是否允许页面在 frame, /iframe 或者 object 中展现。 网站可以使用此功能来确保自己网站的内容没有被嵌套到别人的网站中去也从而避免了点击劫持 (clickjacking) 的攻击。
重点1当访问网页浏览器支持 X-Frame-Options 时有效。 重点2Content-Security-Policy CSP HTTP 响应头有一个名为 frame-ancestors 的指令有相同的作用。支持CSP frame-ancestors 指令的浏览器已经废弃了 X-Frame-Options 响应头。
语法
X-Frame-Options: DENY或
X-Frame-Options: SAMEORIGIN检查 X-Frame-Options 是否已生效
以Google浏览器为例打开网站按F12键选择Network找到对应的Headers如下图所示
测试 X-Frame-Options 是否已生效
https://clickjacker.io/
Nginx 配置 X-Frame-Options
配置 Nginx 发送 X-Frame-Options 响应头把下面这行添加到 ‘http’, ‘server’ 或者 ‘location’ 的配置中
add_header X-Frame-Options SAMEORIGIN always;了解 Nginx 的 add_header 指令入口
spring boot 配置 X-Frame-Options
启用 X-Frame-Options
支持SAMEORIGIN的设置方式
EnableWebSecurity
Configuration
public class WebSecurityConfig extends DefaultWebSecurityConfigurer {Overrideprotected void configure(HttpSecurity http) throws Exception {super.configure(http);http.headers().frameOptions().sameOrigin();}
}禁用 X-Frame-Options
EnableWebSecurity
Configuration
public class WebSecurityConfig extends DefaultWebSecurityConfigurer {Overrideprotected void configure(HttpSecurity http) throws Exception {super.configure(http);http.headers().frameOptions().disable();}
}参考
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/X-Frame-Options https://blog.csdn.net/zzhongcy/article/details/124609116 https://blog.csdn.net/u014704612/article/details/115633050