Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS policy.AllowAnyHeader() does not appear to work #42424

Closed
catmanjan opened this issue Jul 29, 2024 · 1 comment
Closed

CORS policy.AllowAnyHeader() does not appear to work #42424

catmanjan opened this issue Jul 29, 2024 · 1 comment
Labels
Area-Workloads untriaged Request triage from a team member

Comments

@catmanjan
Copy link

I have the following Program.cs as part of a dotnet 8 web API project:

var builder = WebApplication.CreateBuilder(args);
builder.Logging.ClearProviders();
builder.Logging.AddConsole();

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddCors(options =>
{
    options.AddDefaultPolicy(
        policy =>
        {
            policy.AllowAnyHeader();
            policy.AllowAnyMethod();
            policy.AllowAnyOrigin();
        });
});

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();
app.UseCors();
app.UseAuthorization();
app.MapControllers();

app.Run();

Notice policy.AllowAnyHeader();. If I browse to my API in the latest Google Chrome I get the following headers, but no Access-Control-Allow-Headers.
image

I would expect to be receiving an Access-Control-Allow-Headers value of *

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Workloads untriaged Request triage from a team member labels Jul 29, 2024
@martincostello
Copy link
Member

This issue should be filed in the dotnet/aspnetcore repository as that's where the CORS functionality lives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Workloads untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

2 participants