Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome and JSESSIONID

Following problem with chrome...:

I've running an Grails 1.3.7 Application on a Server. I've noticed, when I request a static content (such as non-dynamic html-files) from Chrome, Chrome creates two JSESSIONID-Cookies. The first one when the login-window shows up, and the second after a successfull login. If I want to refresh the page, or request another resource, I've to login again. (I think because Tomcat doesn't understand those two cookies)

I've tried it with FF, but FF just just creates one Cookie and its working perfectly. Also, I've ran the app locally, and it works even with chrome perfectly. So, something with tomecat must be wrong.

Enviroment:

  • Grails-Application 1.3.7 (with Spring-Security-Core 1.2.4)
  • Apache Tomcat 7 (on Windows Server 2008)

My httpd.conf:

ProxyPass /manager http://myUrl:8080/manager
ProxyPass /myGrailsApp http://myUrl:8080/myGrailsApp
ProxyPassReverse /manager http://myUrl:8080/manager
ProxyPassReverse /myGrailsApp http://myUrl:8080/myGrailsApp

ProxyPass / http://myUrl:8080/myGrailsApp/frontend
ProxyPassReverse / http://myUrl:8080/myGrailsApp/frontend

Thanks in advance.

Update 1:

I re-builded, re-deployed the app and restarted tomcat again.

Now I noticed: Chrome doesn't generate two cookies anymore. But the error is the same. Every time I refresh or request something, the JSESSIONID changes and I have to log in again.

A short watch on the tomcat-server displays a big amount of active sessions - those from chrome...

Update 2:

I tried it locally on the server (with chrome):

  • localhost/myApp/frontend => Apache => FAIL
  • localhost:8080/myApp/frontend => Tomcat => OK

It seems like Apache is the problem (?).

Solution:

I've got it :) The Grails *.gsp-Templates always requested the 'favicon.ico' on each request. The reason why the error appeared on static content (like html-files) is because we redirect to those resources from our Grails-Application.

So I've put the favicon.ico in the right place, and now it works :)

This error just concerns Google Chrome, in FF and IE it worked without any problems.

like image 237
Beastcraft Avatar asked Jan 16 '12 13:01

Beastcraft


People also ask

What is Jsessionid used for?

JSESSIONID is a cookie generated by Servlet containers and used for session management in J2EE web applications for HTTP protocol. If a Web server is using a cookie for session management, it creates and sends JSESSIONID cookie to the client and then the client sends it back to the server in subsequent HTTP requests.

Why Jsessionid is appended to the URL?

Ø Why is jsessionid appended to some URLs even after cookies are enabled? Note that even when cookies are enabled, if URLs are being encoded, java application appends jsessionid to all the URLs for the first request.


1 Answers

I also ran into this problem. It took me a while to figure out what was happening (including sniffing with Wireshark), and still more time to find a viable solution. At last I found this thread https://vaadin.com/forum/-/message_boards/view_message/1216366

It seams that this is a problem with Chrome/Safari (Webkit browsers?) and the way they handle redirected cookies. The simple fix was to add a context.xml to the META-INF directory in my spring project containing

<?xml version='1.0' encoding='utf-8'?>
<Context sessionCookiePathUsesTrailingSlash='false'>
</Context>

and then redeploying the new war file. Now everything is working as intended.

like image 118
Marqs Avatar answered Sep 19 '22 13:09

Marqs