.NET Core & C# Security Pitfalls: Auth, SQL & Serialization
Common ASP.NET Core and C# security vulnerabilities found during code reviews: EF Core FromSqlRaw, BinaryFormatter, missing [Authorize], and open redirects.
Source Code Review · By Thimmagurudu Bathini, CTO · Published · 5 min read
Common Gaps in Enterprise ASP.NET Core Apps
ASP.NET Core powers enterprise portals, healthcare backends, and thick-client APIs across India. Even with Entity Framework Core and built-in Identity, subtle mistakes in raw SQL helpers, attribute-based authorization, and legacy deserializers create critical exposures.
// Program.cs: require authenticated users by default on every endpoint
builder.Services.AddAuthorization(options => {
options.FallbackPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
});EF Core, Authorization & Deserializer Pitfalls
| Component | Vulnerable Pattern | Recommended Fix |
|---|---|---|
| Entity Framework Core | FromSqlRaw($"SELECT ... {input}") interpolation | Use FromSqlInterpolated or SqlParameter bindings |
| Authorization | Controller missing [Authorize] or relying on [AllowAnonymous] broadly | Set fallback authorization policy requiring auth by default |
| Deserialization | BinaryFormatter, NetDataContractSerializer, TypeNameHandling.All | Migrate to System.Text.Json without polymorphic type names |
| Redirects | Redirect(returnUrl) without LocalRedirect() check | Use Url.IsLocalUrl() or LocalRedirect() |
Auditing Controllers, Minimal APIs & Configs
- Audit all controllers and Minimal APIs to confirm a global fallback [Authorize] policy is configured.
- Grep for FromSqlRaw, SqlCommand concatenation, BinaryFormatter, and Newtonsoft TypeNameHandling.
- Verify AntiForgeryToken validation on state-changing MVC/Razor endpoints.
- Review appsettings.json and Azure Key Vault bindings for hardcoded connection strings or JWT signing keys.
Enforcing Global Fallback Authorization
Configure a strict global AuthorizationPolicyBuilder fallback in Program.cs so forgetting an [Authorize] attribute never leaves a new endpoint public.
Review your .NET Core APIs or thick clients under NDA starting from ₹36,000 + 18% GST. Request a scoped proposal →
.NET Security Review Questions
Do you review .NET desktop thick clients as well as ASP.NET APIs?
Yes—we test and review both ASP.NET Core web/APIs and .NET WPF/WinForms thick clients.
How is source code shared safely?
Under signed Mutual NDA via read-only private Git access or encrypted archive transfer.