Search code examples
cookiesfirefox-addonsetcookie

Firefox extension/addon does not store cookies


I'm working on an browser extension that authenticates with a remote server via XMLHttpRequests. In Firefox (59.0.2) I have the problem that the session cookie send by the server is not stored in the browser. When looking at the network traffic I get a Set-Cookie response from the server for every request:

Set-Cookie JSESSIONID=node01abks2u96hf84wt0i1uqwsb9879.node0;Path=/

but it seems that the cookie is never accepted or stored in the extension.

When looking at Chrome (where the extension is working) my extension includes this cookie in the request:

Cookie: io=jCX1X9rlaOhCqE0nAAAB JSESSIONID=node01abks2u96hf84wt0i1uqwsb9879.node0

However, this is not the case in Firefox. Why is Firefox is not including the cookie in the request? and why is it not storing the cookie?

UPDATE: as suggested I filed a bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=1454806

Furthermore, I created a very minimal example addon that fails: https://gitlab.com/czeidler/firefox-cookie-problem Could somebody please let me know if that addon really should work? or am I doing something wrong? To trigger the problem open the debug view of the addon and select the network view. Then click the addon popup icon. This will trigger two requests to my server. The first reply contains a Set-Cookie header that is not reused in the second request.


Solution

  • I found the reason why it is not working. Firefox handles a request from the popup as a cross domain request and does not set the cookie for this reason. Not sure if Chrome and Firefox should behave the same here or which approach is the better one. Here is how I fixed this issue to make it work in both browsers:

    On the server:

    response.addHeader("Access-Control-Allow-Origin", request.getHeader("Origin")) response.addHeader("Access-Control-Allow-Credentials", "true")

    In the popup:

    connection.withCredentials = true;