V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
1sm23
V2EX  ›  浏览器

iframe

  •  
  •   1sm23 · Jun 7, 2021 · 3097 views
    This topic created in 1788 days ago, the information mentioned may be changed or developed.
    嵌入在 iframe 里的子页面如果有登陆操作返回 302,但是页面不会跳转
    Supplement 1  ·  Jun 8, 2021
    iframe 跨域 cookie SameSite chrome 4 楼总结了
    6 replies    2021-06-08 22:55:21 +08:00
    AV1
        1
    AV1  
       Jun 7, 2021
    你需要把问题描述具体些。
    控制台打了啥?
    Network 请求记录是怎样的?
    你的“登录”用的是<form>标签+submit 按钮实现的,还是 JS 构造异步请求实现的?
    如果是<form>标签,尝试过设置 target="_top"属性了么?
    如果是 JS 构造异步请求,尝试过 Window.top.location.href 设置页面跳转地址了么?
    1sm23
        2
    1sm23  
    OP
       Jun 7, 2021
    @DOLLOR #1 是第三方子页面,可能没办法修改,看了下好像是用的<form>+submit,看了你的回复试了下 target="_top"好像不行
    1sm23
        3
    1sm23  
    OP
       Jun 7, 2021
    @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  
       Jun 7, 2021
    如果你的 <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
       Jun 8, 2021
    @lujjjh #4 说的太准了,全中了😩,我们正在想解决办法,可能最后要改成免登录了
    billly
        6
    billly  
       Jun 8, 2021
    最近新版本的 chrome,导致我们一个同域的 iframe 不能 set-cookie,不知道哪里不对,还在排查呢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2764 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 14:20 · PVG 22:20 · LAX 07:20 · JFK 10:20
    ♥ Do have faith in what you're doing.