正经文章的地方

samesite cookie花式绕过方案

虽然多次提醒了公司同事不要设计iframe,但是难以避免的有一些现有的旧页面还在iframe里。

chrome已在历次更新中多次升级严控iframe的sameSite cookie,非https逐渐要和iframe说拜拜了。

chrome更新说明

The flags #same-site-by-default-cookies
 and #cookies-without-same-site-must-be-secure
 have been removed from chrome://flags as of Chrome 91, as the behavior is now enabled by default. In Chrome 94, the command-line flag –disable-features=SameSiteByDefaultCookies,CookiesWithoutSameSiteMustBeSecure
 will be removed.

chrome91之前,可以通过设置 chrome://flags 中的 #same-site-by-default-cookies 和 #cookies-without-same-site-must-be-secure 关闭(disabled)后,重启浏览器来实现关闭samesite cookie规范,91之后,需要通过命令行开启,94之后,命令行也不可行了。

命令行参考

mac os:

  1. 如果已经启动了Chrome,必须首先在Chrome里按住command+Q键,彻底退出Chrome
  2. 打开MacOS的「启动台」->「其他」->「终端」
  3. 把下列命令粘贴到终端里,按回车,启动Chrome
open -a "Google Chrome" --args --disable-features=SameSiteByDefaultCookies

Windows

  1. 如果已经启动了Chrome,必须首先在Chrome里按Alt+F键然后按X键,彻底退出Chrome
  2. 打开Windows开始菜单 -> 「Windows系统」->「命令提示符」
  3. 把下列命令粘贴到终端里,按回车,启动Chrome
"c:Program FilesGoogleChromeApplicationchrome.exe" --disable-features=SameSiteByDefaultCookies

如果上述命令报错,可以尝试使用下列命令:

"c:Program Files (x86)GoogleChromeApplicationchrome.exe" --disable-features=SameSiteByDefaultCookies