Skip to content

CorsPolicyBuilder.GetNormalizedOrigin NullReferenceException #19830

Closed
@chrispickford

Description

@chrispickford

Making a call to CorsPolicyBuilder.WithOrigins with an array that contains a null string will cause a NullReferenceException to be thrown rather than throwing against the argument. This was noticed when a configuration file failed to read.

To Reproduce

app.UseCors(builder => builder.WithOrigins(null));

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder.GetNormalizedOrigin(String origin)
   at Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder.WithOrigins(String[] origins)
   at ###.Startup.<Configure>b__11_0(CorsPolicyBuilder builder) in ###\Startup.cs:line 95
   at Microsoft.AspNetCore.Builder.CorsMiddlewareExtensions.UseCors(IApplicationBuilder app, Action`1 configurePolicy)
   at ###.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env) in ###\Startup.cs:line 94
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

It would be beneficial if an ArgumentNullException was thrown instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.feature-corsThis issue is related to CORS

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions