spring-session icon indicating copy to clipboard operation
spring-session copied to clipboard

Support for multiple domains when writing the session cookie

Open rwanderc opened this issue 6 years ago • 1 comments

Hi Spring Team,

I came up to a situation where I need to issue the session cookie for 2 different domains. Didn't find that in docs neither in code, since org.springframework.boot.web.servlet.server.Session has only 1 Cookie and org.springframework.session.web.http.DefaultCookieSerializer.writeCookieValue() seems to be called only once and also writes to response once.

Is there a way to do it (maybe I'm missing smth)? Or do you plan to have it soon?

For reference, I found these issues that seem to be diff but related #1323 #297 #299 #162 #955

rwanderc avatar Jun 14 '19 13:06 rwanderc

@rwanderc You can call org.springframework.session.web.http.DefaultCookieSerializer.setDomainNamePattern method and pass it a string like ^(domain1\.example\.com|domain2\.example\.com)$ This will make it extract domain from request, test against provided RegExp pattern, select one of the two values (domain1.example.com or domain2.example.com) and set corresponding domain value for session cookie.

izogfif avatar May 10 '25 22:05 izogfif