Skip to content

CORS does not function on swagger.json endpoint #2641

@rcollette

Description

@rcollette

My API application is configured to allow cross domain requests by setting:

services.AddCors(
            options =>
            {
                options.AddDefaultPolicy(
                    builder =>
                    {
                        builder.WithOrigins("http://localhost:4200")
                            .AllowAnyMethod()
                            .AllowAnyHeader();
                    });
            });

and

app.UseForwardedHeaders(forwardedHeadersOptions)
            .UseRouting()
            .UseCors()

When a request to any of my APIs contains the Origin request header with a value of http://localhost:4200 the http response header access-control-allow-origin is set to http://localhost:4200. CORS configuration is working.

When a request is made to the swagger.json endpoint rendered by Swashbuckle, and the Origin request header is included as mentioned previously, no access-control-allow-origin header is included in the response.

I am unable to locate any documentation that mentions separate configuration required for Swashbuckle to handle CORS requests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions