📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

Explain SameSite cookies. What do Strict, Lax and None actually do, what counts as the 'same site', why does an OpenID Connect sign-in break if the correlation cookie is Lax, and how have browser changes (Lax by default, third-party cookie blocking) affected ASP.NET Core apps?

SameSite=Strict, Lax and None semantics, the site vs origin distinction, cross-site flows such as the OIDC form_post callback, ASP.NET Core cookie settings, and the browser changes that broke older apps.

Mid-Level Theory Intermediate aspnet-core cookies csrf openid-connect samesite security

🎯 Key points

  • SameSite controls whether a cookie is sent on cross-site requests; it's a CSRF and cross-site leak mitigation
  • Site = scheme + registrable domain (eTLD+1); sibling subdomains are same-site, different origins
  • Strict: never cross-site; Lax: still sent on cross-site top-level GET navigations, nothing else; None: always, and requires Secure
  • Set SameSite and Secure explicitly on every cookie: Chromium treats a missing attribute as Lax, other browsers don't
  • OIDC form_post callback is a cross-site POST, so correlation and nonce cookies must be SameSite=None; Secure (the ASP.NET Core OIDC handler defaults to this; your own cookies default to Lax or Strict)
  • None cookies need the app to see HTTPS: behind a proxy that means UseForwardedHeaders
  • ASP.NET Core: CookieOptions.SameSite, SameSiteMode.Unspecified omits the attribute, CookiePolicyOptions.MinimumSameSitePolicy
  • Safari and Firefox block or partition third-party cookies regardless of SameSite=None; Chrome kept them but offers CHIPS (Partitioned)

⏱ 30-second answer

SameSite tells the browser whether to send a cookie on cross-site requests. Strict: never cross-site. Lax: cross-site only on top-level GET navigations (clicking a link), not on cross-site POSTs, iframes or fetch. None: always, and it must also be Secure. 'Site' means scheme plus registrable domain, so app.example.com.au and api.example.com.au are the same site.

Chromium now treats cookies without the attribute as Lax by default, which broke flows that relied on cross-site POSTs, most famously OpenID Connect form_post callbacks: the identity provider POSTs back to /signin-oidc, so the correlation and nonce cookies must be SameSite=None; Secure, which ASP.NET Core sets for you over HTTPS. The trade-off: Strict is safest but hurts UX; None is needed for embedding and federation but loses CSRF protection.

🗣 Full answer (senior)

How I would answer this in an interview

"SameSite is a cookie attribute that decides whether the browser attaches the cookie when the request comes from another site. Strict means only same-site requests; Lax adds top-level GET navigations, so following a link from an email still sends it, but a cross-site form POST, an iframe or a fetch from another site doesn't; None means always, and browsers require Secure with it. The subtle part is that 'site' isn't 'origin': it's the scheme plus the registrable domain, so all my subdomains are the same site as each other. That's why SameSite doesn't protect me from a compromised sibling subdomain.

The big change was Chromium making Lax the default for cookies with no attribute. That quietly broke anything that depended on a cross-site POST carrying a cookie. The classic is OpenID Connect with response_mode=form_post: Entra ID auto-posts the response back to /signin-oidc from its own domain, and the handler needs the correlation and nonce cookies it set before the redirect. If those are Lax, they aren't sent, and you get 'Correlation failed'. ASP.NET Core sets those cookies to SameSite=None; Secure, which means the app must be on HTTPS, or see HTTPS through forwarded headers, otherwise browsers drop them. At [company] we hit exactly this after [moving behind a TLS-terminating proxy]: [the fix was forwarded headers, not changing SameSite].

For my own cookies: the session cookie is Lax by default in ASP.NET Core, or Strict if users rarely arrive from external links. I only use None for genuinely cross-site needs like an embedded widget, and then I add antiforgery, because None removes SameSite's CSRF protection. The mistake I see is setting everything to None to 'fix' a login bug; that trades a symptom for a vulnerability."


What gets sent

Request from another site Strict Lax None (+Secure)
Clicking a link (top-level GET) No Yes Yes
Cross-site form POST (e.g. OIDC form_post) No No Yes
fetch/XHR with credentials No No Yes (if third-party cookies allowed)
Iframe of your site No No Yes (if third-party cookies allowed)
Image or script subresource No No Yes

Site vs origin

A B Same origin? Same site?
https://app.example.com.au https://api.example.com.au No Yes
https://app.example.com.au http://app.example.com.au No No (schemeful)
https://example.com.au https://login.microsoftonline.com No No

ASP.NET Core cookies and their defaults

Cookie Default SameSite Why
Cookie authentication Lax Survives link navigation; blocks cross-site POSTs
OIDC correlation and nonce None (Secure) Must survive the IdP's cross-site POST
Antiforgery cookie Strict Only needed on same-site form posts
Session (AddSession) Lax

Production example

After TLS termination moved to the ingress, sign-in failed for about 30% of users with 'Correlation failed': the app saw HTTP, so the None cookies weren't marked Secure and Chromium rejected them. Adding UseForwardedHeaders with the ingress network restored sign-in instantly; nobody needed to touch SameSite.

🔍 What the interviewer is checking

Checks that the candidate knows exact SameSite semantics, the site/origin distinction, and can diagnose real breakages like OIDC correlation failures.

Green flags

  • Explains Lax as 'top-level GET only' and None requiring Secure
  • Knows subdomains are same-site
  • Explains why the OIDC form_post callback needs None cookies
  • Connects None-cookie failures to HTTPS and forwarded headers behind proxies

Red flags

  • Sets everything to None to fix sign-in
  • Thinks SameSite alone prevents CSRF
  • Confuses site with origin

📚 Learn in depth

1. What SameSite decides

Request initiator site == target cookie's site ?  -> send (all modes)
Otherwise (cross-site):
   Strict -> don't send
   Lax    -> send only if top-level navigation AND safe method (GET)
   None   -> send (requires Secure; subject to third-party cookie policy)

The browser compares the site of the top-level page that initiated the request with the cookie's site, using the Public Suffix List to find the registrable domain (example.com.au, because com.au is a public suffix). Since 2021 browsers compare schemefully, so http:// and https:// versions are different sites.

2. Lax by default

Chromium (2020) changed cookies with no SameSite attribute to behave as Lax, with a temporary 'Lax+POST' allowance for top-level cross-site POSTs within two minutes of the cookie being set, kept to avoid breaking sign-in flows. Firefox and Safari did not ship Lax-by-default broadly, but both block or partition third-party cookies anyway. So: never rely on the default, set the attribute explicitly.

3. The OIDC callback in detail

1. App (example.com.au) -> 302 to IdP; sets .AspNetCore.Correlation + Nonce cookies (SameSite=None; Secure)
2. User signs in at login.microsoftonline.com
3. IdP returns an auto-submitting HTML form: POST https://example.com.au/signin-oidc
      -> cross-site, top-level POST
4. Browser sends cookies only if SameSite=None (Lax wouldn't send on POST)
5. Handler validates correlation (CSRF protection for the flow) and nonce (replay protection)

With response_mode=query (code in the query string, a GET), Lax cookies would be sent, but form_post is the default in the ASP.NET Core OpenID Connect handler because it keeps codes out of URLs and logs.

4. ASP.NET Core controls

  • CookieOptions.SameSite per cookie; CookieAuthenticationOptions.Cookie.SameSite for the auth cookie.
  • SameSiteMode.Unspecified omits the attribute (browser default applies). It was introduced for the 2019–2020 transition when some older browsers (notably iOS 12 Safari) mishandled None.
  • CookiePolicyOptions.MinimumSameSitePolicy and OnAppendCookie let you enforce or adjust policy globally via UseCookiePolicy().
  • None cookies need Secure; behind a TLS-terminating proxy that requires UseForwardedHeaders so the app knows the request is HTTPS.

5. Third-party cookies today

SameSite=None is necessary but no longer sufficient for third-party contexts: Safari (ITP) blocks third-party cookies, Firefox partitions them per top-level site (Total Cookie Protection), and Chrome, which dropped its plan to remove them, supports CHIPS (Partitioned attribute) for embedded widgets that need per-embedder state. Designs that depend on third-party cookies (silent token renewal in hidden iframes, cross-site embedded sessions) should move to first-party alternatives such as a BFF on the same site.

Try it yourself

  1. Set three cookies with Strict, Lax and None on a test site; navigate to it from another site via a link and a form POST, and inspect which were sent in dev tools.
  2. Reproduce 'Correlation failed' by running an OIDC app over HTTP behind a proxy, then fix it with forwarded headers.
  3. Use CookiePolicyOptions.OnAppendCookie to log every cookie's SameSite value at startup.
  4. Check chrome://settings/cookies behaviour with third-party cookies blocked and test an embedded iframe.
  5. Add Partitioned to a None cookie in an embedded test page and compare behaviour across browsers.

💻 Code

Explicit SameSite settings for each cookie in an ASP.NET Core app that signs in with Microsoft Entra ID and runs behind a TLS-terminating proxy.

using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.HttpOverrides;

var builder = WebApplication.CreateBuilder(args);

builder.Services.Configure<ForwardedHeadersOptions>(o =>
{
    // None cookies must be Secure; the app must know the original request was HTTPS
    o.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
    o.KnownNetworks.Add(new Microsoft.AspNetCore.HttpOverrides.IPNetwork(System.Net.IPAddress.Parse("10.240.0.0"), 16));
});

builder.Services.AddAuthentication(o =>
    {
        o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
        o.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
    })
    .AddCookie(o =>
    {
        o.Cookie.HttpOnly = true;
        o.Cookie.SecurePolicy = CookieSecurePolicy.Always;
        o.Cookie.SameSite = SameSiteMode.Lax;   // survives links from email; blocks cross-site POSTs
    })
    .AddOpenIdConnect(o =>
    {
        builder.Configuration.Bind("EntraId", o);
        o.ResponseType = "code";
        // form_post is the default: the IdP POSTs back cross-site, so the handler's
        // correlation and nonce cookies are SameSite=None; Secure. Don't downgrade them.
        o.CorrelationCookie.SameSite = SameSiteMode.None;
        o.NonceCookie.SameSite = SameSiteMode.None;
    });

builder.Services.AddAntiforgery(o => o.Cookie.SameSite = SameSiteMode.Strict);

var app = builder.Build();

app.UseForwardedHeaders();   // first, so Request.IsHttps is correct for Secure cookies
app.UseAuthentication();
app.UseAuthorization();
app.Run();
// An embedded widget that genuinely needs a cross-site cookie: None + Secure + Partitioned (CHIPS)
context.Response.Headers.Append("Set-Cookie",
    "widget_state=abc; Path=/; Secure; HttpOnly; SameSite=None; Partitioned");

⚠ Common mistakes

  • Mistake: Setting every cookie to SameSite=None to fix a sign-in error. Why it is wrong: it removes SameSite's CSRF protection from the session cookie. Instead: only the OIDC correlation and nonce cookies need None; fix the real cause (often HTTPS or forwarded headers).
  • Mistake: Using SameSite=None without Secure. Why it is wrong: modern browsers reject the cookie entirely. Instead: always pair None with Secure, and make sure the app sees HTTPS behind proxies.
  • Mistake: Assuming subdomains are cross-site. Why it is wrong: sibling subdomains share a registrable domain, so they're same-site and SameSite doesn't separate them. Instead: treat subdomain takeover as a CSRF risk and keep antiforgery tokens.
  • Mistake: Relying on browser defaults by omitting the attribute. Why it is wrong: browsers differ (Chromium Lax-by-default, others not). Instead: set SameSite explicitly on every cookie.
  • Mistake: Making the session cookie Strict without thinking about entry points. Why it is wrong: users following a link from email or Teams appear logged out on the first request. Instead: use Lax for the session, Strict for cookies only needed on same-site actions.
  • Mistake: Expecting SameSite=None to make third-party cookies work everywhere. Why it is wrong: Safari blocks and Firefox partitions third-party cookies by default. Instead: design first-party flows (same-site BFF) or use Partitioned for embedded state.
  • Mistake: Treating SameSite as the CSRF defence. Why it is wrong: Lax still allows top-level GETs and same-site attacks. Instead: layer it with antiforgery tokens.

🏛 Senior insight: trade-offs

The senior understanding is that SameSite is a browser-side policy on ambient credentials that interacts with everything else: CSRF defences, federation flows, embedding and third-party cookie restrictions. Getting it right means being explicit per cookie and knowing which flows are cross-site by design.

Setting When it fits Cost When not to
Strict Antiforgery cookies, high-value admin sessions Users from external links seem logged out initially General session cookies on consumer sites
Lax Most session cookies Allows top-level GET from other sites Cookies needed in cross-site POSTs or iframes
None + Secure OIDC correlation/nonce, embedded widgets No CSRF protection from SameSite; third-party blocking Session cookies of normal apps
None + Secure + Partitioned Embedded widgets needing per-embedder state Per-site state only Cross-site single sign-on state

Measure: sign-in failure rate ('Correlation failed' in logs), cookie attributes asserted in integration tests, and browser-matrix testing of embedded flows.

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions SameSite as a CSRF defence Why: Checks they know antiforgery tokens are still required and how ASP.NET Core implements them
    How to answer

    CSRF makes a victim's browser send a state-changing request to your site from another site; it works because the browser attaches cookies automatically. If you authenticate with cookies, you're exposed; if callers send a bearer token in the Authorization header, a cross-site page can't add it, so classic CSRF doesn't apply.

    ASP.NET Core's antiforgery uses a synchroniser token: a cookie token plus a token in the form or a header, validated together. MVC forms get it from the form tag helper with [ValidateAntiForgeryToken] or the global auto-validate filter; Razor Pages validate POSTs by default; Minimal APIs need AddAntiforgery/UseAntiforgery and validate form-bound endpoints. SameSite=Lax (the default for ASP.NET Core auth cookies) blocks most cross-site POSTs, but not attacks from a sibling subdomain or GETs that change state, so keep tokens.

  2. When: Candidate mentions the authentication cookie Why: Checks the full cookie authentication picture: flags, expiry and Data Protection
    How to answer

    After a successful login the app calls HttpContext.SignInAsync: the cookie handler serialises the ClaimsPrincipal into an authentication ticket, encrypts and signs it with Data Protection, and sends it as a cookie. On each request the handler decrypts the cookie and rebuilds HttpContext.User, with no database call.

    • Flags: HttpOnly (JavaScript can't read it), Secure (HTTPS only), SameSite=Lax by default (not sent on most cross-site requests).
    • Expiry: ExpireTimeSpan (default 14 days) with sliding expiration that reissues the cookie once half the window has passed; IsPersistent decides whether it survives closing the browser.
    • Keys: every instance must share the Data Protection key ring, or cookies issued by one server can't be read by another.

    The trade-off: a self-contained cookie is fast and stateless, but you can't revoke it without extra checks or a server-side ticket store.

🛠 Real-world problems: how you handle them

'Correlation failed' after moving TLS termination to the ingress
Situation
An internal line-of-business app on [AKS / App Service] signs users in with Microsoft Entra ID via OpenID Connect. After [migrating to a new ingress that terminates TLS], about [30]% of sign-ins fail. [Number] staff can't start work.
Signals
Users loop back to Entra ID or see an error page; logs show 'Correlation failed' and 'Unable to unprotect the message.State'; Chrome dev tools show the correlation cookie rejected with a warning about SameSite=None without Secure; Entra sign-in logs show successful authentications.
Investigation
Compared the Set-Cookie headers before and after the migration: the correlation and nonce cookies lacked `Secure`. Confirmed `Request.Scheme` was `http` inside the app (logged it), because forwarded headers weren't processed. Checked which browsers failed (Chromium-based) versus succeeded, which matched the None-requires-Secure rule. Ruled out Data Protection key issues by confirming the key ring was shared.
Resolution
Immediate: enabled `UseForwardedHeaders` with the ingress's network in KnownNetworks, first in the pipeline, restoring HTTPS awareness so cookies were marked Secure. Long term: set `CookieSecurePolicy.Always` on cookies explicitly and documented the ingress contract (X-Forwarded-Proto required).
Prevention
Integration test asserting the correlation cookie is `SameSite=None; Secure`; a synthetic sign-in check in staging after infrastructure changes; an alert on 'Correlation failed' log volume; a platform checklist item for forwarded headers on every app behind the ingress.

How to tell it (STAR)

**S:** At [company], after we moved [our apps] to a new TLS-terminating ingress, about [30]% of staff couldn't sign in and saw 'Correlation failed'. **T:** I had to restore sign-in fast without weakening cookie security. **A:** In dev tools I saw Chrome rejecting the correlation cookie because it was SameSite=None without Secure. Logging the request scheme showed the app thought every request was HTTP, because forwarded headers weren't processed. I added `UseForwardedHeaders` with the ingress network, so cookies were marked Secure again, and forced Secure on all cookies. **R:** Sign-in failures dropped to zero within [minutes] of the deploy, and a synthetic sign-in check now runs after every infrastructure change.

↩ Usually asked after

More in Web Security

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me