.NET security for ASP.NET Core applications, control by control
ASP.NET Core provides authentication, authorisation, antiforgery, CORS, Data Protection and configuration for secrets.
Which endpoints those features cover, and how each one is set, is decided in your own code and configuration. This guide sets out what Microsoft's documentation says about each control and where its defaults stop, then gives you a control matrix to fill in for your own application, with a worked example in every row. Only one row sends requests: one sign-in and one sign-out by a test account on your own staging copy.
In this guide
ASP.NET Core control matrix
Put the table in a spreadsheet with a separate copy for each environment, then fill it in from the top. Each row names where to look, what Microsoft's documentation says about that control, and what to write down.
How to use itHide the instructions
Every row reads code, configuration, a log, the output of a listing command or a Microsoft documentation page, except the cookie row, which signs one test account in and out once on a staging copy you control and reads the cookie attributes the browser shows, within the limits that row sets. No row changes a setting, rotates or deletes a key, or asks you to copy a secret: where a row meets a secret, you record where it is and never its value. The last column is a worked example from an invented app written for this page, not client code. Documentation details are as the ASP.NET Core 10.0 articles on Microsoft Learn, the NuGet auditing guide and the .NET support policy gave them on 14 November 2026.
17 rows
Control
Where to look
Fallback authorisation policy
- Where to look
- Program.cs: AddAuthorization or AddAuthorizationBuilder, any FallbackPolicy or SetFallbackPolicy call, and where UseStaticFiles sits relative to UseAuthorization.
- What Microsoft's documentation says
- The policy-based authorisation article says endpoints with no authorisation metadata use the fallback policy if one is configured, that it is null by default so authorisation is not required, and that static files served before the authorisation middleware are not protected by it. Blazor WebAssembly apps do not support a server-side fallback policy.
- What to record
- Whether a fallback policy is set, what it requires, its file and line, and what the static file middleware serves before UseAuthorization. If a served file holds a key or token, record only that one is present and in which file.
- Worked evidence (invented example app)
- Program.cs line 22 calls SetFallbackPolicy with a policy built from RequireAuthenticatedUser(). UseStaticFiles on line 41 runs before UseAuthorization on line 44; wwwroot holds only CSS, images and the public script bundle, confirmed by listing the folder.
MVC controllers and Razor Pages
- Where to look
- Every controller and page model class, with its Authorize attributes and their Roles or Policy values, and the AddRazorPages conventions in Program.cs, such as AuthorizeFolder.
- What Microsoft's documentation says
- The MVC authorisation article says the Authorize attribute limits a controller, action or Razor Page to authenticated users, and that without Roles or Policy it uses the default policy. The conventions article says AuthorizePage and AuthorizeFolder add an authorisation filter from startup code.
- What to record
- One line per controller and page folder: the attribute or convention that protects it, the role or policy, and any action with an attribute of its own.
- Worked evidence (invented example app)
- OrdersController: Authorize(Policy = "StaffOnly") at class level. ReportsController: no attribute, so the fallback policy applies. Pages/Admin: AuthorizeFolder with the AdminOnly policy, Program.cs line 30.
Minimal API endpoints and route groups
- Where to look
- Every MapGet, MapPost, MapPut, MapDelete and MapGroup call, with any RequireAuthorization or AllowAnonymous chained to the endpoint or its group, and the order of UseAuthentication, UseAuthorization and the Map calls.
- What Microsoft's documentation says
- The policy-based authorisation article says RequireAuthorization applies a named policy when given one, and the default policy without a name unless the endpoint also has an explicit AuthorizationPolicy instance. The route handlers article says MapGroup can apply RequireAuthorization to a whole group, and group metadata behaves as if added to each endpoint. The cookie authentication article says UseAuthentication and UseAuthorization must be called before Map methods such as MapRazorPages.
- What to record
- Each route with its HTTP method, its group prefix, and the policy that applies to it from the endpoint, the group or the fallback policy.
- Worked evidence (invented example app)
- The /api group (Program.cs line 58) calls RequireAuthorization("ApiUser"). GET /api/health sits in that group with AllowAnonymous(). /webhooks/payments is mapped outside the group with AllowAnonymous() and verifies the provider's signature in its handler.
AllowAnonymous exceptions
- Where to look
- A repository search for AllowAnonymous as an attribute and as a method call, and for AllowAnonymousToPage and AllowAnonymousToFolder.
- What Microsoft's documentation says
- The MVC authorisation article warns that for MVC controllers AllowAnonymous bypasses authorisation statements: Authorize attributes combined with it are ignored, and at controller level, requirements on that controller and its actions are ignored. The conventions article says the anonymous filter takes precedence when both filters apply to a page. The error handling article says a custom error page must support anonymous access for signed-out users to see it.
- What to record
- Each exception with its scope (action, controller, page, folder, endpoint or group), the reason it is public, what data it returns and who confirmed the reason.
- Worked evidence (invented example app)
- Five exceptions: the Login and ForgotPassword actions on AccountController (sign-in flow), the Error page (error handling), GET /api/health (returns the word ok and nothing else) and /webhooks/payments (signature checked in the handler). Reasons confirmed by the tech lead.
Record ownership in handlers
- Where to look
- Every controller action, page handler and route handler that loads a record by an id from the route, query string or body.
- What Microsoft's documentation says
- The resource-based authorisation article says attribute evaluation occurs before data binding and before any method that loads a resource, so the Authorize attribute does not suffice for resource-based authorisation, and the app must call a custom authorisation method such as IAuthorizationService.AuthorizeAsync with the resource. The policy-based authorisation article says authorisation handlers are called even if authentication fails.
- What to record
- Each handler, the record it loads, and whether it calls AuthorizeAsync with that record or loads it through a query filtered by owner or tenant.
- Worked evidence (invented example app)
- OrdersController.Details loads the order by id, then calls AuthorizeAsync with the order and the SameCustomer policy (line 77). InvoicesController.Download loads by id with no owner check; logged for a fix.
Authentication cookie
- Where to look
- The AddCookie options in Program.cs, or the application cookie settings if the app uses ASP.NET Core Identity; any ValidatePrincipal handler; UseCookiePolicy options; and the cookie attributes the browser shows after one sign-in. That sign-in and the sign-out after it are the only requests in the matrix, and they have these limits: your own staging copy only; a test account that holds only test records, with any sign-in email or text going to an address or number you control; one sign-in and one sign-out, with no repeated or automated requests.
- What Microsoft's documentation says
- The cookie authentication article says SignInAsync creates an encrypted cookie using Data Protection; that once created the cookie is the single source of identity, so a user disabled in back-end systems stays signed in while it is valid; that ValidatePrincipal can check it on each request at a possible performance cost; that persistent cookies should only be enabled with explicit user consent; and that the cookie policy middleware's default MinimumSameSitePolicy is SameSiteMode.Lax.
- What to record
- ExpireTimeSpan and SlidingExpiration, whether ValidatePrincipal or another revocation check exists, whether a persistent cookie needs a "Remember Me" choice, and the HttpOnly, Secure and SameSite attributes the browser shows. The browser also shows the cookie's value, a live session token for the test account: never copy, paste or screenshot it.
- Worked evidence (invented example app)
- ExpireTimeSpan of 30 minutes with SlidingExpiration on (Program.cs line 35). ValidatePrincipal compares a LastChanged claim with the user store. The browser shows HttpOnly, Secure and SameSite=Lax on the authentication cookie; the value was not copied.
JWT bearer validation
- Where to look
- The AddJwtBearer options, such as Authority, Audience, MetadataAddress and any TokenValidationParameters, any code in the app that issues tokens itself, and where Swagger UI is mapped.
- What Microsoft's documentation says
- The JWT bearer article says tokens should be fully validated in an API (signature, issuer, audience and expiry), that explicitly defining the validation parameters is not required and the default values should be used if possible, not to generate your own access or ID tokens except for testing, and that a Swagger UI should normally not be deployed to production.
- What to record
- The authority and audience, each TokenValidationParameters property the code sets, every Validate setting set to false or custom validator with its reason, whether the app issues its own tokens, and whether Swagger UI is mapped outside Development. For any signing key, record only where it is loaded from, never its value.
- Worked evidence (invented example app)
- Authority and Audience are read from configuration (Program.cs line 38), with no TokenValidationParameters overrides. Swagger UI is mapped only inside the IsDevelopment() block. The app issues no tokens of its own.
Antiforgery in MVC and Razor Pages
- Where to look
- AddControllers or AddControllersWithViews, global filters, every ValidateAntiForgeryToken, AutoValidateAntiforgeryToken and IgnoreAntiforgeryToken attribute, and forms with asp-antiforgery="false".
- What Microsoft's documentation says
- The antiforgery article says Razor Pages are automatically protected, that AddControllers does not enable antiforgery tokens and AddControllersWithViews must be called for built-in antiforgery token support, that Microsoft recommends AutoValidateAntiforgeryToken broadly for non-API scenarios, and that IgnoreAntiforgeryToken overrides ValidateAntiForgeryToken and AutoValidateAntiforgeryToken filters specified at a higher level.
- What to record
- Whether AutoValidateAntiforgeryToken is applied globally, each IgnoreAntiforgeryToken and opted-out form with its reason, and any cookie-authenticated controller registered through AddControllers.
- Worked evidence (invented example app)
- AddControllersWithViews with AutoValidateAntiforgeryToken added as a global filter (Program.cs line 18). One IgnoreAntiforgeryToken, on the Error page handler, so that it accepts re-executed POST requests.
Antiforgery in Minimal APIs
- Where to look
- The UseAntiforgery call in Program.cs, endpoints that bind form data with FromForm, and every DisableAntiforgery() call.
- What Microsoft's documentation says
- The antiforgery article says Minimal APIs need an explicit UseAntiforgery call, that by default Minimal API endpoints accepting form data require antiforgery validation and fail before application code runs if it is not successful, and that DisableAntiforgery() should not be used on browser-accessible endpoints that rely on cookies for authentication or process user-submitted form data.
- What to record
- Whether UseAntiforgery is called, each form-binding endpoint, and each DisableAntiforgery() call with how that endpoint authenticates and why CSRF does not apply to it.
- Worked evidence (invented example app)
- UseAntiforgery on line 52. POST /api/uploads binds a form and keeps validation. DisableAntiforgery() appears once, on /webhooks/payments, which no browser calls and which checks a signature instead.
CORS policies
- Where to look
- Every AddCors policy, the UseCors calls and their position, EnableCors and DisableCors attributes, and RequireCors calls.
- What Microsoft's documentation says
- The CORS article says CORS is not a security feature and relaxes security; that AllowAnyOrigin with AllowCredentials is an insecure configuration that can result in cross-site request forgery, as is SetIsOriginAllowed(_ => true) with AllowCredentials; that SetIsOriginAllowedToAllowWildcardSubdomains matches any subdomain of the configured domain; that DisableCors does not disable CORS enabled with RequireCors; and that UseCors goes after UseRouting and before UseAuthorization.
- What to record
- Each policy with its origins, methods, headers and credentials setting, where it applies, who owns each origin, and whether policies are declared in more than one way.
- Worked evidence (invented example app)
- One named policy, PortalOrigins, allowing https://portal.example.com with credentials, applied with EnableCors on two API controllers. No default policy and no RequireCors. The portal is run by the same team.
Model binding on write endpoints
- Where to look
- Every action, page handler and route handler that creates or updates a record, and the type each one binds to.
- What Microsoft's documentation says
- The model binding article says the Bind and BindNever attributes affect binding from posted form data, not the input formatters that process JSON and XML request bodies, and recommends view models rather than Bind for protection against overposting. The web API tutorial says a DTO may be used to prevent over-posting.
- What to record
- Each write endpoint, whether it binds to a stored entity or to an input model, and for entities, which properties a client could set that the screen never offers.
- Worked evidence (invented example app)
- Twelve write endpoints, eleven of them bound to input models. CustomersController.Edit binds the Customer entity directly, so CreditLimit and IsApproved can be posted; logged for a fix.
Data Protection key storage
- Where to look
- AddDataProtection in Program.cs, with any PersistKeysTo and ProtectKeysWith calls, the hosting platform, and the access settings of the key location.
- What Microsoft's documentation says
- The key management article says the app attempts to detect its operational environment and handle key configuration on its own, that keys on Azure Apps are not protected at rest, and that where no default applies, keys are not persisted outside the process and are lost when it shuts down. The key encryption article says an explicit persistence location turns off the default encryption at rest and recommends an explicit key encryption mechanism for production. The configuration article says only the identity the app runs under should have read, write and create access to a key directory on disk.
- What to record
- Where keys are persisted, how they are encrypted at rest, which identities can read and write that location, and the key lifetime if it was changed. Never open, copy or delete key files.
- Worked evidence (invented example app)
- Keys persisted to a blob container and protected with a Key Vault key (Program.cs line 26). Only the app's managed identity has access to the container and the key. Default 90-day lifetime.
Data Protection key sharing
- Where to look
- SetApplicationName, the number of instances and deployment slots, and any other app pointed at the same key location.
- What Microsoft's documentation says
- The cookie authentication article says an app on multiple machines should use the same key ring and app identifier. The key management article says that with keys in the default Azure Apps folder, separate deployment slots do not share a key ring, so swapping slots logs users out of an app on the standard ASP.NET Core cookie authentication, and that an external key ring provider gives slot-independent key rings. The configuration article says apps are isolated by content root path by default, and that if two apps point at the same repository, a compromise of one is functionally equivalent to a compromise of both.
- What to record
- The application name, whether every instance and slot reads the same ring, and every other app that shares the key location.
- Worked evidence (invented example app)
- SetApplicationName("orders-app") on all three instances. Staging uses a separate container. No other app reads the production key location.
Secrets and configuration
- Where to look
- appsettings.json and each environment's settings file in the repository, the names of the host's environment variables and secret store entries (names only, with values hidden), and any key vault configuration provider.
- What Microsoft's documentation says
- The app secrets article says never to store passwords or other sensitive data in source code or configuration files, not to deploy secrets with the app, and to access production secrets through a controlled means like Azure Key Vault. It says environment variables are commonly stored as plain, unencrypted text, and that the Secret Manager is for development only and does not encrypt. For an app on WebApplication.CreateBuilder, the configuration article ranks environment variables not prefixed with ASPNETCORE_ or DOTNET_ above the settings files.
- What to record
- Each secret by name: where production loads it from, who can read that place, and any tracked settings file holding a value for the same key, recorded by file and key name only.
- Worked evidence (invented example app)
- The database connection string and the payment API key load from Key Vault through the configuration provider. appsettings.json holds an empty ConnectionStrings:Default entry. No tracked file assigns a secret value.
Environment name and production errors
- Where to look
- The ASPNETCORE_ENVIRONMENT and DOTNET_ENVIRONMENT values where production runs, read one by one rather than from a full listing of the environment, which can hold secrets; the IsDevelopment() branches in Program.cs; and the UseExceptionHandler, UseHttpsRedirection and UseHsts calls.
- What Microsoft's documentation says
- The environments article says the environment is Production when neither variable is set, and that DOTNET_ENVIRONMENT, if present, takes precedence in a web app on WebApplication.CreateBuilder. The error handling article says the developer exception page is on by default in Development for apps built on WebApplication.CreateBuilder, and can show the stack trace, query string parameters, cookies and headers, and says not to serve sensitive error information to clients. The HTTPS article recommends UseHttpsRedirection and UseHsts for production web apps unless a reverse proxy does that work.
- What to record
- The environment value in production and where it is set, what Program.cs does outside Development, and whether the error page, HTTPS redirection and HSTS come from the app or the proxy.
- Worked evidence (invented example app)
- ASPNETCORE_ENVIRONMENT=Production in the container definition, with DOTNET_ENVIRONMENT not set. Outside Development, Program.cs calls UseExceptionHandler("/Error") and UseHsts; the load balancer redirects HTTP to HTTPS.
Runtime version and support status
- Where to look
- The output of dotnet --list-runtimes on the production host or in the container image, the TargetFramework in each project file, whether the app is published self-contained, and the .NET support policy page.
- What Microsoft's documentation says
- The support policy says systems must remain current on released patch updates within a release's support lifecycle, and that automatic patching through Microsoft Update on Windows makes no change to apps using the self-contained deployment model, which are still responsible for keeping the runtime updated. Read on 14 November 2026, it listed .NET 10 and .NET 11 as supported, and .NET 8 and .NET 9 as out of support with end of support on 10 November 2026.
- What to record
- The installed Microsoft.AspNetCore.App version, the target framework, the deployment model, and the support status the policy page gives for that release, with the date you read it.
- Worked evidence (invented example app)
- dotnet --list-runtimes in the container image lists one Microsoft.AspNetCore.App 10.0 patch release, recorded with its full version number. TargetFramework is net10.0 and the app is framework-dependent. Support status checked on the policy page and dated.
NuGet package audit
- Where to look
- The NuGetAudit, NuGetAuditMode and NuGetAuditLevel properties in project files or a repository-level MSBuild file, any NuGetAuditSuppress items, and the NU1901 to NU1904 warnings in the build log of the deployed commit.
- What Microsoft's documentation says
- The NuGet auditing guide says restore checks dependencies against known vulnerabilities from the audit sources, that NuGetAudit defaults to true and NuGetAuditLevel to low, that NuGetAuditMode defaults to all for projects targeting net10.0 or higher and to direct otherwise, and that NuGetAuditSuppress should be considered a last resort.
- What to record
- The three settings, each suppressed advisory with its reason and reviewer, and each NU1901 to NU1904 warning with the package named and the version that resolves it. If the build log shows a secret, record only that one is present, never its value.
- Worked evidence (invented example app)
- No audit settings overridden; the mode is all because the projects target net10.0. One NuGetAuditSuppress entry, with a note that the affected code path is not used. The deployed build log shows no NU1901 to NU1904 warnings.
Where ASP.NET Core sits in a .NET application
Microsoft's .NET support policy says .NET refers to several technologies, including the runtime, the SDK, ASP.NET Core and Entity Framework Core.
ASP.NET Core is the web framework among them. Microsoft's overview describes it as a cross-platform, open-source framework for building web apps using .NET, and lists among its features a modular HTTP request pipeline, the Kestrel HTTP server, environment-based configuration, Minimal APIs and Blazor, with built-in features for authentication, authorisation and data protection.
Inside an application, a request passes through the middleware that Program.cs registers and ends at an endpoint: an MVC controller action, a Razor Page, a Minimal API route handler or a Blazor component. The authorisation, authentication, antiforgery and CORS controls in this guide are settings on that path.
Which endpoints need a signed-in user, what a cookie or token must prove, which forms need an antiforgery token, which origins may read a response and where the keys that protect cookies are stored are all set in your code or configuration. A value left at its default is still a setting the project is running with.
This guide covers ASP.NET Core web applications and APIs: the places where a browser or an API client meets your code. By this page's own choice of scope, it leaves out applications built on .NET Framework, desktop apps and the hosting platform underneath. It was written from the ASP.NET Core 10.0 articles on Microsoft Learn, Microsoft's .NET install and NuGet auditing documentation and the .NET support policy page, all read on 14 November 2026.
If your application targets another release, read the same articles for that release and compare the setting names and defaults.
What ASP.NET Core handles and what stays with your project
This page gives no verdict on the framework.
Microsoft's security topics article links articles on authentication, authorisation, data protection, HTTPS enforcement, safe storage of app secrets in development, XSRF/CSRF prevention, CORS and cross-site scripting. Within those areas the documentation describes what some of the built-in features do once they are in use:
- Output encoding. The XSS article says the Razor engine used in MVC automatically encodes all output sourced from variables unless you work to prevent it, and that Tag Helpers also encode input used in tag parameters. It adds that the at symbol must be used only in an HTML context, not when inserting untrusted input directly into JavaScript, and it warns that the HtmlString class is not encoded on output and should never be used with untrusted input.
- Antiforgery on forms. The antiforgery article says Razor Pages are automatically protected from XSRF/CSRF and that the form tag helper injects antiforgery tokens into HTML forms. It also says calling AddControllers alone does not enable antiforgery tokens.
- Encrypted authentication cookies. The cookie authentication article says SignInAsync creates an encrypted cookie, using the Data Protection system for the encryption.
- A default policy. The policy-based authorisation article says the default policy, used by the Authorize attribute without a policy name, requires an authenticated user by default.
What your own code and configuration decide
On this page's reading, each of the following is decided in the application's own code and configuration. Beside each one is what the documentation says about it:
- Which endpoints need a signed-in user at all. The policy-based authorisation article says that by default the fallback policy is null, so an endpoint with no authorisation metadata does not require authorisation.
- Which records a user may open. The resource-based authorisation article says the Authorize attribute does not suffice for resource-based authorisation, because attribute evaluation occurs before data binding and before any method that loads the resource runs.
- Which origins may read responses. Microsoft's CORS article says CORS is not a security feature and that it relaxes security.
- Where Data Protection keys live. The Data Protection configuration article says the default settings are appropriate for apps running on a single machine.
- Where production secrets come from. The app secrets article says the Secret Manager is for development purposes only and does not encrypt what it stores.
- Which environment production runs in. The error handling article says the developer exception page is enabled by default when the app runs in the Development environment and was built on WebApplication.CreateBuilder.
AllowAnonymous exceptions
AllowAnonymous is how an endpoint opts out, and Microsoft's documentation is direct about how far the opt-out reaches.
The MVC authorisation article warns that for MVC controllers AllowAnonymous bypasses authorisation statements: combined with one or more Authorize attributes, the Authorize attributes are ignored. Applied at controller level, any requirement from an Authorize attribute on that controller or its action methods is ignored, and authentication middleware still runs but does not need to succeed.
The policy-based authorisation article says that for AllowAnonymous, as an attribute or as the AllowAnonymous() call, the authorisation middleware does not enforce an authorisation failure for the endpoint.
This page's reading: AllowAnonymous on a controller class opens every action on it, including actions added after the review, and an Authorize attribute a later developer puts on one of those actions does not close it. An AllowAnonymousToFolder convention does the same for pages added to that folder.
So the matrix lists each exception with its scope (action, controller, page, folder, endpoint or group), the reason it is public, what it returns and who confirmed the reason.
Some exceptions are expected. The error handling article says a custom error page has to support anonymous access if signed-out users are to see it. Sign-in, sign-up and password reset pages, health checks and webhook receivers are other candidates, and each still belongs on the list with what it returns.
Policies decide who reaches an endpoint, not which record they open
Microsoft's resource-based authorisation article says this needs special attention in ASP.NET Core.
Attribute evaluation occurs before data binding and before execution of any method that loads a resource, so declarative authorisation with the Authorize attribute does not suffice for resource-based authorisation. The app must invoke a custom authorisation method, an approach the article calls imperative authorisation. Its example loads a document and passes it to IAuthorizationService.AuthorizeAsync with a policy that succeeds when the user authored the document.
This page's reading: an endpoint that takes an order id, carries a role or policy attribute and never checks the loaded order lets every user who meets the policy open any order whose id they can guess.
The check belongs in the handler, as a call to AuthorizeAsync with the record or as a query that already filters by owner or tenant. The policy-based authorisation article adds a detail for anyone writing the authorisation handlers behind those policies: authorisation handlers are called even if authentication fails, and they can execute in any order. The broken access control guide in this library covers how ownership is tested from outside.
Antiforgery in MVC, Razor Pages and Minimal APIs
ASP.NET Core's antiforgery system answers the case the CSRF guide in this library explains: a cookie the browser sends without being asked.
Microsoft's antiforgery article says the system is built on Data Protection, which has to be configured to work in a server farm, and it describes a different arrangement for each kind of endpoint:
- Razor Pages are automatically protected, and the form tag helper injects antiforgery tokens into HTML forms. A form can opt out with asp-antiforgery="false".
- For MVC controllers, ASP.NET Core includes the ValidateAntiForgeryToken, AutoValidateAntiforgeryToken and IgnoreAntiforgeryToken filters. Microsoft recommends AutoValidateAntiforgeryToken broadly for non-API scenarios; it requires a token on requests other than GET, HEAD, OPTIONS and TRACE. IgnoreAntiforgeryToken, applied to an action or controller, overrides ValidateAntiForgeryToken and AutoValidateAntiforgeryToken where they are set at a higher level, globally or on a controller.
- Calling AddControllers does not enable antiforgery tokens. The article says AddControllersWithViews must be called for built-in antiforgery token support.
- Minimal APIs and Blazor need an explicit UseAntiforgery call. By default, Minimal API endpoints that accept form data require antiforgery validation and fail before application code runs if it is not successful.
- DisableAntiforgery() switches the protection off for one endpoint. The article says to use it only for endpoints that are not vulnerable to CSRF, such as those not callable from a browser or those secured with non-cookie authentication, and not for browser-accessible endpoints that rely on cookies for authentication or that process user-submitted form data.
Where the protection is switched off
This page's reading for a review: list each place the protection is off, whether an IgnoreAntiforgeryToken, a DisableAntiforgery() call, a form with asp-antiforgery="false" or an API registered through AddControllers that signs users in with a cookie, and write down what protects each one instead. The same article calls never changing state on a GET request a best practice, and says using HTTPS does not prevent a CSRF attack.
CORS policies and what they relax
Microsoft's CORS article starts from a point worth keeping in view: CORS is not a security feature, it relaxes security, and an API is not safer by allowing it.
The browser enforces CORS, while the server still executes the request and returns the response. The CORS misconfiguration guide in this library covers testing a policy from outside; in ASP.NET Core, the review is about how policies are declared.
- The article describes enabling CORS in middleware with a named or default policy, through endpoint routing with RequireCors, and with the EnableCors attribute. It says a named policy applied through EnableCors gives the finest control, says that when the attribute and a middleware policy are both in use, both policies are applied, recommends against combining them, and says DisableCors does not disable CORS enabled through RequireCors.
- AllowAnyOrigin lets any website make cross-origin requests to the app, which the article calls insecure. It calls AllowAnyOrigin with AllowCredentials an insecure configuration that can result in cross-site request forgery, says the CORS service returns an invalid CORS response when both are set, and says getting around that check with SetIsOriginAllowed(_ => true) and AllowCredentials is also an insecure configuration.
- SetIsOriginAllowedToAllowWildcardSubdomains turns an origin such as https://*.example.com into a match for any subdomain of example.com.
- The article calls allowing cross-origin credentials a security risk, because a site on another domain can send a signed-in user's credentials to the app on the user's behalf without their knowledge.
- The UseCors call goes after UseRouting and before UseAuthorization.
What to record for each policy
For the matrix, record each policy with its origins, whether it allows credentials, the endpoints it applies to and who owns each origin. On this page's reading, a wildcard subdomain entry trusts whatever runs on every subdomain under it, including one later handed to a supplier or a marketing tool.
Model binding and overposting
Model binding fills your objects from request values, and the mass assignment guide in this library covers what happens when it fills in more than the form offered.
Microsoft's model binding article says the Bind and BindNever attributes apply when posted form data is the source and have no effect on input formatters, the part that reads JSON and XML request bodies. It recommends view models rather than the Bind attribute for protection against overposting, and Microsoft's web API tutorial says a DTO may be used to prevent over-posting.
For the matrix, list each endpoint that creates or updates a record and whether it binds to the stored entity or to a separate input model.
Data Protection keys: where they live and who can read them
Data Protection is the key ring behind several controls above.
The cookie authentication article says it encrypts the authentication cookie, and the antiforgery article says antiforgery is implemented with it. Microsoft's key management article says the app attempts to detect its environment and handle key configuration on its own, and describes where keys go by default:
- Hosted in Azure Apps: the %HOME%\ASP.NET\DataProtection-Keys folder, on network storage synchronised across the machines hosting the app. Keys are not protected at rest there, and separate deployment slots such as Staging and Production do not share a key ring, so swapping slots logs users out of an app on the standard ASP.NET Core cookie authentication.
- With a user profile available: the %LOCALAPPDATA%\ASP.NET\DataProtection-Keys folder, with keys encrypted at rest using DPAPI on Windows. The article adds that the app pool's setProfileEnvironment attribute must also be enabled.
- Hosted in IIS: a registry key under HKLM restricted to the worker process account, with keys encrypted at rest using DPAPI.
- None of these: keys are not persisted outside the current process, and when the process shuts down, every generated key is lost.
Containers, lifetime and deletion
In a Docker container, the key management article says keys should be persisted in a Docker volume that persists beyond the container's lifetime, or in an external provider such as Azure Key Vault or Redis. The configuration article adds that only Redis versions supporting Redis Data Persistence should be used to store keys.
Keys have a 90-day lifetime by default, and Microsoft recommends not deleting them, because deleting a key makes its protected data permanently inaccessible.
Encryption at rest, access and sharing
Choosing a location has a cost the documentation spells out. Pointing Data Protection at a specific key repository disables the automatic encryption of keys at rest, and the key encryption article recommends specifying an explicit key encryption mechanism for production deployments. The configuration article asks for the key ring to be protected with appropriate permissions, so that for keys on disk only the identity the web app runs under has read, write and create access to the directory, and it notes that encrypting keys at rest does not prevent attackers creating new keys.
The same article says that if an app is compromised, all master key material accessible to it must be considered compromised, and that if two apps point at the same repository, even with different app discriminators, a compromise of one is functionally equivalent to a compromise of both.
The article also says the Data Protection system isolates apps from one another by their content root paths by default, even when they share a key repository, and that to share protected payloads among apps, each app must set SetApplicationName to the same value and use the same version of the Data Protection API stack.
For the matrix, record where keys are persisted, how they are encrypted at rest, which identities can read and write that location, the application name, and whether every instance and slot shares the ring.
Read all of it from configuration and access settings; never open, copy or delete a key file during the review.
Secrets and configuration in production
ASP.NET Core reads configuration from several sources in an order of priority.
For an app that calls WebApplication.CreateBuilder, Microsoft's configuration article lists the default app configuration sources from highest to lowest priority: command-line arguments; environment variables not prefixed with ASPNETCORE_ or DOTNET_; user secrets, when the app runs in the Development environment; the environment's settings file, such as appsettings.Production.json; appsettings.json; and fallback host configuration.
This page's reading: a value in appsettings.json can be replaced at deployment without anyone editing the file, so the file in the repository may not show what production runs with.
Microsoft's app secrets article is plain about what belongs in those files. It says never to store passwords or other sensitive data in source code or configuration files, not to use production secrets for development or test, not to deploy secrets with the app, and to access production secrets through a controlled means like Azure Key Vault.
It says environment variables are used to keep secrets out of code and local configuration files, and warns that they are commonly stored as plain, unencrypted text that is accessible to untrusted parties if the machine or process is compromised.
The security topics article goes further for production connection strings: it recommends against storing one in an environment variable, and says that for Azure services the most secure authentication is managed identities.
The Secret Manager is the development half of that advice. The app secrets article says it does not encrypt the stored secrets, should not be treated as a trusted store and is for development purposes only, and that the builder WebApplication.CreateBuilder initialises calls AddUserSecrets when the environment name is Development.
The configuration article also warns that a resource owner password credential in a connection string is a security risk that should be avoided in production apps.
For the matrix, record each secret by name: where production loads it from, who can read that place, and whether a tracked settings file in the repository holds a value for the same key. Write down the file and key, never the value, and do not run anything that prints configuration to find out. If a secret has already leaked, the secrets exposure guide in this library sets out the response.
Environment name and production exception handling
Several defaults in this guide depend on the environment name.
Microsoft's environments article says ASP.NET Core reads DOTNET_ENVIRONMENT and ASPNETCORE_ENVIRONMENT, that in an ASP.NET Core web app DOTNET_ENVIRONMENT, if present, takes precedence over ASPNETCORE_ENVIRONMENT (the reverse holds under WebHost, which the article marks obsolete as of .NET 10), and that if neither is set the environment is Production.
It says launchSettings.json is only used on the local development machine and is not deployed, and that apps deployed to Azure App Service adopt Production by default. Among the settings it lists as differing in Production is disabling diagnostic error pages and enabling friendly ones.
The developer exception page is why the value matters. Microsoft's error handling article says it is enabled by default when the app runs in the Development environment and was created on WebApplication.CreateBuilder, and that it can show the stack trace, query string parameters, cookies, headers and endpoint metadata.
Its warning says not to enable the page unless the app is running in Development, and not to share detailed exception information publicly in production. For production it points to UseExceptionHandler and a custom error page, and it repeats a warning: do not serve sensitive error information to clients. The database developer page exception filter is enabled only in Development as well.
This page's reading: in an app built on WebApplication.CreateBuilder, a production server that someone set to Development for a debugging session shows the detailed error page, and the default builder adds user secrets as a configuration source, until the value is changed back. The matrix therefore records the environment value where production actually runs, not what launchSettings.json says, and the lines in Program.cs that decide what happens outside Development.
HTTPS sits on the same path. For production web apps, Microsoft's HTTPS article recommends UseHttpsRedirection to redirect HTTP requests to HTTPS and UseHsts to send HSTS headers. It says the app does not need the redirection middleware where a reverse proxy handles HTTPS redirection, or the HSTS middleware where the proxy writes HSTS headers.
For web APIs it says the project should not listen on HTTP at all, or should close the connection with status code 400 and not serve the request.
.NET versions, patches and ASP.NET Core vulnerabilities
Framework flaws are closed by patches, and Microsoft's .NET support policy sets the terms.
Long Term Support releases get free support and patches for three years and Standard Term Support releases for two, and within a release's support lifecycle, systems must remain current on released patch updates. The final six months of any release are maintenance support, when releases are updated to mitigate security vulnerabilities only.
The policy says use of out-of-support .NET versions may put applications, application data and the computing environment at risk.
Read on 14 November 2026, the policy page listed .NET 11 (Standard Term Support, released 10 November 2026) and .NET 10 (Long Term Support, released 11 November 2025) as supported, both with end of support on 14 November 2028.
It listed .NET 9 and .NET 8 under out of support versions, each with end of support on 10 November 2026. Check the page itself for the release your application runs on.
The policy says updates are cumulative and are released on Patch Tuesday, the second Tuesday of each month, though a given Patch Tuesday may have no .NET release, and that patches are announced on the .NET blog with a digest of monthly releases published to dotnet/announcements.
On Windows, supported versions can be patched through Microsoft Update, which reaches framework-dependent apps; apps that use the self-contained deployment model get no change from it, and the policy says they are still responsible for keeping the runtime updated.
Microsoft's install documentation says dotnet --list-runtimes shows which runtimes are installed on a machine, and its example output lists the Microsoft.AspNetCore.App entries with their versions.
Packages are the other half. Microsoft's NuGet auditing guide says restore checks a project's dependencies against known vulnerabilities from its audit sources, and that the data source for nuget.org's vulnerability database is the GitHub Advisory Database.
Findings appear as warnings NU1901 to NU1904, from low to critical severity. NuGetAudit defaults to true and NuGetAuditLevel to low, and NuGetAuditMode defaults to all when a project targets net10.0 or higher and otherwise to direct, which audits top-level dependencies only.
NuGetAuditSuppress removes an advisory from the report completely, and the guide calls it a last resort. The dependency security guide in this library covers the wider practice.
This page names no individual advisory. Microsoft's policy points to the .NET blog and the dotnet/announcements digests for patches, and the NuGet guide points to the GitHub Advisory Database for package vulnerabilities. The runtime and package rows in the matrix record what you found there and the date you looked.
An ASP.NET Core security checklist drawn from Microsoft's documentation
These best practices are this page's own summary of the Microsoft articles above.
Whoever builds the application decides on each of them, and a row of the matrix records what was decided.
- Where most or all endpoints need a signed-in user, set a fallback policy that requires one, and keep a written list of every AllowAnonymous exception with its reason.
- Check record ownership inside each handler, with AuthorizeAsync and the record or with a query filtered by owner or tenant, since the Authorize attribute is evaluated before the record is loaded.
- Keep UseAuthentication and UseAuthorization ahead of the Map calls, and UseCors after UseRouting and before UseAuthorization.
- Leave JWT validation parameters at their defaults where you can, and give a written reason for every Validate setting turned off.
- Apply AutoValidateAntiforgeryToken across MVC controllers that serve browsers, and treat each IgnoreAntiforgeryToken and DisableAntiforgery() as an exception with a reason.
- Name CORS origins explicitly, do not pair AllowAnyOrigin with AllowCredentials, and declare policies in one way rather than mixing middleware and attributes.
- Bind write requests to input models or DTOs rather than to stored entities.
- Persist Data Protection keys where every instance can reach them, encrypt them at rest explicitly, and limit access to the app's own identity.
- Keep production secrets out of the repository and settings files, use the Secret Manager only in development, and use a managed identity or key vault for production credentials where your platform offers one.
- Confirm the environment is Production where production runs, and keep the developer exception page and detailed errors out of it.
- Run on a supported .NET release, stay current on its released patch updates, and read the NuGet audit warnings from each restore.
How to fill in the ASP.NET Core control matrix
Make one copy for each environment that runs the application, production first, and work down the rows in order.
- Every row reads code, configuration, a log, the output of a listing command or a Microsoft documentation page, apart from the cookie row, which signs one test account in and out once on a staging copy you control. No row changes a setting, rotates or deletes a key, asks you to copy a secret or sends anything to a system you do not own.
- Search the repository for the attributes and calls each row names, and record each hit by file and line. A solution with several projects needs every project that serves requests.
- Record names, never values. A connection string, signing key, client secret or Data Protection key goes in the matrix as a name, the place it is loaded from and the identities that can read that place. If any file, log or listing you read shows a password, key or token, record only that one is present and where, and do not copy it.
- Read the environment value and the runtime version where production runs, from the host's settings or the deployment definition, not from launchSettings.json.
- For the cookie row, use your own staging copy and a test account that holds only test records, with any sign-in email or text going to an address or number you control. Sign in once, read the cookie's attributes in the browser's developer tools, then sign out. That is one sign-in and one sign-out, with no repeated or automated requests. The developer tools also show the cookie's value, which is a live session token for the test account: record the attributes only, and do not copy, paste or screenshot the value.
- The last column is a worked example from an invented app written for this page. Replace it with your own evidence, with file, line and the date you checked.
- Repeat the matrix after a .NET upgrade, a change to Program.cs or the authentication settings, a new controller or route group, or a move to new hosting.
What the control matrix cannot show
The matrix records configuration and code structure.
It shows whether a fallback policy exists and which exceptions it has, how cookies and tokens are validated, where antiforgery and CORS are relaxed, where keys and secrets live, and which runtime and packages are deployed. Apart from the test sign-in and sign-out in the cookie row, it sends no requests to the application, so it cannot show what the running application does when a signed-in user asks for someone else's record, posts a field the form never offered, or sends steps in an order the interface never would.
It also has no view of logic outside its rows: a handler that loads a record by id and compares the wrong owner field, a policy handler that trusts a claim the client can set, or a discount rule that lets a customer stack offers that were never meant to combine.
A clean matrix tells you that the rows you checked match what Microsoft's documentation describes, and says nothing either way about the rest of the code. It is also a snapshot. Date each row, and treat any row older than the last release as unchecked.
Where a Clever Ops assessment fits
This guide is informational.
It describes no .NET-specific service, and nothing on this page describes testing of the .NET platform or of the ASP.NET Core framework. Developers and operators of an ASP.NET Core application fill the matrix in themselves, from their own repository and their own hosting settings.
When your ASP.NET Core application itself needs active testing, it is done within a scoped web application and API penetration test, which is how Clever Ops tests custom web applications and their APIs. That scope needs two test accounts per role with some sample records in each, so one person's access to another's records can be checked both ways within a role, plus accounts in two customer organisations if the application serves more than one.
Before any request is sent, the owner of every target signs a testing authorisation, and your host's testing policy is checked in case it asks for notice or approval.
For code, a secure code review reads the repository through read-only access, against a written scope such as the authorisation layer and every route that returns customer data.
A filled-in matrix gives that scope a starting point, because it already names the endpoints, exceptions, schemes and environments. For an application Clever Ops built or hosts, the engagement is titled a security review rather than an independent penetration test, and its report identifies both the builder and the host.
Emergency incident response and round-the-clock monitoring are not Clever Ops services: if a key or an account may already be in someone else's hands, call an incident response specialist before anything else.
Frequently asked questions
No. Microsoft's policy-based authorisation article says endpoints with no authorisation metadata use the fallback policy if one is configured, and that by default the fallback policy is null, so authorisation is not required. It says the default policy, which by default requires an authenticated user, applies when an endpoint selects it with the Authorize attribute or RequireAuthorization() without a policy name. For a server-side app where most or all endpoints need a signed-in user, the article says to set a fallback policy that requires one and to apply AllowAnonymous to endpoints that are intentionally public.
For MVC controllers, Microsoft's documentation says AllowAnonymous bypasses authorisation statements and the Authorize attributes are ignored. Applied at controller level, any requirement from an Authorize attribute on that controller or its action methods is ignored. Razor Pages conventions have a matching rule: the conventions article says a page cannot be made to require authorisation inside a folder opened with AllowAnonymousToFolder, and that when both filters apply to a page, the anonymous filter takes precedence and controls access.
It depends on where the app runs. Microsoft's key management article says the app attempts to detect its environment. On Azure Apps keys go to a synchronised folder where they are not protected at rest and which separate deployment slots do not share. With a user profile available, and the app pool's setProfileEnvironment attribute enabled, they go to a folder under %LOCALAPPDATA%, encrypted with DPAPI on Windows, and under IIS to a registry key encrypted with DPAPI. Where none of those applies, keys are not persisted outside the process and are lost when it shuts down. In a Docker container it says to persist keys to a volume that outlives the container or to an external provider, and the cookie authentication article says an app on multiple machines should use the same key ring and app identifier.
No. Microsoft's app secrets article says the Secret Manager does not encrypt the stored secrets, should not be treated as a trusted store and is for development purposes only, and that the builder WebApplication.CreateBuilder initialises calls AddUserSecrets when the environment name is Development. For production it says secrets should be accessed through a controlled means like Azure Key Vault, should not be deployed with the app, and should never be stored in source code or configuration files such as appsettings.json.
Not on the date this page was checked. Read on 14 November 2026, Microsoft's .NET support policy page listed .NET 8 and .NET 9 under out of support versions, each with end of support on 10 November 2026, and listed .NET 10 and .NET 11 as supported until 14 November 2028. The policy says use of out-of-support .NET versions may put applications, application data and the computing environment at risk, and that within a release's support lifecycle, systems must remain current on released patch updates. Check the page for the release you run.
No. Microsoft's CORS article says CORS is not a security feature, that it relaxes security, and that an API is not safer by allowing it. The browser enforces CORS while the server still executes the request. The article calls AllowAnyOrigin combined with AllowCredentials an insecure configuration that can result in cross-site request forgery, and calls allowing cross-origin credentials a security risk. This page's advice is to name the origins you trust and leave credentials off unless a known origin needs them.
Scope the right test for your application
Tell us what you have built, who uses it and when it needs to launch. You will get a plain-English recommendation: a website audit, a web application test or a referral to a specialist.