当前位置:网站首页>chrome浏览器跨域Cookie的SameSite问题导致访问iframe内嵌页面异常
chrome浏览器跨域Cookie的SameSite问题导致访问iframe内嵌页面异常
2020-11-07 18:55:00 【麦漁翁】
Indicate whether to send a cookie in a cross-site request by specifying its SameSite attribute
问题还原
原先一直访问正常的系统,最近打开页面一直加载不出来。
- 初步分析,该系统为iframe内嵌第三方系统页面,将iframe中的链接复制出来可以单独访问,排除第三方系统的问题。
- 进一步尝试,将这个带有链接的iframe放在一个全新的html文件中也不能正常访问,排除当前系统的iframe加载问题。
- 发现问题,将刚刚新建的html文件再火狐浏览器中打开可以正常访问。 最后定位是浏览器兼容性问题,当前浏览器:Google Chrome ,版本85.0.4183.102(正式版本) (64 位)。
打开浏览器控制台发现接口请求报500错,控制台出现以下提示(Indicate whether a cookie is intended to be set in a cross-site context by specifying its SameSite attribute):
原因分析
Google 在2020年2月4号发布的 Chrome 80 版本(schedule:https://www.chromestatus.com/features/schedule)中默认屏蔽所有第三方 Cookie,即默认为所有 Cookie 加上 SameSite=Lax 属性(https://www.chromestatus.com/feature/5088147346030592),并且拒绝非Secure的Cookie设为 SameSite=None(https://www.chromestatus.com/feature/5633521622188032)
SameSite的作用就是防止跨域传送cookie,从而防止 CSRF 攻击和用户追踪,此举是为了从源头屏蔽 CSRF 漏洞。
关于 SameSite 属性的介绍,可参考阮一峰的《Cookie 的 SameSite 属性》。
上述问题中,在当前系统访问第三方系统时,带了一些cookie过去,然后被这个SameSite机制拦截掉了。
可能在 Chrome 80 中受到影响的场景如下
组件数据基于第三方网站的登录态返回相关用户数据的API请求
HTTP 本地部署
解决方案
- Chrome浏览器打开新标签页,地址栏中分别输入
chrome://flags/#same-site-by-default-cookies
chrome://flags/#cookies-without-same-site-must-be-secure
然后如上如图所示将这两个配置均设置为Disabled
-
不使用谷歌浏览器或者将谷歌浏览器降级到 Chrome 79 及以下版本,并关闭自动更新。
-
将两个系统部署在同一台服务器,通过相同IP同源策略传送cookie。
-
购买SSL证书,升级HTTP服务,将 API 切换为 HTTPS 协议请求,并且检查响应头中的 Set-Cookie 中是否包含了 SameSite=None 和 Secure字样。
版权声明
本文为[麦漁翁]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/3204029/blog/4707684
边栏推荐
- C語言重點——指標篇(一文讓你完全搞懂指標)| 從記憶體理解指標 | 指標完全解析
- ImageMagick - 添加水印
- 南京标志设计,logo设计公司
- 嘉宾专访|2020 PostgreSQL亚洲大会中文分论坛:岳彩波
- RFID fixed assets management system for fire equipment
- 7. Swarm builds clusters
- 谈了多年的数字化转型,为什么还有很多企业依然“口头管理”
- Git submission specification
- Git SSH bad permissions
- PHP security: the past and present of variables
猜你喜欢
vue踩坑:axios使用this指针
频收罚单的浦发银行:增收不增利,曾遭骗贷数亿元,内控缺位?
PHP backdoor hiding skills
甘特图对活动进行分组教程
Using rabbitmq to implement distributed transaction
谈了多年的数字化转型,为什么还有很多企业依然“口头管理”
9. Routingmesh service communication between clusters
How to solve the problem of blank page in Google Chrome browser
PHP安全:变量的前世今生
ImageMagick - 添加水印
随机推荐
How to solve the problem of blank page in Google Chrome browser
如何解决谷歌Chrome浏览器空白页的问题
VARCHART XGantt如何在日历上表示工作日
【涂鸦物联网足迹】物联网主流通信方式
How to create an interactive kernel density chart
8. Swarm creates maintenance and horizontal extension service
Kubernetes (1): introduction to kubernetes
PHP后门隐藏技巧
三步轻松理解Kerberos协议
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Blazor 準備好為企業服務了嗎?
New features of vue3
C語言重點——指標篇(一文讓你完全搞懂指標)| 從記憶體理解指標 | 指標完全解析
Insomnia all night
[original] the impact of arm platform memory and cache on the real-time performance of xenomai
Application layer software development Godfather teaches you how to refactor, senior programmers must professional skills
嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:王旭
Using JSON webtoken (JWT) to generate token in nodejs
使用RabbitMQ实现分布式事务
条形码识别器Dynamsoft Barcode Reader v7.5全新上线!