Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
Asp.Net Core

Asp.Net Core: Fix a Correlation Cookie Dropped by SameSite Lax

- 29.11.26 - ErcanOPAK

⚙️ Fix a Correlation Cookie Dropped by SameSite Lax

ASP.NET Core’s OpenID Connect and OAuth handlers set a short-lived correlation cookie before redirecting to the identity provider, and read it back when the provider redirects the user home to validate that the response matches a request this app actually started. Some identity providers return control to your app via a cross-site HTTP POST (response_mode=form_post is common), and a browser enforcing SameSite=Lax on that correlation cookie — the ASP.NET Core default unless you override it — will not attach the cookie to a cross-site POST, so the handler can’t find it, and the flow fails with a “Correlation failed” error that has nothing to do with your actual login credentials.

🔎 The Problem

services.AddAuthentication()
    .AddOpenIdConnect(options =>
    {
        options.ResponseMode = "form_post"; // IdP redirects back via
                                              // cross-site POST
        // CorrelationCookie.SameSite left at its default (Lax) -
        // browser won't send it on the cross-site POST back from the IdP,
        // handler can't find the correlation value it set before redirecting
    });

✅ Fix: A Correlation Cookie Dropped by SameSite Lax

  • Set options.CorrelationCookie.SameSite = SameSiteMode.None explicitly for any flow using form_post or another cross-site redirect back into your app, since Lax is only safe for same-site or top-level GET redirects.
  • Pair SameSite=None with Secure=true on the same cookie (required by the spec, and by modern browsers), which means this fix only works correctly when your app is served over HTTPS.
  • Apply the same SameSite=None adjustment to the nonce cookie if you’re using one alongside correlation, since it’s subject to exactly the same cross-site POST restriction.

🚨 Why This Is Dangerous

  • A “Correlation failed” error reads like a security or configuration problem with the identity provider, which can send you chasing IdP settings for a while before you realize the actual cookie never left the browser.

SameSite=Lax protects a cookie from showing up where it shouldn’t — including, sometimes, the one cross-site redirect your own login flow actually needs it to reach.

— Backend Architect

Related posts:

.NET Core: Implementing Professional Monitoring with Health Checks

.NET Core: Implementing Professional Monitoring with Health Checks

ASP.NET Core: Fix a Background Service That Silently Stops Running After One Unhandled Exception

ASP.NET Core: Fix a Background Service That Silently Stops Running After One Unhandled Exception

ASP.NET Core: Why an IOptionsSnapshot Injected Into a Singleton Silently Freezes on Its First Config...

ASP.NET Core: Why an IOptionsSnapshot Injected Into a Singleton Silently Freezes on Its First Config...

Views: 4
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

SQL Server: Fix a Scalar UDF Inlining Silently Changing a Result
C#: Fix a TaskCompletionSource Never Completing After a Timeout

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,079 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 996 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 995 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 866 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 671 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 629 views
  8. 08Average of all values in a column that are not zero in SQL 584 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 561 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com