ASP.NET Core authorization is opt-in. An endpoint with no authorization metadata needs no authorization at all, unless the app sets a fallback policy. Most teams know this on day one. The trouble starts in month nine, when a new controller ships without an attribute, someone adds [AllowAnonymous] to a class to fix one public page, or a minimal API endpoint is mapped on app instead of the protected group.
None of these look wrong in a diff. Each one turns an authenticated route into an anonymous one, or an admin route into a signed-in route. This post covers how ASP.NET Core chooses the policy for an endpoint, the four drift patterns that keep reaching production, and a review routine that catches them.
How ASP.NET Core picks a policy
The authorization middleware combines the metadata on an endpoint into one policy. Microsoft's policy selection table is the reference; the short version:
| Endpoint metadata | What runs |
|---|---|
| Nothing | The fallback policy, if one is configured. By default it is null, so nothing is required |
[Authorize] or RequireAuthorization() with no name |
The default policy: an authenticated user |
[Authorize(Policy = "X")] or RequireAuthorization("X") |
The named policy |
[Authorize(Roles = "admin")] |
A policy built from the roles |
| Several of the above | All of them combined; every requirement must pass |
[AllowAnonymous] or AllowAnonymous() |
No authorization failure is enforced |
Two rows cause most incidents. The first row means "secure by default" is something you configure, not something you get. The last row means anonymous access overrides everything else on the endpoint.
Drift 1: no fallback policy
Without a fallback policy, every new controller, Razor Page or minimal API endpoint is public until someone remembers the attribute. Microsoft's own guidance for apps where most endpoints need a signed-in user is to require authentication globally and mark the public ones explicitly:
using Microsoft.AspNetCore.Authorization;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthentication().AddJwtBearer();
builder.Services.AddAuthorizationBuilder()
.SetFallbackPolicy(new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build())
.AddPolicy("Admin", policy => policy.RequireRole("admin"));
builder.Services.AddControllers();
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.MapGet("/health", () => Results.Ok()).AllowAnonymous();
app.Run();On ASP.NET Core 6 the same thing is written as options.FallbackPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build(); inside AddAuthorization.
Two limits to know. The fallback policy only applies to requests the authorization middleware processes, so static files served before UseAuthorization() are not covered. And the fallback is not combined with named policies: an endpoint with [Authorize(Policy = "Admin")] runs the Admin policy only. That is usually what you want, as long as the Admin policy itself requires an authenticated user, which a role requirement does.
Drift 2: [AllowAnonymous] on the class
This one survives review because it looks additive. The catalogue page needs to work signed out, so someone puts [AllowAnonymous] on the controller:
[ApiController]
[Route("api/[controller]")]
[AllowAnonymous]
public class ProductsController(IProductRepository repo) : ControllerBase
{
[HttpGet]
public IActionResult List() => Ok(repo.All());
[HttpDelete("{id}")]
[Authorize(Roles = "admin")]
public IActionResult Delete(int id)
{
repo.Delete(id);
return NoContent();
}
}The Delete action is now anonymous. Microsoft's MVC authorization docs state it plainly: [AllowAnonymous] bypasses authorization statements, and when it is combined with [Authorize] attributes, the [Authorize] attributes are ignored. At controller level it overrides every [Authorize] on the controller and its actions.
The fix is to put [AllowAnonymous] on the one action that needs it, or to split public reads into their own controller:
[ApiController]
[Route("api/[controller]")]
public class ProductsController(IProductRepository repo) : ControllerBase
{
[HttpGet]
[AllowAnonymous]
public IActionResult List() => Ok(repo.All());
[HttpDelete("{id}")]
[Authorize(Policy = "Admin")]
public IActionResult Delete(int id)
{
repo.Delete(id);
return NoContent();
}
}The same trap exists through inheritance. An [AllowAnonymous] on a base controller applies to every derived controller, so check base classes when you review one.
Drift 3: minimal API groups
Minimal APIs put authorization on the route builder. Groups make this tidy, and they also make it easy to map one endpoint outside the group:
var api = app.MapGroup("/api").RequireAuthorization();
api.MapGet("/orders/{id}", (int id, IOrderStore store) => store.Find(id));
var admin = api.MapGroup("/admin").RequireAuthorization("Admin");
admin.MapPost("/refunds", (RefundRequest r, IRefunds refunds) => refunds.Issue(r));
// Added later, on app instead of api: no authorization metadata at all
app.MapPost("/api/export", (IExporter exporter) => exporter.Run());The path starts with /api, so it reads as part of the protected group. It is not. Without a fallback policy it is anonymous. With one, it needs a signed-in user but not the Admin policy that an export probably deserves. Map endpoints on the group variable, and treat any app.Map* call in a file that also defines groups as a review question.
Drift 4: authenticated is not authorized
[Authorize] with no arguments means "signed in". It says nothing about which user may touch which record. The common drift is a controller where most actions carry [Authorize(Policy = "Admin")] and a newer action carries plain [Authorize], or a route that checks the role but not the owner.
Object-level checks belong in the handler, against the record you loaded. ASP.NET Core has a built-in pattern for this, resource-based authorization:
[HttpPut("{id}")]
public async Task<IActionResult> Update(
int id, DocumentUpdate body, [FromServices] IAuthorizationService authz)
{
var doc = await docs.FindAsync(id);
if (doc is null) return NotFound();
var result = await authz.AuthorizeAsync(User, doc, "DocumentOwner");
if (!result.Succeeded) return Forbid();
doc.Apply(body);
await docs.SaveAsync(doc);
return NoContent();
}The DocumentOwner policy's handler compares the document's owner with the user's id claim. The decision now depends on the record, which no attribute can do.
Two smaller traps
- Decisions based on the Host or Referer header. Code that grants access when
Request.Hostislocalhost, or skips authentication when theRefererlooks internal, trusts a header the client sets. Behind a proxy, "local" often means "came through the proxy", which is every request. - Error and debug configuration.
UseDeveloperExceptionPage()without an environment check,"DetailedErrors": truein a production settings file, orcustomErrors mode="Off"in a legacyweb.confighand attackers stack traces and sometimes configuration values.
A review routine
| Check | How |
|---|---|
| Fallback policy is set | Look for SetFallbackPolicy or options.FallbackPolicy in Program.cs |
No class-level [AllowAnonymous] on a controller with mutating actions |
Search for [AllowAnonymous] and read the attribute's scope, including base controllers |
Every app.Map* call is intentional |
Compare top-level Map* calls with your groups |
| Admin actions use the same policy as their siblings | Read each controller's actions side by side |
| Handlers that load a record by id check ownership | Look for AuthorizeAsync(User, resource, ...) or an explicit owner comparison |
Run it on every pull request that adds a controller or a group, not once a year.
What Vulkro checks in ASP.NET Core
Vulkro Core reads C# with configuration and syntactic rules, plus an ASP.NET Core route reader. Attribute-routed controllers (including routes and attributes inherited from base controllers) and minimal APIs under MapGroup prefixes become endpoints, and [Authorize], [AllowAnonymous], RequireAuthorization() on a route, a group or MapControllers(), an options.FallbackPolicy assignment and a global AuthorizeFilter are read as guards. That makes the access level of each route visible:
vulkro rbac . # every endpoint with the login level it requires
vulkro discover . # the endpoint inventory on its own
vulkro scan . # findings, each tied to its routeDOTNET-AUTH-001 reports [AllowAnonymous] on a mutating action beside [Authorize] siblings, and access decided by the Host or Referer header. DOTNET-CONFIG-001 reports exposed error pages, debug compilation, request validation turned off and any-origin CORS with credentials. The C# page lists every rule and its limits: there is no cross-method taint for C#, and object-level authorization is a decision Vulkro marks as not checked rather than guessing.
FAQ
Does [AllowAnonymous] override [Authorize] in ASP.NET Core?
Yes. For MVC controllers, [AllowAnonymous] bypasses authorization statements, and any [Authorize] attributes on the same endpoint are ignored. On a controller class it applies to every action in it, so put it on individual actions instead.
What does the fallback policy do?
It is the policy used when an endpoint has no authorization metadata. By default it is null, which means no authorization. Setting it to require an authenticated user makes new endpoints private unless they opt out with [AllowAnonymous] or AllowAnonymous().
Do minimal APIs respect [Authorize]?
Minimal API endpoints use RequireAuthorization() and AllowAnonymous() on the route or group builder, and attributes on the handler delegate also work. Group conventions apply to every endpoint mapped on the group, but not to endpoints mapped directly on app.
See the API security use case and the vulkro rbac reference, or start a 14-day trial. Related: broken access control is still number one and Spring Boot security mistakes.