-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
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"
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.
aspnetcore/src/Security/Authentication/OpenIdConnect/src/OpenIdConnectOptions.cs
Lines 68 to 76 in 0f51760
| _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
