Introduction
The OWASP Top 10 ASP.NET Core is the most important baseline for modern web application security. It represents real-world vulnerabilities observed in enterprise systems, SaaS platforms, APIs, and microservices.
For developers working with ASP.NET Core, these risks are not theoretical — they exist in everyday code: controllers, LINQ queries, JWT authentication, configuration, error handling, and external integrations.
A typical application may look clean:
- Dependency Injection ✔
- Entity Framework ✔
- JWT ✔
- Docker ✔
But still be vulnerable.
🔴 Image — Request Security Flow
6
User → Validation → Authentication → Authorization → Business Logic → Database
In OWASP Top 10 ASP.NET Core most vulnerabilities happen when one of these steps is skipped.
1. Broken Access Control
❌ Example 1 — Missing Ownership Check
[HttpGet("{id}")]
public async Task<IActionResult> GetOrder(int id)
{
var order = await db.Orders.FindAsync(id);
return Ok(order);
}Attack
GET /orders/1
GET /orders/2
GET /orders/3
User reads data.
❌ Example 2 — Admin Endpoint Without Role Check
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteUser(int id)
{
var user = await db.Users.FindAsync(id);
db.Users.Remove(user);
await db.SaveChangesAsync();
return Ok();
}✅ Fix
[Authorize(Roles = "Admin")]
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteUser(int id)
{
...
}✅ Secure Ownership Check
var userId = User.FindFirst("sub")?.Value;
var order = await db.Orders
.Where(o => o.Id == id && o.UserId == userId)
.FirstOrDefaultAsync();2. Injection
🔴 Image — SQL Injection
❌ Example 1 — Raw SQL
var sql = "SELECT * FROM Users WHERE Email = '" + email + "'";
var users = db.Users.FromSqlRaw(sql).ToList();❌ Example 2 — Command Injection
Process.Start("cmd.exe", "/c ping " + host);✅ Fix 1 — LINQ
var user = await db.Users
.FirstOrDefaultAsync(x => x.Email == email);✅ Fix 2 — Sanitization + Whitelist
if (!Regex.IsMatch(host, @"^[a-zA-Z0-9.-]+$"))
return BadRequest();3. Cryptographic Failures
🔴 Image — Password Security
6
❌ Example 1 — Plain Password
user.Password = password;❌ Example 2 — Weak Hash
user.Password = SHA1(password);✅ Fix 1 — ASP.NET Identity
await userManager.CreateAsync(user, password);
✅ Fix 2 — Data Protection API
var protector = dataProtectionProvider.CreateProtector("tokens");
var encrypted = protector.Protect("sensitive-data");4. Insecure Design
❌ Example 1 — No Rate Limit
[HttpPost("login")]
public IActionResult Login(LoginDto dto)
{
return Ok(authService.Login(dto));
}❌ Example 2 — No Business Rules
User can order negative quantity:
order.Quantity = -100;✅ Fix 1 — Rate Limiting
builder.Services.AddRateLimiter(options =>
{
options.AddFixedWindowLimiter("login", opt =>
{
opt.PermitLimit = 5;
opt.Window = TimeSpan.FromMinutes(1);
});
});✅ Fix 2 — Domain Validation
if (quantity <= 0)
throw new ArgumentException("Invalid quantity");5. Security Misconfiguration
❌ Example 1 — Swagger Public
app.UseSwagger();❌ Example 2 — Detailed Errors
app.UseDeveloperExceptionPage();✅ Fix
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
}✅ Security Headers
app.Use(async (ctx, next) =>
{
ctx.Response.Headers.Add("X-Content-Type-Options", "nosniff");
ctx.Response.Headers.Add("X-Frame-Options", "DENY");
await next();
});6. Vulnerable Components
❌ Example 1 — Old NuGet
dotnet add package Newtonsoft.Json --version 9.0.1❌ Example 2 — No Dependency Scan
CI without security check.
✅ Fix
dotnet list package --vulnerable✅ CI Check
- name: Check vulnerabilities
run: dotnet list package --vulnerable7. Authentication Failures
🔴 Image — JWT Flow
6
❌ Example 1 — No Validation
ValidateIssuer = false;❌ Example 2 — No Expiration
Token never expires.
✅ Fix
ValidateLifetime = true;
ClockSkew = TimeSpan.Zero;✅ Secure Cookie
options.Cookie.HttpOnly = true;
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;8. Software/Data Integrity Failures
❌ Example 1 — Auto Deploy
OWASP Top 10 ASP.NET Core CI deploys on push without review.
❌ Example 2 — Untrusted Packages
dotnet add package random-lib✅ Fix
✔ Code review required
✔ Signed packages
✔ Private NuGet feed
9. Logging & Monitoring Failures
❌ Example 1
catch { }❌ Example 2
No logs for login attempts.
✅ Fix
logger.LogWarning("Failed login for {Email}", email);✅ Central Logging
builder.Host.UseSerilog();10. SSRF (Server-Side Request Forgery)
❌ Example 1
return await httpClient.GetStringAsync(url);❌ Example 2
Calling internal services via user input.
✅ Fix — Whitelist
var allowed = new[] { "api.partner.com" };✅ Fix — DNS/IP Check
var ip = Dns.GetHostAddresses(uri.Host);
if (ip.Any(i => IPAddress.IsLoopback(i)))
return BadRequest();🔥 Enterprise Security Checklist
✔ Per-user data filtering
✔ Strong JWT validation
✔ Rate limiting
✔ Secure headers
✔ Dependency scanning
✔ Logging & alerting
✔ No raw SQL
✔ Input validation
✔ External call whitelist
✔ CI/CD security gates
Final Thoughts
OWASP Top 10 ASP.NET Core Security is not a feature — it is a continuous process.
Most real vulnerabilities are not complex:
- missing WHERE clause
- missing validation
- wrong config
The OWASP Top 10 helps you avoid exactly those mistakes.
Source
https://github.com/rafalkukuczka/OwaspTop10AspNetCoreDemo
References
https://owasp.org/www-project-top-ten
More Info
We implement this in real production systems.
If you need help → contact us