背景

在接入内容平台的时候, 内容平台使用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
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

拒绝了我们的连接请求相关推荐

  1. vscode调试html页面status200无法访问此网站 localhost 拒绝了我们的连接请求

    vscode使用debugger for chrome调试web项目和报错解决办法 vscode调试html页面status200无法访问此网站 localhost 拒绝了我们的连接请求 vscode ...

  2. 无法访问此网站 localhost 拒绝了我们的连接请求。

    使用linux下的ssh或者windows下的xshell远程了服务器之后, 使用jupyter notebook命令想在本地浏览器打开服务器的jupyter, 复制login的链接如:http:// ...

  3. 【s3.amazonaws.com】【github.com】拒绝了我们的连接请求-解决方案

    Q: 类似问题 github-production-release-asset-2e65be.s3.amazonaws.com 拒绝了我们的连接请求 github.com 拒绝了我们的连接请求 在Gi ...

  4. 127.0.0.1 拒绝了我们的连接请求--访问本地IP时显示拒绝访问

    问题描述 今天在访问http://127.0.0.1时,浏览器显示"127.0.0.1 拒绝了我们的连接请求",需要设置浏览器设置 解决方法 1.打开控制面板,搜索 "程 ...

  5. 解决vscode进行chrome调试时报错:localhost拒绝了我们的连接请求

    解决vscode进行chrome调试时报错:localhost拒绝了我们的连接请求 只是为了记录,参考博客https://blog.csdn.net/LiBlacksmith/article/deta ...

  6. 嵌入页面拒绝了我们的连接请求

    背景 将Grafana图表使用iframe集成到自己的web项目时出现 "192.168.79.130 拒绝了我们的连接请求" 192.168.79.130为虚拟机地址. 原因 G ...

  7. Mac Tomcat安装 localhost 拒绝了我们的连接请求

    Mac Tomcat安装 localhost 拒绝了我们的连接请求 Mac下安装Tomcat服务器,下载的Tomcat10 在bin目录下,授权 chmod 777 *.sh 启动Tomcat服务 . ...

  8. 启动Jenkins时报错,localhost拒绝了我们的连接请求

    问题:根据文章一路next安装Jenkins下来,使用http://localhost:8080/打开Jenkins的时候报错,提示localhost拒绝了我们的连接请求 找了一下原因 1.重新启动J ...

  9. 【异常解决】vue项目localhost:8080无法访问此网站或者无法访问此页面,localhost拒绝了我们的连接请求

    localhost拒绝了我们的连接请求的解决方案 一.背景描述 二.问题原因 三.解决方案 方案一:重启前端和后端服务 方案二:关闭被占用的端口程序,或者换新的其他端口重启服务 方案三:启动Windo ...

  10. 解决127.0.0.1拒绝了我们的连接请求

    运行Django项目,浏览器显示127.0.0.1拒绝了我们的连接请求 PyCharm后台运行截图 在Google输入前端界面网址截图 在IE输入前端界面网址截图 解决方法 总结 PyCharm后台运 ...

最新文章

  1. 2020 腾讯广告算法大赛:突破高分瓶颈方案分享
  2. Expression Tree 上手指南 (二)
  3. python3 字符串转数组 数组转字符串 切片操作
  4. 面试官问:能否模拟实现JS的new操作符
  5. 几张表格怎么联动_猛男必备具皮肤:和平精英火箭少女联动火爆来袭,这摩托皮不香?...
  6. css中width:100%与width:auto的区别
  7. 如何发送html email,如何发送HTML电子邮件?
  8. Impinj增强ItemSense软件功能,简化RFID方案部署
  9. 深度迁移学习在花生叶部病害图像识别中的应用
  10. 把Chrome浏览器变成文本编辑器
  11. javaweb学生宿舍管理系统
  12. 安卓问题-第三方相关
  13. 服务器ssl证书在哪查看,https证书查看
  14. MySQL基础——多表查询
  15. matlab 二值图像连通区域标记法,一种二值图像连通区域标记的简单快速算法_葛春平...
  16. 依赖多个项目,重复jar包不同版本冲突解决
  17. 大数据之Hadoop生态系统概述
  18. 【MQTT】MQTT协议学习
  19. 工程(二)——DeeplabV3+语义分割训练自制数据集
  20. GIS文件 | EXCEL中打开ShapeFile等GIS文件

热门文章

  1. springboot整合微信公众号(服务号)之消息推送
  2. 科大讯飞2020秋招
  3. 趣学呗老师整理:初中英语60个常见介词短语!
  4. Flowable深入浅出-6 Flowable-Modeler详述之常见问题Table act_ge_property doesn‘t exist
  5. 操作系统(4) 进程同步
  6. 开源一款自用听书App---Ting
  7. 我的2016,我的苦辣酸甜
  8. NGS测序结果中duplicate序列问题的理解
  9. bzoj 2002 Bounce 弹飞绵羊
  10. linux 软件源总结