Skip to content

OIDC NonceCookie/CorrelationCookie not accepted by latest Chrome/Edge in some cases #44853

@andi0b

Description

@andi0b

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have a website that uses OpenID Connect with the Microsoft.IdentityModel.Protocols.OpenIdConnect library. It runs on HTTP behind an Azure App Serivice (reverse proxy), which communicates via the browser over HTTPS.

The OIDC middleware creates two cookies, .AspNetCore.OpenIdConnect.Nonce... and .AspNetCore.Correlation.... Because ASP.NET Core thinks it is running on HTTP (no Forwarded Headers Middleware), it doesn't set the Secure flag of the cookie. But it still declares it as SameSite=None which makes Chrome/Edge 107 ignore the Set-Cookie header. Which always causes a failed login. Current Firefox accepts the cookie.

Workaround:

builder.AddOpenIdConnect((OpenIdConnectOptions options) =>
{
    // your settings...
    options.NonceCookie.SecurePolicy = CookieSecurePolicy.Always;
    options.CorrelationCookie.SecurePolicy = CookieSecurePolicy.Always;
});

Screenshot of the Edge dev tools. The exclamation mark shows a message like: This attempt to set a cookie via a Set-Cookie header was blicked because it had the "SameSite=None" attribute but did not have the "Secure" attribute, which is required in order to use "SameSite=None"

Screenshot 2022-11-02 194338

Expected Behavior

The default for the cookie builder should either be SameSite=Lax or SameSite=None, Secure=true. It anyway doesn't make a lot of sense to allow OIDC via an insecure HTTP connection.

_nonceCookieBuilder = new OpenIdConnectNonceCookieBuilder(this)
{
Name = OpenIdConnectDefaults.CookieNoncePrefix,
HttpOnly = true,
SameSite = SameSiteMode.None,
SecurePolicy = CookieSecurePolicy.SameAsRequest,
IsEssential = true,
};
}

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

7.0.100-rc.2.22477.23

Anything else?

asp.net core 7.0 rc2

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-authIncludes: Authn, Authz, OAuth, OIDC, Bearerhelp wantedUp for grabs. We would accept a PR to help resolve this issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions