when backend and frontend domains differ the decision if the cookies will be saved in frontend domain cookie storage from received response is brought by the browser. Browser will allow sending cookies ONLY if XHR request has
withCredentials=trueand correct server Cookie attributes (HTTP Set-Cookie header) are recievedwhen backend and frontend domains differ the decision if the cookies will be sent within request is brought by the browser. Browser will allow this ONLY if XHR request has
withCredentials=truein other words, if
withCredentials=trueis ommited - cookies won't be sent within request NOR will be recieved and saved from responserecieved cookies are allways stored under frontend domain name in browser cookie storage. In case when server domain differs and cookies are saved successfully, the effect is the same as if they have been sent by frontend domain in the first place.
if
SameSite=Nonecookie attribute is omitted today's browser (Firefox/Chrome) will use defaultLaxmode which is too strict for cross site cookiesif
Securedcookie attribute is ommited - thenSameSite=Nonewill be ignored - it requiresSecuredto be setfor localhost
Securedcookie property browser does not require HTTPS / SSL, http will work - no need to serve frontend or backend underhttps://localhost ...EDIT 2022-03-02 - For Safari (v15.1) this is not true -> in Safari http://localhost + cookie with Secure - the cookie will be ignored, not saved in browser (solution: for Safari + http://localhost remove Secure and SameSite if provided).
EDIT 2022-03-02 - For Safari (v15.1) this is not true -> in Safari http://localhost + cookie with Secure - the cookie will be ignored, not saved in browser (solution: for Safari + http://localhost remove Secure and SameSite if provided).
EDIT 2023-01-13 - @Barnaby reported that "Firefox refuses to set it: 'has been rejected because a non-HTTPS cookie can’t be set as “secure”.'" If this is the case - solution as for Safari should work (see EDIT 2022-03-02 above).