解决 Express 或 nginx 站点 iframe 嵌入无法写 Cookie 问题

原创
前端路迹
2021-11-9 20:47
编辑于 2022-6-17 15:20

新版的Chrome下iframe内加载的页面无法写入Cookie,需要嵌入的站点在写Cookie的时候增加 SameSite=none 和 Secure=true。

对于 Express 站点,如果使用的是 express-session ,在其 1.17.0 版本后,支持了配置 sameSite=none,之前的版本是不支持的。

配置如下

测试效果

如果使用 nginx,可以配置 proxy_cookie_path。

location / {
        # your usual config ...
        # hack, set all cookies to secure, httponly and samesite (strict or lax)
        proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
    }
转载请注明出处。本文地址: https://www.qinshenxue.com/article/express-site-iframe-can-not-write-cookies-problem.html
关注我的公众号