当前位置:网站首页>Solve the cross domain problem of the new version of chrome: Cookie loss and samesite attribute problem "recommended collection"
Solve the cross domain problem of the new version of chrome: Cookie loss and samesite attribute problem "recommended collection"
2022-06-27 23:46:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
Recently, when using front and back-end separation development , Encountered a strange problem , Set cross domain anyway , From the same page session Always inconsistent .
Find the problem :
The front and back ends of the login interface are separated ,ajax Error submitting login Verification code interface and login interface session atypism ( Cross-domain problem ) Search the Internet for cross domain issues , To reset , The problem remains.
Troubleshooting :
ajax allow cookie( Have been set xhrFields: { withCredentials: true} ) springboot Tried to set up a variety of cross domain methods (springboot To solve the cross domain )
In depth analysis :
Use other browsers (firefox, ie),session But it's the same
contrast chrome and firefox Request headers and response headers :
firefox: After the first request , Server return sessionId after , After each request cookie They'll bring sessionId. chrome: The request header never carries sessionId, Even the whole cookie All is empty , As a result, the server cannot accept sessionId, It's reassigned every time One individual session.
Explore solutions : Set... In the configuration class SameSite=null:
@Configuration
public class SpringSessionConfig {
@Bean
public CookieSerializer httpSessionIdResolver() {
DefaultCookieSerializer cookieSerializer = new DefaultCookieSerializer();
...
cookieSerializer.setSameSite(null);
...
}
}Be careful , If your project is not done session Distributed management , You may need to introduce the following dependencies to use the above class . As for the difference Chrome For the issue of version number, please refer to this article : About solving Chrome In the new version cookie Cross domain carrying and samesite How to deal with the problem
<!-- https://mvnrepository.com/artifact/org.springframework.session/spring-session-core -->
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>Final solution : When you continue to search for information , Fortunately, I found github On this question :New cross-site cookie not ‘SameSite’ warning in Chrome
See one of the solutions : Ban chrome samesite. The method is as follows : 1. stay chrome Open link in : chrome://flags/#site-isolation-trial-opt-out, Search for samesite
2. Disable the above three options ( Set to disable) Restart after chrome, Problem solving
summary : Existence is reason ,SameSite Is designed to prevent CSRF attack , Ban SameSite It doesn't actually solve the problem , It's the worst policy . Here is my understanding ,SameSite In order to prevent CSRF attack , Strengthened right cookie Management of , Prevent users from carrying cookie Go to a third-party website , And this involves cross domain issues . However , We can't ask users to disable the new version like us chrome Of SameSite, The current proposal is to header Set in samesite, That is to say response.setHeader("Set-Cookie", "HttpOnly;Secure;SameSite=None") after , Use https transmission cookie.
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/133162.html Link to the original text :https://javaforall.cn
边栏推荐
- webserver流程图——搞懂webserver各模块间调用关系
- Feign通过自定义注解实现路径的转义
- SQL中IS NOT NULL与!=NULL的区别
- EasyCVR平台路由日志功能的技术实现过程【附代码】
- 零基础自学SQL课程 | CASE函数
- 【微服务|Sentinel】sentinel数据持久化
- 实践torch.fx:基于Pytorch的模型优化量化神器
- 单细胞数据清洗的这5个步骤你会做吗?
- [sword finger offer] 47 Maximum value of gifts
- [PCL self study: pclvisualizer] point cloud visualization tool pclvisualizer
猜你喜欢

最新云开发微信余额充电器特效小程序源码

Swing UI——容器(一)

How to set the enterprise wechat group robots to send messages regularly?

c语言字符指针、字符串初始化问题

Halcon's region: features of multiple regions (6)

【tinyriscv verilator】分支移植到正点原子达芬奇开发板

Golang - the difference between new and make
![[PCL self study: segmentation4] point cloud segmentation based on Min cut](/img/af/a6c5abf357c1db0718df505499df70.png)
[PCL self study: segmentation4] point cloud segmentation based on Min cut

Stream + Nacos

【PCL自学:PCLVisualizer】点云可视化工具PCLVisualizer
随机推荐
居家办公竟比去公司上班还累?
The choice and trade-off between vector recall and literal recall
【剑指Offer】47. 礼物的最大价值
Zero foundation self-study SQL course | case function
[learn FPGA programming from scratch -48]: Vision - development and application of intelligent sensors
电子科大(申恒涛团队)&京东AI(梅涛团队)提出用于视频问答的结构化双流注意网络,性能SOTA!优于基于双视频表示的方法!
沉寂了一段时间 ,我又出来啦~
The file or assembly 'cefsharp.core.runtime.dll' or one of its dependencies could not be loaded. Is not a valid Win32 Application. (exception from hresult:0x800700c1)
golang使用mongo-driver操作——查(数组相关)
十大券商注册账户安全吗,会有风险吗?
Cornernet understands from simple to profound
VMware virtual machine bridging connectivity
支持删除,更新任意结点的优先级队列
Cornernet由浅入深理解
MySQL删除表后如何使ID从1开始
图的存储结构
超纲练习题不超纲
ClickOnce error deploying ClickOnce application - the reference in the manifest does not match the identity of the downloaded assembly
golang使用mongo-driver操作——查(进阶)
How to solve the problem that the browser developed with CeF3 does not support flash