Cookie set on root domain not available to subdomain - what am I doing wrong?

戏子无情 提交于 2021-02-11 15:14:29

问题


Client hosted on subdomain.example.com makes api call to example.com to fetch a cookie. The response has a Set-cookie header and I see the cookie as being returned alright:

However, I don't see the cookie saved in the Browser (Chrome, Firefox, Edge) and, as a result, is not sent as a header in subsquent API requests:

Set-cookie domain attribute is set to .example.com, but as I read in MDN I think the trailing dot gets ignored.

The cookie in question, by the way, is the csrf token secret set by the csurf library.

What am I doing wrong? I have been troubleshooting for 3 evenings now, I don't have a clue yet. seems to be same question as [0] but that one is unanswered. Thanks!

[0] Set cookie from subdomain to root domain and all subdomains


回答1:


Clearly I didn't have a good enough understanding of cors - [0] put me on the right track. It was due to not doing doing the AJAX request with withCredentials client side and credentials: true because I am setting an origin since server in example.com in not the same as subdomain.example.com. Hope it is helpful

[0] https://stackoverflow.com/a/60142012/3630417



来源:https://stackoverflow.com/questions/63513651/cookie-set-on-root-domain-not-available-to-subdomain-what-am-i-doing-wrong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!