强制执行SameSite策略的Cookie在iOS 12中被阻止,用于涉及跨源请求的SSO流

Tar*_*tar 7 c# .net-core auth0 ios12

摘要:iOS/OS 12中的第三方登录中断!

我们有一个适用于多个网站的通用登录.这在Windows,macOS和iOS上的Firefox,Chrome和Safari中运行良好.但是对于iOS 12和macOS 12,似乎cookie不再从auth0登录窗口工作到我们的登录API.

它不仅在Safari中停止工作,而且在iOS 12上也在Chrome和Firefox中停止工作(它仍适用于Mac OS 12上的Chrome).我怀疑这与智能跟踪预防2.0有关,但我很难找到许多技术细节.

我们的登录流程如下:

  1. 用户单击login,将window.location.href设置为通用(不同)登录域上的登录URL.
  2. 这称为ChallengeAsync,它将用户发送到auth0域进行登录.
  3. 然后将用户发送回登录域,但此时缺少来自auth0的cookie和控制器中设置的会话cookie.

我在启动时使用以下内容:

    services.AddAuthentication(options => {
                    options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                    options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                    options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                })
                .AddCookie(options =>
                {
                    options.Cookie.Path = "/";
                    options.SlidingExpiration = false;
                })
                .AddOpenIdConnect("Auth0", options => {
                // Set the authority to your Auth0 domain
                options.Authority = $"https://{Configuration["Auth0:Domain"]}";

                // Configure the Auth0 Client ID and Client Secret
                options.ClientId = Configuration["Auth0:ClientId"];
                options.ClientSecret = Configuration["Auth0:ClientSecret"];

                // Set response type to code
                options.ResponseType = "code";

                // Configure the scope
                options.Scope.Clear();
                options.Scope.Add("openid");
                options.Scope.Add("profile");
                options.Scope.Add("email");
                options.Scope.Add("offline_access");
                options.CallbackPath = new PathString("/signin-auth0");
                options.ClaimsIssuer = "Auth0";
                options.SaveTokens = true;
                options.Events = new OpenIdConnectEvents
                {
                    OnRemoteFailure = context => {
                        <not relevant error redirects>    
                    },
                    OnRedirectToIdentityProvider = context =>
                    {
                        context.ProtocolMessage.SetParameter("audience", $"{ Configuration["Auth0:ApiIdentifier"]}");    
                        return Task.FromResult(0);
                    },
                    OnRedirectToIdentityProviderForSignOut = (context) =>
                    {
                        <not relevant logout handling>
                    }
                };
            });
Run Code Online (Sandbox Code Playgroud)

在登录控制器中,我有一个登录操作,它只设置会话值并调用ChallengeAsync打开Auth0登录:

await HttpContext.ChallengeAsync("Auth0", new AuthenticationProperties() { IsPersistent = true, ExpiresUtc = DateTime.UtcNow.AddMinutes(Global.MAX_LOGIN_DURATION_MINUTES), RedirectUri = returnUri });
Run Code Online (Sandbox Code Playgroud)

"returnUri"参数是返回此同一控制器的完整路径,但操作不同.当这个动作被击中时,来自auth0登录的两个cookie(即https://ourcompany.eu.auth0.com)和我在登录操作中设置的会话数据在iOS 12中丢失.

我能以其他方式在iOS 12上运行吗?所有帮助赞赏.

Tar*_*tar 7

我终于明白了.默认情况下设置的cookie使用SameSiteMode.Lax.这种方法在iOS 12之前一直运行良好,现在需要设置为iOS 12 SameSiteMode.None.

这是我使用的修改使它再次运行:

.AddCookie(options =>
            {
                options.Cookie.Path = "/";
                options.SlidingExpiration = false;
                options.Cookie.SameSite = SameSiteMode.None;
                options.Cookie.Expiration = TimeSpan.FromMinutes(Global.MAX_LOGIN_DURATION_MINUTES);
            })
Run Code Online (Sandbox Code Playgroud)

  • 仔细阅读RFC6265 [§5.3.7](https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-02#section-5.3.7)和[§8.8.3](https ://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-02#section-8.8.3),这似乎是任何需要遍历涉及跨源请求的SSO流的cookie的预期解决方案.有关更多上下文,请参阅[WebKit问题](https://bugs.webkit.org/show_bug.cgi?id=188165). (2认同)