تخطَّ إلى المحتوى

Mass assignment (ARCH340)

هذا المحتوى غير متوفر بلغتك بعد.

Key dotnet.security.mass-assignment · Severity warning · Category security · CWE CWE-915

When an action binds the whole request into a type and hands that same object to Add, Update or Attach, every bindable property - IsAdmin, Balance, OwnerId - is whatever the caller sent. TryUpdateModelAsync(entity) without an include list has the same effect.

[HttpPost]
public IActionResult Create(User user)
{
_db.Users.Add(user);
_db.SaveChanges();
return Ok();
}
[HttpPost]
public IActionResult Create(CreateUserRequest request)
{
var user = new User { Name = request.Name, Email = request.Email };
_db.Users.Add(user);
_db.SaveChanges();
return Ok();
}

Bind a request DTO and copy only the allowed properties onto the entity, or pass the property allowlist overload of TryUpdateModelAsync.