
SameSite Cookie
概念H2
Secure CookiesH3
标记为 Secure 的 Cookie 只应通过被 HTTPS 协议加密过的请求发送给服务端
SameSiteH3
限制第三方 Cookie
- Strict Cookies只会在第一方上下文中发送,不会与第三方网站发起的请求一起发送
- Lax Cookies允许与顶级导航一起发送,并将与第三方网站发起的GET请求一起发送。这是浏览器中的默认值
- None Cookie将在所有上下文中发送,即允许跨域发送
None 是默认值
变化H2
Chrome 80开始(2020年2月)
SameSite LaxH3
Chrome把没有声明Samesite 的值的Cookie当作SameSite=Lax 来处理。
没有声明Samesite 的值的Cookie当作SameSite=Lax 来处理后,GET请求是可以获取到的。
但是还依赖于chrome://flags->#cookies-without-same-site-must-be-secure 的设置,如果启用的话,没有声明Samesite 的值必须同时设置Secure,否则会被拒接访问。
SameSite=None 需要 SecureH3
如果没有设置 Secure 属性,控制台中可能会出现以下警告:
java
Some cookies are misusing the “sameSite“ attribute, so it won’t work as expected.Cookie “myCookie” rejected because it has the “sameSite=none” attribute but is missing the “secure” attribute.
出现此警告是因为需要 SameSite=None 但未标记 Secure 的任何cookie都将被拒绝。
java
Set-Cookie: flavor=choco; SameSite=None
要解决此问题,必须将 Secure 属性添加到 SameSite=None cookies中。
java
Set-Cookie: flavor=choco; SameSite=None; Secure
结论H2
针对不带SameSite 的Cookie
- disable
chrome://flags->#same-site-by-default-cookies→ 可以第三方iframe访问 - enable
chrome://flags->#same-site-by-default-cookies→ 不可以被第三方iframe访问,但是对于第三方GET请求的访问- enable
chrome://flags->#same-site-by-default-cookies→ 拒接 - disable
chrome://flags->#same-site-by-default-cookies→ 允许
- enable
参考H2
[1]: https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Set-Cookie/SameSite
评论
新的评论
上一篇
storybook pragma and pragmaFrag cannot be set
使用Storybook来渲染Theme UI组件时,报错 React 17支持新的JSX转换, 但是转换本身需要Babel 的 v7.9.0 及以上版本 使用了 "runtime": "automatic" ,在emotion中就不能再以这种方式写了 Storybook使用的B…
下一篇
Bash Startup Files
Shell Interactive Shells /etc/bash.bashrc 、 ~/.bashrc Login Shells /etc/profile 、 ~/.bashprofile, ~/.bashlogin, ~/.profile Non Login Shel…
