異常提示
This setcookie was blocked because it had the "samesite=none" attribute but did not have the "secure" attribute, which is required in order to use "same=none"
SameSite
SameSite 有3個可選值 :
- Strict 禁止第三方 cookie
- Lax
- None 關閉 SameSite 選項.
其實在谷歌升級后呢,默認限制了跨域攜帶cookie給后端,在使用samesite=none后其實不僅僅如此,我們還需要設置Secure
屬性才可以生效,但是對於項目中有些不可告人的秘密,哈哈哈哈哈,所以此處不從項目中修改了我們將修Nginx服務器來解決SameSite的問題。
Nginx proxy_cookie_path
具體配置方法(在location節點下加入,配置后重載Nginx):
- 站點Cookie所在目錄在根目錄/下,設置如下:
proxy_cookie_path / "/; secure; SameSite=None";
- 站點Cookie所在目錄在abc目錄下,設置如下:
proxy_cookie_path /abc/ "/abc/; secure; SameSite=None";
- 如果無法確定站點Cookie目錄,可使用Chrome開發者工具,監測Network下網絡請求,找到Response Headers中set-cookie屬性值,該值中有path屬性值即為Cookie目錄,也即上文要替換的/或者/abc/值。
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cookie_path
https://docs.microsoft.com/zh-cn/aspnet/samesite/system-web-samesite