当前位置:网站首页>chrome浏览器跨域Cookie的SameSite问题导致访问iframe内嵌页面异常
chrome浏览器跨域Cookie的SameSite问题导致访问iframe内嵌页面异常
2020-11-07 18:55:23 【麦漁翁】
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++ 数字、string和char*的转换
- C++学习——centos7上部署C++开发环境
- C++学习——一步步学会写Makefile
- C++学习——临时对象的产生与优化
- C++学习——对象的引用的用法
- C++编程经验(6):使用C++风格的类型转换
- Won the CKA + CKS certificate with the highest gold content in kubernetes in 31 days!
- C + + number, string and char * conversion
- C + + Learning -- capacity() and resize() in C + +
- C + + Learning -- about code performance optimization
猜你喜欢
-
C + + programming experience (6): using C + + style type conversion
-
Latest party and government work report ppt - Park ppt
-
在线身份证号码提取生日工具
-
Online ID number extraction birthday tool
-
️野指针?悬空指针?️ 一文带你搞懂!
-
Field pointer? Dangling pointer? This article will help you understand!
-
HCNA Routing&Switching之GVRP
-
GVRP of hcna Routing & Switching
-
Seq2Seq实现闲聊机器人
-
【闲聊机器人】seq2seq模型的原理
随机推荐
- LeetCode 91. 解码方法
- Seq2seq implements chat robot
- [chat robot] principle of seq2seq model
- Leetcode 91. Decoding method
- HCNA Routing&Switching之GVRP
- GVRP of hcna Routing & Switching
- HDU7016 Random Walk 2
- [Code+#1]Yazid 的新生舞会
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- HDU7016 Random Walk 2
- [code + 1] Yazid's freshman ball
- CF1548C The Three Little Pigs
- HDU7033 Typing Contest
- Qt Creator 自动补齐变慢的解决
- HALCON 20.11:如何处理标定助手品质问题
- HALCON 20.11:标定助手使用注意事项
- Solution of QT creator's automatic replenishment slowing down
- Halcon 20.11: how to deal with the quality problem of calibration assistant
- Halcon 20.11: precautions for use of calibration assistant
- “十大科学技术问题”揭晓!|青年科学家50²论坛
- "Top ten scientific and technological issues" announced| Young scientists 50 ² forum
- 求反转链表
- Reverse linked list
- js的数据类型
- JS data type
- 记一次文件读写遇到的bug
- Remember the bug encountered in reading and writing a file
- 单例模式
- Singleton mode
- 在这个 N 多编程语言争霸的世界,C++ 究竟还有没有未来?
- In this world of N programming languages, is there a future for C + +?
- es6模板字符
- js Promise
- js 数组方法 回顾
- ES6 template characters
- js Promise
- JS array method review
- 【Golang】️走进 Go 语言️ 第一课 Hello World
- [golang] go into go language lesson 1 Hello World