Mass Assignment in Aspnet with Mutual Tls
Mass Assignment in Aspnet with Mutual Tls — how this specific combination creates or exposes the vulnerability
Mass assignment in ASP.NET occurs when an action method binds incoming HTTP data (form values, JSON, query strings) directly to a model or entity without explicit filtering. When mutual TLS (mTLS) is used for client authentication, the server validates the client certificate but does not inherently limit what data a successfully authenticated client can submit. This combination can create or expose risk because authentication (mTLS) and authorization (model binding) are treated as separate layers, allowing an authenticated client to over-post or manipulate properties they should not access.
For example, consider an ASP.NET Core controller that accepts JSON to update a user profile:
[HttpPut("profile")]
public IActionResult UpdateProfile(UserProfileModel model) { /* ... */ }
If UserProfileModel contains sensitive fields such as IsAdmin or Balance and these are not explicitly excluded from binding, an authenticated mTLS client can send those fields in the request body to escalate privileges or change account values. The mTLS handshake ensures the client is known and trusted, but it does not enforce property-level permissions; that responsibility falls to the developer to implement via whitelisted binding, view models, or explicit attribute usage (e.g., [Bind] or [ApiController] with strict validation). Attack patterns like this are commonly mapped to OWASP API Top 10 — BOLA/IDOR and Unsafe Consumption — and can lead to unauthorized data modification or elevation of privilege.
In scans that validate unauthenticated attack surfaces, middleBrick checks for missing property authorization and unsafe consumption practices. Even when mTLS is in place, findings may highlight endpoints where mass assignment is possible, emphasizing that transport-layer client authentication does not replace input and model binding controls. Proper remediation requires explicit control over which properties are bindable, regardless of the strength of the client certificate.
Mutual Tls-Specific Remediation in Aspnet — concrete code fixes
To secure ASP.NET applications with mutual TLS while preventing mass assignment, combine mTLS enforcement with strict model binding practices. Below are concrete code examples that demonstrate a secure approach.
Enforce Mutual TLS in ASP.NET Core
Configure the server to require and validate client certificates. In Program.cs, use the following setup for Kestrel:
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(serverOptions =>
{
serverOptions.ListenAnyIP(5001, listenOptions =>
{
listenOptions.UseHttps(httpsOptions =>
{
httpsOptions.ClientCertificateMode = ClientCertificateMode.RequireCertificate;
httpsOptions.AllowAnyClientCertificate(); // Consider using a custom validator for strict checks
// Optionally configure certificate policies, e.g., revocation
});
});
});
This enforces mTLS at the transport layer, ensuring only clients with a trusted certificate can establish a connection. Note that mTLS does not filter request payload content; it only authenticates the client.
Prevent Mass Assignment with Explicit Binding
Use view models or explicit binding to allow only intended properties to be updated. For example:
public class UserProfileUpdateModel
{
public string DisplayName { get; set; }
public string Email { get; set; }
// Do not include IsAdmin, Role, or other sensitive properties here
}
In the controller, accept the whitelisted model instead of the domain entity:
[HttpPut("profile")]
public IActionResult UpdateProfile(UserProfileUpdateModel model)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
// Map to domain entity explicitly, updating only allowed fields
var user = _userService.GetCurrentUser();
user.DisplayName = model.DisplayName;
user.Email = model.Email;
_userService.Save(user);
return NoContent();
}
For scenarios where you must bind directly to an entity (not recommended), use the [Bind] attribute to whitelist properties:
[HttpPut("profile")]
public IActionResult UpdateProfile([Bind("DisplayName,Email")] UserProfile user)
{
// Only DisplayName and Email will be bound; other properties are ignored
_userService.Update(user);
return NoContent();
}
Combine this with model validation and anti-forgery measures where appropriate. middleBrick’s checks for property authorization and unsafe consumption can help verify that endpoints adhere to these patterns, even when mTLS is used for client authentication.
Related CWEs: propertyAuthorization
| CWE ID | Name | Severity |
|---|---|---|
| CWE-915 | Mass Assignment | HIGH |