【问题标题】:IFrame with safari no longer support 3rd party cookies带有 safari 的 IFrame 不再支持 3rd 方 cookie
【发布时间】:2021-02-18 11:11:35
【问题描述】:

虽然 IFrame 和 xyz.com 正在 IFrame 中加载,但我正在尝试访问跨站点 url。

在 xyz.com 中,我们使用了 asp.net 会员模块,并且我们正在使用 SetAuthCookie。

FormsAuthentication.SetAuthCookie(userName, false);

以前,我们可以通过使用以下逻辑,通过引用者访问顶部框架 href,在 safari 中访问这些身份验证 cookie。

  <script>
    window.onload = function () {        
        if (navigator.userAgent.indexOf('Safari') != -1 && (navigator.userAgent.indexOf('iPhone') != -1 || navigator.userAgent.indexOf('iPad') != -1)) {              
            var cookies = document.cookie;
            if (top.location != document.location) {
               
                if (!cookies) {
                    href = document.location.href;
                    href = (href.indexOf('?') == -1) ? href + '?' : href + '&';
                    top.location.href = href + 'reref=' + encodeURIComponent(document.referrer);                      
                }
            } else {
                
                ts = new Date().getTime(); document.cookie = 'ts=' + ts;
                rerefidx = document.location.href.indexOf('reref=');
                if (rerefidx != -1) {
                    href = decodeURIComponent(document.location.href.substr(rerefidx + 6));
                    window.location.replace(href);                    
                }
            }
          
            var redirectValue = document.getElementById('hgvRedirectValueHiddenField').value;
            if (redirectValue != "") {
                window.open(redirectValue, '_self');
            }
        }

    }

</script>

但是对于最新的更新,safary 不允许设置

 top.location.href = href + 'reref=' + encodeURIComponent(document.referrer);

auth cookie 似乎不再允许并出现以下错误

顶层窗口尝试导航的框架是 跨域或不受信任且用户从未与 框架。

由于我无法访问 ABC.com 并且无 cookie 表单身份验证对我们来说似乎发生了巨大变化,因此该问题的解决方法是什么。

是否可以要求用户从 iframe 页面内部接受 cookie 并设置 cookie?

【问题讨论】:

    标签: javascript authentication cookies iframe safari


    【解决方案1】:

    作为解决方案,我们对 web.xml 进行了一些更改。配置

     <sessionState timeout="70" cookieless="AutoDetect" />
    

    “cookieless”属性的可能值为:

    AutoDetect :如果启用了 cookie,会话将使用后台 cookie。如果 cookie 被禁用,则 URL 用于存储会话信息。

    UseCookie:会话始终使用后台 cookie。这是默认设置。

    UseDeviceProfile:如果浏览器支持 cookie,则会话使用后台 cookie,否则使用 URL。

    UseUri:会话始终使用 URL。

    并添加:

     <authentication mode="Forms">
          <forms loginUrl="Login.aspx" cookieless="AutoDetect" timeout="2880" name=".ASPXAUTH" slidingExpiration="true" />
     </authentication>
    

    【讨论】:

      猜你喜欢
      • 2022-08-08
      • 2016-08-28
      • 2015-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-28
      • 1970-01-01
      相关资源
      最近更新 更多