Missing authorization

Missing authorization

Description

For each request to a protected resource, check whether the caller may perform the requested operation on that resource.

Potential impact

Missing checks can expose data or administrative functions. Unauthorized use of limited resources may also disrupt service.

Remediation

Authenticate the caller with a framework such as Spring Security. At each protected endpoint, enforce the role, ownership or other permissions required for the operation and its target.

Examples

Before

The first controller assumes no separate URL or service-layer restriction. Add @EnableMethodSecurity to a Spring configuration class and configure authentication and role mapping.

java
@GetMapping("/admin")
public String getAdminPage() {
    // Sensitive data or an administrator-only function
    return "admin-page";
}

After

java
@GetMapping("/admin")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public String getAdminPage() {
    // Sensitive data or an administrator-only function
    return "admin-page";
}

On the Spring-managed controller, @PreAuthorize checks for the administrator role (ROLE_ADMIN) before the method handles /admin.

Related CVEs

References