Missing function-level access control

Missing function-level access control in C#

Description

Check the caller’s administrative permissions before allowing account deletion, deactivation or permission changes.

Potential impact

Unauthorized account changes can affect other users and interrupt their access to the service.

Remediation

Use Authorize to enforce the required role or policy on the server. If the action has no attribute of its own, check the controller and global policies that apply to it.

Examples

Before

csharp
[HttpDelete("delete-user")]
public IActionResult DeleteUser([FromQuery] int id)
{
    return Ok();
}

After

csharp
[Authorize(Roles = "Admin")]
[HttpDelete("delete-user")]
public IActionResult DeleteUser([FromQuery] int id)
{
    return Ok();
}

Both methods return only Ok(). The attribute on the second limits execution of the action to callers in the Admin role.

References