Home › .NET Core Web API
Security — Authentication & Authorization — .NET Core Web API
A comprehensive security implementation covering JWT authentication, authorization policies, CORS, rate limiting, security headers, and input validation. JWT Bearer Authentication Authorization Policies CORS — Allow Only Trusted Origins Rate Limiting Fixed-window rate limiting per IP address: 100 requests per minute. Security Headers Middleware Header Purpose X-Content-Type-Options: nosniff Prevents MIME-type sniffing X-Frame-Options: DENY Prevents clickjacking via iframes Referrer-Policy Limits referrer information leakage X-XSS-Protection Legacy XSS filter (defense-in-depth) Security Checklist Measure Implementation HTTPS Enforcement app.UseHttpsRedirection() redirects HTTP → HTTPS HSTS app.UseHsts() in production — browsers only use HTTPS JWT Validation Validate issuer, audience…
Key Takeaways
- Validate JWT issuer, audience, lifetime, and signing key.
- Use role-based and policy-based authorization — not hardcoded values.
- CORS allows only trusted origins — never use AllowAnyOrigin in production.
- Rate limiting (100 req/min per IP) blocks brute-force attacks.
- Security headers (HSTS, X-Frame-Options, nosniff) on every response.
- Never log tokens, passwords, or sensitive user data.