BERRY9 IT SERVICES

.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

.NET Core & C# Security Pitfalls: Auth, SQL & Serialization architecture and testing overview

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

Common .NET Core / C# code review findings
ComponentVulnerable PatternRecommended Fix
Entity Framework CoreFromSqlRaw($"SELECT ... {input}") interpolationUse FromSqlInterpolated or SqlParameter bindings
AuthorizationController missing [Authorize] or relying on [AllowAnonymous] broadlySet fallback authorization policy requiring auth by default
DeserializationBinaryFormatter, NetDataContractSerializer, TypeNameHandling.AllMigrate to System.Text.Json without polymorphic type names
RedirectsRedirect(returnUrl) without LocalRedirect() checkUse 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.