请教, iframe 页面中登录表单提交成功后, cookie 未正常设置

2021 年 3 月 16 日
 gzf6

同一个网页,通过 cookie 中的 session 授权。

正常访问时登录后正常,cookie 正常设置,f12 可以看到有值;

使用 iframe 嵌入到其他页面中时,登录后 cookie 不能正常设置,f12 中值是空的,导致未授权一致卡在登录页面。

2205 次点击
所在节点    程序员
8 条回复
gzf6
2021 年 3 月 16 日
flask 框架,登录用的 flask_login
zythum
2021 年 3 月 16 日
跨域 iframe 要种 cookie 现在得走 https, 并且 cookie 设置 sameSite: none 。
ch2
2021 年 3 月 16 日
你要把一个网站用 iframe 嵌入到别的域名中,就得设置它允许被别人嵌入
chendy
2021 年 3 月 16 日
比较新的浏览器需要 https + Secure + SameSite: None
https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Set-Cookie/SameSite
SmiteChow
2021 年 3 月 16 日
如果我没猜错 是跨域了吧
gzf6
2021 年 3 月 16 日
@SmiteChow 对的,跨域了
lisianthus
2021 年 3 月 16 日
后端返回 header 的 Set-Cookie 字段加上 SameSite=None; Secure; 并且需要 https 协议才会自动带 cookie
SmiteChow
2021 年 3 月 16 日
2020 年 2 月份 从 Chrome v80 起 Cookie 的跨域安全策略有大改动

详细看: https://blog.chromium.org/2019/10/developers-get-ready-for-new.html

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://v2ex.ih06.com/t/762058

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX