• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Webapp session cookies losing domain value when called over AJAX.

 
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm hoping someone can help me out with this as I'm a little rusty when it comes to ajax requests. I'm working on a webapp (Tomcat is embedded) where we want to allow the user to login via an ajax call.

Let's say the user is on http://www.mysite.com/anypage and clicks to login, a popup opens asking for creds, that form submits via ajax to https://www.mysite.com/do_login_process_url which in turn verifies credentials and returns a response including the Tomcat JSESSIONID cookie and ROUTEID cookie. When hitting the login url directly I get the correct response with cookies, when hitting it via ajax I get the correct response with cookies EXCEPT the cookies domain value is blank and therefore not associated with mysite.com which leads to the user not getting updated as logged in. Any advise?

To note I did post a question on StackOverflow 2 days ago but have received no answers.
 
Marc Cracco
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To put a little bit more detail on this. I am aware that this (http to https) XMLHttpRequest is considered different origin according to the same-origin policy. I am making use of the cross-origin resource sharing mechanism by adding a header to the response "Access-Control-Allow-Origin" with my http domain name. This seems to enable me to get the response accordingly but this is when the cookie domain return blank.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect that from the point of view of cookies, they are different domains. Whether you are using CORS or not may not affect this. The cookies, and therefore the session, may not be shared across the different domains.
 
Marc Cracco
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:From the point of view of cookies, they are different domains. Whether you are using CORS or not does not affect this. The cookies, and therefore the session, will not be shared across the different domains.



The TOMCAT cookie is never set to include http or https so it's the same domain. It just returns a cookie with domain set to mysite.com and the cookie is used on both http and https pages afterwards. If it were considered different domain then why would the same cookie that I normally get on an http page also work on an https one? My problem here isn't that they are different domains, it's that the domain value isn't being set.
 
Marc Cracco
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Further look into this seems to show that Firefox sets the domain correctly yet chrome does not. Interestingly enough is that while the response in firefox shows the cookies they are not being stored.
 
Marc Cracco
Ranch Hand
Posts: 80
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So here it is... this can be done:

had to add



as an ajax param
and



as my response headers
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for posting back with your findings.
 
Marc Cracco
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Thanks for posting back with your findings.



Anytime.
 
Marc Cracco
Ranch Hand
Posts: 80
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More documentation for those who might have similar issues.

JQuery Ajax Documentation

Mozilla Article on CORS that led me to figure out my answer.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have been granted a cow for your follow-up. It could save people in the same situation hours and hours of time. Thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic