Languages

Tomcat handle subdomains with 1 session error - java.lang.IllegalArgumentException: An invalid domain [.localhost] was specified for this cookie, Rfc6265CookieProcessor.java:210

1 points
Asked by:
Marcin
2544

I try to setup tomcat to handle subdomains with 1 session and got this error after I added new parameters to context.xml file in tomcat.

Error:

java.lang.IllegalArgumentException: An invalid domain [.localhost] was specified for this cookie
org.apache.tomcat.util.http.Rfc6265CookieProcessor.validateDomain(Rfc6265CookieProcessor.java:210)
org.apache.tomcat.util.http.Rfc6265CookieProcessor.generateHeader(Rfc6265CookieProcessor.java:145)

Context.xml file location:

apache-tomcat-8.5.45/conf/context.xml

Before:

<Context>

</Context>

After:

<Context sessionCookiePath="/" sessionCookieDomain=".localhost">

</Context>

How to solve this exception?

1 answers
3 points
Answered by:
Marcin
2544

Quick fix:

<Context sessionCookiePath="/" sessionCookieDomain=".localhost">

  <!-- Use Legacy Cookie Processor, newer tomcat version implements Rfc6265 which causes our error -->
  <CookieProcessor className="org.apache.tomcat.util.http.LegacyCookieProcessor" />

</Context>

We just need to tell tomcat to use LegacyCookieProcessor as newer tomcat version implements Rfc6265 specification which causes our error.

I don't know if browser will let you set JSESSIONID for localhost subdomains. For domain with sub-domains it will work.

For example when we use:

sessionCookieDomain=".test123.com"

instead of .localhost then it will work and share JSESSIONID between all subdomains, eg:

  • de.test123.com
  • ru.test123.com
  • etc

I found interesting articles, related to this topic:

0 comments Add comment
Native Advertising
50 000 ad impressions - 449$
ūüöÄ
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

‚̧ԳŹūüíĽ ūüôā

Join