⚙️ Asp.Net Core: Fix a Cookie Policy Blocking a Cross-Site Redirect
Setting a cookie’s SameSite policy to Strict is the safest default for most authentication cookies, but it also means the cookie is withheld on the very first request after a user arrives via an external link or a redirect from a third-party identity provider — exactly the flow an OAuth or SSO login depends on. The sign-in can complete successfully on the provider’s side and still land the user back at the app logged out, because the session cookie set moments earlier wasn’t sent along with that first cross-site navigation.
🔎 The Problem
services.ConfigureApplicationCookie(options => {
options.Cookie.SameSite = SameSiteMode.Strict;
});
// External IdP redirects back via 302 to /signin-oidc
// Browser treats this as a cross-site navigation ->
// the auth cookie just set is withheld on the NEXT request
// User ends up on the home page, still unauthenticated
✅ Fix: Scope SameSite to the Actual Flow That Needs It
- Use
SameSiteMode.Laxfor the primary authentication cookie when any part of login happens via a top-level cross-site redirect (OAuth, SAML, OIDC) — Lax still blocks the cookie on cross-site subrequests like images or iframes, while allowing it on full-page navigations. - Reserve
SameSiteMode.Strictfor cookies that genuinely never need to survive an external redirect, such as an anti-CSRF token tied to forms submitted only from within the same site. - Test the full external-IdP round trip in an actual browser, not just Postman or a same-site dev environment — SameSite enforcement only manifests on a genuine cross-origin redirect, which local testing against
localhostcan easily fail to reproduce.
🚨 Why This Is Dangerous
- An intermittent ‘login succeeded but I’m logged out’ report that only happens for users coming through SSO, and never for users who log in directly, can go undiagnosed for a long time if nobody thinks to check the cookie’s SameSite setting specifically against the redirect flow.
SameSite=Strict protects a cookie from everyone — including the identity provider you just asked to redirect the user back to you.





