【发布时间】:2020-05-12 14:02:49
【问题描述】:
我正在使用 Spring 4,并使用 request.getSession() 创建一个会话
我观察到创建了一个 SESSION cookie。响应头包含如下内容:
Set-Cookie: SESSION=ZTgwZWMxMDItOTA1MC00ZTZjLWIxMmUtZmM3NmQxNzJmNDBm; Path=/myApp/; Secure; HttpOnly
在创建的 Cookie 中,我需要 SameSite=Lax。目前,SameSite 没有价值。
所以在我的代码中,我做了以下尝试覆盖 SESSION cookie。
// request is of type HttpServletRequest
// response is of type HttpServletResponse
HttpSession session = request.getSession();
String base64value = Base64.getEncoder().encodeToString(session.getId().getBytes());
response.setHeader("Set-Cookie","SESSION=" + base64value + ";path=/myApp/ ;HttpOnly ;Secure;SameSite=lax");
但现在创建了 2 个 SESSION cookie,并且可以在响应标头中看到:
Set-Cookie: SESSION=ZTgwZWMxMDItOTA1MC00ZTZjLWIxMmUtZmM3NmQxNzJmNDBm;path=/myApp/ ;HttpOnly ;Secure;SameSite=lax
Set-Cookie: SESSION=ZTgwZWMxMDItOTA1MC00ZTZjLWIxMmUtZmM3NmQxNzJmNDBm; Path=/myApp/; Secure; HttpOnly
Spring 4 中的 SameSite=Lax 如何只有 1 个 SESSION cookie?
【问题讨论】:
标签: java spring tomcat cookies spring-4