logo

Database

C Sharp Override Auth Modifier

Description

Detects potential authorization bypass vulnerabilities in C# code where methods are marked with [AllowAnonymous] while being in a class that has authorization requirements. This misconfiguration could allow unauthorized access to protected functionality.

Weakness:

056 - Anonymous connection

Category: Access Subversion

Detection Strategy

    Look for C# method declarations in the code

    Check if the method is within a class that has authorization requirements (like [Authorize] attribute)

    Verify if the method is marked with the [AllowAnonymous] attribute

    Report a vulnerability if a method with [AllowAnonymous] exists in an authorized class, as this could create unintended security bypasses

Vulnerable code example

[AllowAnonymous] // Dangerous: Allows unauthenticated access to entire controller
public class AdminController : Controller 
{
    public ActionResult SensitiveData() 
    {
        return View(GetConfidentialRecords());
    }
}

✅ Secure code example

[Authorize] // Secure: Requires authentication for all actions by default
public class AdminController : Controller 
{
    [Authorize(Roles = "Admin")] // Additional protection: Requires Admin role for sensitive data
    public ActionResult SensitiveData() 
    {
        return View(GetConfidentialRecords());
    }...