Skip to content

CORS

Granit.Cors configures a default CORS policy driven by appsettings.json. Wildcard origins (*) are rejected at startup in non-development environments to enforce ISO 27001 network access controls.

[DependsOn(typeof(GranitCorsModule))]
public class AppModule : GranitModule { }
{
"Cors": {
"AllowedOrigins": ["https://app.example.com", "https://admin.example.com"],
"AllowCredentials": false
}
}

In Program.cs:

app.UseCors(); // Uses the default policy configured by the module
RuleEnforced atEnvironment
At least one origin requiredStartupAll
Wildcard * forbiddenStartupNon-development
AllowCredentials + wildcard rejectedStartupAll (CORS specification)
PropertyDefaultDescription
AllowedOrigins[]Allowed CORS origins (required, minimum 1)
AllowCredentialsfalseInclude Access-Control-Allow-Credentials: true

The default policy applies AllowAnyHeader() and AllowAnyMethod(), which is standard for REST APIs. Origins are restricted to the configured list.

CategoryKey typesPackage
ModuleGranitCorsModule
OptionsGranitCorsOptionsGranit.Cors
ExtensionsAddGranitCors()Granit.Cors