1

I'm facing some issues while trying to work with cookie in distincts domains. In my scenario I have two apps (app1 and app2). Basically, the app1 is doing an ajax request to the app2 in order to this one creates a cookie (i.e. dummyCookie). The app2 is an application running over the Play framework 2.5 for Java. I'm creating the cookie like this:

response().setCookie(Http.Cookie.builder("dummyCookie", "9e0a6b4c-58ed-b700-0000-015ec494956").build());

I'm using the plays's CORSFilter:

package myCustomFilters.filters;

import play.filters.cors.CORSFilter;
import play.http.DefaultHttpFilters;

import javax.inject.Inject;

public class Filters extends DefaultHttpFilters {

    @Inject
    public Filters(CORSFilter corsFilter) {
        super(corsFilter);
    }
}

In my application.conf I have this configuration:

play.http.filters = "myCustomFilters.Filters"

play.filters {
  cors {
    pathPrefixes = ["/"]
    allowedOrigins = null
    allowedHttpMethods = ["POST, GET, PUT, DELETE, OPTIONS"]
  }
}

In the Chrome's console, in the Network tab, I could see the cookie in the response header.

enter image description here

If I check the Application tab, Cookies session, I couldn't see the cookie there:

enter image description here

I did some investigations and maybe the problem is related to the scenario "CORS + AJAX", since that I have one application calling (via ajax request) the another one to generate a cookie.

Guys, somebody already faced with this kind of scenario?

sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
vallim
  • 308
  • 2
  • 12

1 Answers1

0

I had similar issues. I had to tweak the configuration in different ways to make that work in Chrome. And client request also need some specific changes (I use JQuery, and this kind of approach was necessary : Sending credentials with cross-domain posts?).

However, in the end, I discovered that Safari would most likely never work for me, as Apple now has specific rules to handle when cookies can be sent cross domain or not. Depending on what you are trying to achieve, this might lead you to consider a totally different approach.

blackbox
  • 671
  • 6
  • 18