【问题标题】:How to set SAMESite cookie to none in spring boot?如何在 Spring Boot 中将 SAMESite cookie 设置为 none?
【发布时间】:2021-09-29 22:48:12
【问题描述】:

我在 两(2) 个不同的服务器上部署了带有 reactjs(frontEnd) 和 springboot(Backend) 的网络应用程序。

它们都是 http 服务器而不是 HTTPS

我搜索了所有与此相关的 stackoverflow 问题,但似乎都没有。

使用 spring-session 依赖或 Spring-security 依赖。

为了维护用户会话,我只是在制作我的 bean @SessionScoped,如果一切都在 同一台服务器上,它工作正常,但在 不同的服务器上它有坏了

浏览器给出了这个错误,因为 can't set samesite=none, over http for this https is required

那么解决这个问题的方法是什么。因为我现在不能让我的服务器成为 https。

【问题讨论】:

    标签: java spring-boot session samesite


    【解决方案1】:

    我使用 ResponseCookie 解决了这个问题。见下文:

    final ResponseCookie responseCookie = ResponseCookie
                    .from("test", "test")
                    .secure(true)
                    .httpOnly(true)
                    .path("/")
                    .maxAge(12345)
                    .sameSite("None")
                    .build();
            response.addHeader(HttpHeaders.SET_COOKIE, responseCookie.toString());
    

    Cookie 名称:test 和值:test。

    需要设置secure true才能使用sameSite("None")。

    这应该会保存您的 Cookie

    【讨论】:

      猜你喜欢
      • 2021-01-11
      • 2019-12-18
      • 2021-07-22
      • 2019-04-02
      • 1970-01-01
      • 1970-01-01
      • 2020-09-01
      • 2020-10-15
      • 2020-05-17
      相关资源
      最近更新 更多