For: anyone running an app or API on ASP.NET Core. No attack steps here — this is a working reference for hardening: a priority-ordered checklist, per-area guidance, and self-verification. For the cross-framework picture, see the security-by-framework hub.
Priority-ordered hardening checklist
Do this table top-down. P0 is a prerequisite, P1 is the most frequent source of incidents, P2 is ongoing maintenance.
P0 ── Prerequisite (do first)
No detailed errors in production / externalize secrets / patch NuGet dependency CVEs fast
P1 ── Top source of incidents
Authorization ([Authorize], default-deny, owner) / over-posting defense (DTOs/[Bind])
P2 ── Ongoing maintenance
Unsafe deserialization / HTTPS, headers, antiforgery / SSRF
| Priority | Control | Specifics (ASP.NET Core) |
|---|---|---|
| P0 | Production errors | UseExceptionHandler. Don't show the Developer Exception Page/detail in prod (correct env check) |
| P0 | Externalize secrets | Don't hardcode in appsettings.json. Dev = User Secrets, prod = env/Key Vault |
| P0 | NuGet dependency CVEs | Monitor with dotnet list package --vulnerable/osv-scanner; judge by running version, patch fast |
| P1 | Explicit authorization | [Authorize] + default-deny (fallback policy) + resource-based/owner checks |
| P1 | Over-posting defense | Bind to a DTO, not the entity directly. Use [Bind] to limit accepted fields |
| P2 | Deserialization | Don't use BinaryFormatter. Don't restore untrusted data with an unsafe format |
| P2 | HTTPS/headers/CSRF | UseHttpsRedirection, UseHsts, antiforgery (CSRF), cookie attributes |
| P2 | SSRF | Allowlist server-side fetches + block internal IPs/metadata |
1. Production error exposure (P0)
- In production, switch to a generic error via
UseExceptionHandlerand don't show the Developer Exception Page/detail (get the environment check right, e.g.ASPNETCORE_ENVIRONMENT=Production). - Don't leak stack traces or internal structure externally.
2. Externalize secrets (P0)
- Don't hardcode connection strings or keys in appsettings.json. Use User Secrets in development and environment variables or a cloud secret manager (Key Vault) in production.
- appsettings.json leaks easily via accidental commit or exposure. Don't commit it to the repo or place it in a public directory (→ keep secrets out of public directories). Rotate promptly if leaked.
3. NuGet dependency CVEs (P0)
- Machine-monitor known CVEs with
dotnet list package --vulnerableor osv-scanner, judge by the running version, and patch fast (→ monitoring dependency CVEs · the vulnerability-response playbook). - Keep .NET on a supported version and don't leave EOL versions in place.
4. Authorization (P1 — the top source)
Common (dangerous)
- forgetting
[Authorize]on an endpoint - authenticated, but no owner check
- default leans "allow," so unauthenticated requests get through
- no role/policy design, ad-hoc checks
Correct
[Authorize]+ default-deny via a fallback policy- role/policy-based + resource-based authorization for ownership
- verified on every read/update/delete path
- authorization built explicitly, not left to defaults
See what IDOR is. Authentication and authorization differ; authorize close to the data.
5. Over-posting (P1)
- Don't bind entities directly. Bind to an input-only DTO and accept only the fields you need.
- Or use
[Bind]to explicitly limit the accepted fields. Don't let a privilege flag be overwritten from external input.
6. Unsafe deserialization and input (P2)
- Don't use
BinaryFormatter(obsolete/insecure). Don't restore untrusted data with an unsafe format (can lead to RCE under the right conditions) (→ what RCE is). - Validate input with model validation (data annotations, etc.) for type/range/allowed values before use.
7. HTTPS, headers, antiforgery (P2)
- Use
UseHttpsRedirection+UseHststo force HTTPS, and mark cookies secure/httponly/samesite. - Use antiforgery tokens (CSRF defense) on forms/state-changing requests (→ what CSRF is).
- Add security headers (check your own site with the security headers checker).
8. SSRF and server-side fetches (P2)
- Server-side (
HttpClient, etc.) fetching of user-supplied URLs should restrict targets to an allowlist and block reaching internal IPs/metadata (→ what SSRF is). Validate uploads and store them off the public surface.
Verify: is your ASP.NET Core actually hardened?
Building it isn't the end — it's done only once you've checked. These are defensive self-checks against your own environment.
No Developer Exception Page in production
Secrets aren't in config/repo
appsettings.json, and that no secrets are in the repo.Authorization holds
Dependencies and HTTPS/headers
dotnet list package --vulnerable/osv is clean, and that HTTPS/HSTS are present via the headers checker.This site's view: even on a stable framework, settings and authorization are your responsibility
ASP.NET Core has solid mechanisms for authentication, authorization, and data protection, but production settings and applying authorization are things you must get right per environment and per endpoint. This site is a different stack, but the principle is the same: don't leak internals in production, keep secrets outside config, always write authorization on public endpoints, and monitor dependencies for CVEs. A framework's security features only help with correct settings and explicit authorization.
Read next
- Hub: security by framework · Spring Boot security (also enterprise, similar dependency/authorization issues)
- Practice: the vulnerability-response playbook · monitoring dependency CVEs · keep secrets out of public directories
- Glossary: what IDOR is · what RCE is · CSRF · SSRF
- Tools: security headers checker
Sources and scope
These primary references support the settings, scope or remediation discussed above; links were checked on October 23, 2026. Consult their version and configuration conditions. Checklist priorities and lessons are this site's guidance, not a full-article revalidation or a safety guarantee.