阮大神的博客也有說到這個問題:傳送門
問題的表現(xiàn)
升級到了Chrome 80版本,cookie在跨域的時候會出現(xiàn)問題(主要的場景是開發(fā)環(huán)境本地連接線上的服務器):
來了一個response中有set-cookies,但卻是沒有set進去,而后的http請求中沒有能帶上這些cookie,
Chrome報出警告:
A cookie associated with a cross-site resource at http://xxxx/ was set without the SameSite attribute. It has been blocked, as Chrome now only delivers cookies with cross-site requests if they are set with SameSite=None and Secure. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
問題的原因:
Chrome 80 版本升級,提升了Cookie SameSite的默認安全等級,強推 SameSite Cookie
Chrome <80 默認值:SameSite=None;請求帶Cookie
Chrome >=80 默認值:SameSite=Lax;請限制帶Cookie
SameSite:
SameSite 是 Chrome 51 版本為瀏覽器的 Cookie 新增的了一個屬性, SameSite 阻止瀏覽器將此 Cookie 與跨站點請求一起發(fā)送。其主要目標是降低跨源信息泄漏的風險。同時也在一定程度上阻止了 CSRF(Cross-site request forgery 跨站請求偽造)。
Cookie 的SameSite屬性用來限制第三方 Cookie,從而減少安全風險。
它可以設置三個值:
Strict
Lax
None
在Chrome 80 以上的版本,它默認設置為Lax

我的解決辦法是將sameSite設置為disabled:
1、地址欄輸入:chrome://flags
2、搜索:SameSite by default cookies
3、選擇:disabled

4、重啟瀏覽器