gpt4 book ai didi

spring-boot - 如何在 Spring Boot 中设置同站 cookie 标志?

转载 作者:行者123 更新时间:2023-12-04 02:53:28 33 4
gpt4 key购买 nike

是否可以设置Same-Site Cookie Spring Boot 中的标志?

我在 Chrome 中的问题:

A cookie associated with a cross-site resource at http://google.com/ was set without the SameSite attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with SameSite=None and Secure. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.



如何解决这个问题呢?

最佳答案

这是 Spring Security 的一个悬而未决的问题 ( https://github.com/spring-projects/spring-security/issues/7537 )

正如我在 Spring-Boot ( 2.1.7.RELEASE ) 中检查的那样,默认情况下它使用 DefaultCookieSerializer携带属性(property)sameSite默认为 Lax .

您可以通过以下代码在应用程序启动时修改它。

注意:这是一个黑客,直到真正的修复(配置)在下一个 Spring 发布时公开。

@Component
@AllArgsConstructor
public class SameSiteInjector {

private final ApplicationContext applicationContext;

@EventListener
public void onApplicationEvent(ContextRefreshedEvent event) {
DefaultCookieSerializer cookieSerializer = applicationContext.getBean(DefaultCookieSerializer.class);
log.info("Received DefaultCookieSerializer, Overriding SameSite Strict");
cookieSerializer.setSameSite("strict");
}
}

关于spring-boot - 如何在 Spring Boot 中设置同站 cookie 标志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58386069/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com