Safari 14 - Cookies are not sent for XHR requests on a subdomain

It seems to be a question that comes up often in different ways, but despite several hours of research I still haven't found a solution.

I currently face an issue in Safari 14 on MacOS BigSur where cookies are never sent by Safari on XmlHttpRequests to an api on the same root domain.

Indeed, i'm working on an Angular SPA where the client app is locally hosted at https://myapp.local and for tests purpose I have an api running locally on https://api.myapp.local.

For some requests, we need to attach 2 cookies that are originally set by the API. I am able to see the said cookies in the API responses and in the "storage" section of Safari's DevTools, however they are never sent back to the server for subsequent XHR requests. (XHR with credentials)

I did try different cookie's attributes but none of my tries were successful :
  • sameSite=None, domain=myapp.local, Secure, httpOnly

  • sameSite=Lax, domain=myapp.local, Secure, httpOnly

The only way I found to get around the problem was to disable the "prevent cross-site tracking" option in Safari's privacy settings (which is not a proper solution for our users since this option is enabled by default...)

Nevertheless, I don't understand why Safari consider those cookies as 3rd party cookies (and blocks them) since the API is hosted on the same domain (on a subdomain to be more accurate) than the client web app. And, if I understood correctly, cookies should be sent by browsers for subdomains requests, both with sameSite=Lax and sameSite=None. Especially since it works perfectly on Firefox and Chromium browsers.

Anyway, if anyone has an idea or a solution I would be very interested to hear it because I don't know what to try anymore!

Thanks a lot !

I'm experiencing nearly the exact same issue on a recently resurrected project. Only difference is I'm using http, not https locally, and Safari 15.5.

Everything works fine in Chrome/Firefox, or Safari w/ "Prevent cross-site tracking" disabled.

Hate this inconsistent functionality with Safari. Doesn't happen on iPadOS Safari, either. Been roughly a year here and good solution or informative yet.

What's worse is, for me, this is resulting in a redirect loop at the network level and unfortunately Safari's DevTools interface doesn't even show basic HTTP requests that are pure 301 redirects. This would at least help me confirm that my issue is relating to cookies since then I could see the actual HTTP headers.

From my tests, it has to do with the TLD.

".local" TLD is unknown, and this might cause this.

I have the same setup as you. My development happens on .localdev and I am experience the same issues.

Once I deployed my app on a .com domain, it start working

Safari 14 - Cookies are not sent for XHR requests on a subdomain
 
 
Q