springboot + springsecurity + thymeleaf (版本2.2.6)
嵌套iframe中出现:127.0.0.1/localhost 将不允许 Firefox 显示嵌入于其他网站的页面
点击了解详细信息:https://developer.mozilla.org/de/docs/Web/HTTP/Headers/X-Frame-Options
提示需要将服务器端页面返回响应头增加:X-Frame-Options
// deny 不允许iframe嵌套
X-Frame-Options: deny
// sameorigin 允许同源嵌套
X-Frame-Options: sameorigin
// 允许指定地址嵌套
X-Frame-Options: allow-from https://example.com/
在WebSecurityConfigurerAdapter实现类中增加配置如下:
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
...省略...
@Override
protected void configure(HttpSecurity http) throws Exception {
...省略...
// 同源头
http.headers().frameOptions().sameOrigin();
}
}
本文介绍如何在SpringBoot项目中使用SpringSecurity与Thymeleaf,解决iframe嵌套引起的X-Frame-Options安全问题,通过配置WebSecurityConfigurerAdapter实现类,确保页面能在iframe中正确加载。
2279

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



