如何正确设置JSP中子域的cookie?

Edw*_*win 2 cookies jsp servlets

我有以下设置:

  • 所有请求都是https(我将在下面的描述中省略这一点)
  • 3个docker服务器:本地主机:8090,本地主机:8091,本地主机:8092
  • 在主机(在我的Windows机器上)中,我有3个域:loc.localdomain、loc2.localdomain和loc3.localdomain都指向我的IP地址
  • 所以我将在我的应用程序中使用 localhost:8090 -> loc.localdomain、localhost:8091 -> loc2.localdomain 和 localhost:8092 -> loc3.localdomain

现在我有一个应用程序loc可以为子域设置一些cookie loc3。我看到 cookie 在 chrome 网络响应中设置(或假设设置)。

Set-Cookie: MY_COOKIE=YUMM; domain=loc3.localdomain; 
expires=Fri, 21-Jun-2019 10:48:58 GMT; path=/coolApp/bro
Run Code Online (Sandbox Code Playgroud)

然后在应用程序 atloc我有一个按钮,可以将用户发送到另一个应用程序 at loc2,将用户重定向到loc3at loc3.localdomain:8092/coolApp/bro/something/more。因此,此时我应该在 的应用程序请求中看到 cookie loc3,但我没有。

Cookie 设置:

FacesContext facesContext = FacesContext.getCurrentInstance();
//facesContext.getExternalContext().addResponseCookie("TEST", "TEST", properties); tried this too 
//then in properties will be the maxAge, path and domain set

Cookie cookie = (Cookie) facesContext.getExternalContext().getRequestCookieMap().get("MY_COOKIE");
if(cookie == null){
     cookie = new Cookie("MY_COOKIE", "YUMMM");
}

cookie.setMaxAge(31536000);
cookie.setPath("/coolApp/bro");
cookie.setDomain("loc3.localdomain"); // I've tried ".localdomain" too

HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
response.addCookie(cookie);
Run Code Online (Sandbox Code Playgroud)

知道这个设置有什么问题吗?

Edw*_*win 5

基于此(https://curl.haxx.se/rfc/cookie_spec.html),域应包含至少 2 个点,因此答案是使用 localhost 的其他别名来模拟我的子域。就像是:*.example.com

更改域名后,一切都按预期进行。