Mass assignment

Mass assignment in C#

Description

Binding a profile update directly to an account object can let client input set fields managed by the server.

Potential impact

Internal account values such as administrator status, balances or permissions may change.

Remediation

Define a request DTO containing only fields the user may edit. Validate their values, then copy those fields to the existing account.

Examples

Before

csharp
currentUser = model;

After

csharp
currentUser.Name = dto.Name;
currentUser.Email = dto.Email;

The revised assignments update only Name and Email on currentUser.

References