拒绝了我们的连接请求
背景
在接入内容平台的时候, 内容平台使用iframe来嵌入ugc的帖子详情页, 让用户可以预览帖子详情。 但是帖子详情页不支持iframe的嵌入, 导致出现如下错误: ”star.aliexpress.com 拒绝了我们的连接请求。“ 具体如下:
image.png
原因
这是因为帖子详情页不支持iframe嵌入, 这个主要是因为spring boot默认为了安全, 默认不让网页支持嵌入, 帮助用户对抗点击劫持。
image.png
解决办法
X-Frame-Options 有三个值:
DENY
表示该页面不允许在 frame 中展示,即便是在相同域名的页面中嵌套也不允许。
SAMEORIGIN
表示该页面可以在相同域名页面的 frame 中展示。
ALLOW-FROM uri
表示该页面可以在指定来源的 frame 中展示。
spring boot支持EnableWebSecurity 这个anotation来设置不全的安全策略。 具体如下:
import com.alibaba.spring.websecurity.DefaultWebSecurityConfigurer;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.header.writers.frameoptions.WhiteListedAllowFromStrategy;
import org.springframework.security.web.header.writers.frameoptions.XFrameOptionsHeaderWriter;import java.util.Arrays;@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends DefaultWebSecurityConfigurer {@Overrideprotected void configure(HttpSecurity http) throws Exception {super.configure(http);//disable 默认策略。 这一句不能省。 http.headers().frameOptions().disable();//新增新的策略。 http.headers().addHeaderWriter(new XFrameOptionsHeaderWriter(new WhiteListedAllowFromStrategy(Arrays.asList("http://itaobops.aliexpress.com", "https://cpp.alibaba-inc.com","https://pre-cpp.alibaba-inc.com"))));}
}
上面是支持ALLOW-FROM uri的设置方式。
其他设置方式比较简单。 下面是支持SAMEORIGIN的设置方式:
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends DefaultWebSecurityConfigurer {@Overrideprotected void configure(HttpSecurity http) throws Exception {super.configure(http);http.headers().frameOptions().sameOrigin();}
}
下面是支持完全放开的方式:
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends DefaultWebSecurityConfigurer {@Overrideprotected void configure(HttpSecurity http) throws Exception {super.configure(http);http.headers().frameOptions().disable();}
}
1人点赞
其他
作者:YDDMAX_Y
链接:https://www.jianshu.com/p/9ec724f4e3ae
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
拒绝了我们的连接请求相关推荐
- vscode调试html页面status200无法访问此网站 localhost 拒绝了我们的连接请求
vscode使用debugger for chrome调试web项目和报错解决办法 vscode调试html页面status200无法访问此网站 localhost 拒绝了我们的连接请求 vscode ...
- 无法访问此网站 localhost 拒绝了我们的连接请求。
使用linux下的ssh或者windows下的xshell远程了服务器之后, 使用jupyter notebook命令想在本地浏览器打开服务器的jupyter, 复制login的链接如:http:// ...
- 【s3.amazonaws.com】【github.com】拒绝了我们的连接请求-解决方案
Q: 类似问题 github-production-release-asset-2e65be.s3.amazonaws.com 拒绝了我们的连接请求 github.com 拒绝了我们的连接请求 在Gi ...
- 127.0.0.1 拒绝了我们的连接请求--访问本地IP时显示拒绝访问
问题描述 今天在访问http://127.0.0.1时,浏览器显示"127.0.0.1 拒绝了我们的连接请求",需要设置浏览器设置 解决方法 1.打开控制面板,搜索 "程 ...
- 解决vscode进行chrome调试时报错:localhost拒绝了我们的连接请求
解决vscode进行chrome调试时报错:localhost拒绝了我们的连接请求 只是为了记录,参考博客https://blog.csdn.net/LiBlacksmith/article/deta ...
- 嵌入页面拒绝了我们的连接请求
背景 将Grafana图表使用iframe集成到自己的web项目时出现 "192.168.79.130 拒绝了我们的连接请求" 192.168.79.130为虚拟机地址. 原因 G ...
- Mac Tomcat安装 localhost 拒绝了我们的连接请求
Mac Tomcat安装 localhost 拒绝了我们的连接请求 Mac下安装Tomcat服务器,下载的Tomcat10 在bin目录下,授权 chmod 777 *.sh 启动Tomcat服务 . ...
- 启动Jenkins时报错,localhost拒绝了我们的连接请求
问题:根据文章一路next安装Jenkins下来,使用http://localhost:8080/打开Jenkins的时候报错,提示localhost拒绝了我们的连接请求 找了一下原因 1.重新启动J ...
- 【异常解决】vue项目localhost:8080无法访问此网站或者无法访问此页面,localhost拒绝了我们的连接请求
localhost拒绝了我们的连接请求的解决方案 一.背景描述 二.问题原因 三.解决方案 方案一:重启前端和后端服务 方案二:关闭被占用的端口程序,或者换新的其他端口重启服务 方案三:启动Windo ...
- 解决127.0.0.1拒绝了我们的连接请求
运行Django项目,浏览器显示127.0.0.1拒绝了我们的连接请求 PyCharm后台运行截图 在Google输入前端界面网址截图 在IE输入前端界面网址截图 解决方法 总结 PyCharm后台运 ...
最新文章
- 2020 腾讯广告算法大赛:突破高分瓶颈方案分享
- Expression Tree 上手指南 (二)
- python3 字符串转数组 数组转字符串 切片操作
- 面试官问:能否模拟实现JS的new操作符
- 几张表格怎么联动_猛男必备具皮肤:和平精英火箭少女联动火爆来袭,这摩托皮不香?...
- css中width:100%与width:auto的区别
- 如何发送html email,如何发送HTML电子邮件?
- Impinj增强ItemSense软件功能,简化RFID方案部署
- 深度迁移学习在花生叶部病害图像识别中的应用
- 把Chrome浏览器变成文本编辑器
- javaweb学生宿舍管理系统
- 安卓问题-第三方相关
- 服务器ssl证书在哪查看,https证书查看
- MySQL基础——多表查询
- matlab 二值图像连通区域标记法,一种二值图像连通区域标记的简单快速算法_葛春平...
- 依赖多个项目,重复jar包不同版本冲突解决
- 大数据之Hadoop生态系统概述
- 【MQTT】MQTT协议学习
- 工程(二)——DeeplabV3+语义分割训练自制数据集
- GIS文件 | EXCEL中打开ShapeFile等GIS文件