cookie
Domain
domain 是可以跨域的,只要设置顶级域名,子域名都可以用。但是跨域名就不行了。
Path
Expires 日期字符串(GMT),老浏览器
Max-Age 类型秒,3600(1h),86400(1天),604800(7天)
Secure 只在 HTTPS 下发送 cookie
HttpOnly JS 无法通过 document.cookie 访问
SameSite
- Strict :只有允许 用户主动顶级导航
- Lax:会拒绝 img、iframe、script、fetch
- None:不做任何限制,但必须是 https
Priority cookie 优先级
cookie 域条件
Set-Cookie:
SameSite=None
Secure1
2
3
2
3
前端需带上 cookie
ts
fetch(url, {
credentials: "include"
})1
2
3
2
3
ts
axios({
withCredentials: true
})1
2
3
2
3
后端运行跨域
Access-Control-Allow-Origin: http://localhost:3000
Access-Control-Allow-Credentials: true1
2
2