V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
1sm23
V2EX  ›  浏览器

iframe

  •  
  •   1sm23 · 2021-06-07 16:38:20 +08:00 · 1615 次点击
    这是一个创建于 1044 天前的主题,其中的信息可能已经有所发展或是发生改变。
    嵌入在 iframe 里的子页面如果有登陆操作返回 302,但是页面不会跳转
    第 1 条附言  ·  2021-06-08 11:45:32 +08:00
    iframe 跨域 cookie SameSite chrome 4 楼总结了
    6 条回复    2021-06-08 22:55:21 +08:00
    DOLLOR
        1
    DOLLOR  
       2021-06-07 17:30:34 +08:00
    你需要把问题描述具体些。
    控制台打了啥?
    Network 请求记录是怎样的?
    你的“登录”用的是<form>标签+submit 按钮实现的,还是 JS 构造异步请求实现的?
    如果是<form>标签,尝试过设置 target="_top"属性了么?
    如果是 JS 构造异步请求,尝试过 Window.top.location.href 设置页面跳转地址了么?
    1sm23
        2
    1sm23  
    OP
       2021-06-07 18:07:28 +08:00
    @DOLLOR #1 是第三方子页面,可能没办法修改,看了下好像是用的<form>+submit,看了你的回复试了下 target="_top"好像不行
    1sm23
        3
    1sm23  
    OP
       2021-06-07 18:11:22 +08:00
    @DOLLOR #1 返回 302 Found
    fetch("http://192.168.1.28:14000/login", {
    "headers": {
    "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
    "accept-language": "zh-CN,zh;q=0.9,en-GB;q=0.8,en;q=0.7",
    "cache-control": "max-age=0",
    "content-type": "application/x-www-form-urlencoded",
    "upgrade-insecure-requests": "1"
    },
    "referrer": "http://192.168.1.28:14000/login",
    "referrerPolicy": "strict-origin-when-cross-origin",
    "body": "username=admin&password=admin&remember-me=on",
    "method": "POST",
    "mode": "cors",
    "credentials": "omit"
    });
    lujjjh
        4
    lujjjh  
       2021-06-07 18:43:47 +08:00
    如果你的 <iframe> 里嵌的页面 cross-site 了,那么要注意 Chrome 对 Set-Cookie samesite 的默认值已经是 lax 了,HTTP 下也没法改成 none,<iframe> 页面里的 Set-Cookie 是不会生效的。如果你要嵌一个第三方( cross-site )的页面,第三方又依赖了 Cookie,只能通过 HTTPS + 显式指定 secure; samesite=none 。

    Cookie 没写成功,没有跳转到正确的页面,就可能造成你看到的“页面不会跳转”的现象。
    1sm23
        5
    1sm23  
    OP
       2021-06-08 11:43:55 +08:00
    @lujjjh #4 说的太准了,全中了😩,我们正在想解决办法,可能最后要改成免登录了
    billly
        6
    billly  
       2021-06-08 22:55:21 +08:00
    最近新版本的 chrome,导致我们一个同域的 iframe 不能 set-cookie,不知道哪里不对,还在排查呢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1353 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 23:35 · PVG 07:35 · LAX 16:35 · JFK 19:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.