Cookies with a SameSite policy enforced are blocked in iOS 12 for SSO flows involving cross-origin requests

旧城冷巷雨未停 提交于 2019-12-09 16:51:06

问题


Summary: Third party login breaks in iOS / OS 12!

We have a common login that works across multiple websites. This is working fine in Firefox, Chrome and Safari on Windows, macOS and iOS. But with iOS 12 and macOS 12, it seems cookies are no longer working from auth0 login window to our login API.

It has stopped working not just in Safari, but on iOS 12 also in Chrome and Firefox (it still works in Chrome on Mac OS 12). I suspect this has to do with Intelligent Tracking Prevention 2.0, but I'm struggling to find many technical details.

Our login flow is as follows:

  1. User clicks login which sets window.location.href to login url on the universal (different) login domain.
  2. This calls ChallengeAsync which sends user to auth0 domain for login.
  3. User is then sent back to the login domain, but at this point the cookies from auth0 and session cookies set in the controller are missing.

I use the following in startup:

    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>
                    }
                };
            });

In the login controller I have a login action which just sets a session value and calls ChallengeAsync to open the Auth0 login:

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

The "returnUri" parameter is the full path back to this same controller, but different action. It is when this action is hit that both cookies from the auth0 login (i.e. https://ourcompany.eu.auth0.com) and session data I set in the login action are missing in iOS 12.

Can I do it in some other way that will work on iOS 12? All help appreciated.


回答1:


I have finally figured it out. The cookie set by default uses SameSiteMode.Lax. This has worked fine everywhere up until iOS 12, where it now needs to be set to SameSiteMode.None.

This is the modification I use that has got it working again:

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


来源:https://stackoverflow.com/questions/51982626/cookies-with-a-samesite-policy-enforced-are-blocked-in-ios-12-for-sso-flows-invo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!