Skip to content

Invalid authentication configuration crashes ASP.NET core (stack overflow) #53267

@tndata

Description

@tndata

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

An invalid/incomplete ASPNET Core authentication configuration causes the framework to crash and generate a stack overflow.

Expected Behavior

I would the application not to crash.

Steps To Reproduce

If I:

  1. Create a new empty ASP.NET Core application, .NET 8
  2. Add OpenIdConnect NuGet package (Microsoft.AspNetCore.Authentication.OpenIdConnect 8.0.1)
  3. add this code
builder.Services.AddAuthentication()
.AddOpenIdConnect("oidc", o =>
{
    o.Authority = "https://example.com";

    o.ClientId = "localhost-client";
    o.ClientSecret = "mysecret";

    o.ResponseType = "code";
    o.Prompt = "consent";

});

  1. I start the application
  2. Then I get a stack overflow as shown below and the console output just outputs errors forever.
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:7106
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5080
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: c:\code\WebApplication1\WebApplication1
Stack overflow.
   at System.Threading.Tasks.Task.FromResult[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].SetResult(System.__Canon)
   at Microsoft.AspNetCore.Authentication.AuthenticationHandlerProvider+<GetHandlerAsync>d__5.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Microsoft.AspNetCore.Authentication.AuthenticationHandlerProvider+<GetHandlerAsync>d__5, Microsoft.AspNetCore.Authentication.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]](<GetHandlerAsync>d__5 ByRef)
...

Yes, the confiuration is not complete/valid.

Exceptions (if any)

Stack Overflow

.NET Version

dotnet --version 8.0.100

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pillar: Dev Experiencearea-authIncludes: Authn, Authz, OAuth, OIDC, BearerenhancementThis issue represents an ask for new feature or an enhancement to an existing one

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions