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();
}
}
版权声明:本文为fly_leopard原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。