GuardAPI Logo
GuardAPI

Fix BFLA (Broken Function Level Authorization) in Spring Boot

BFLA (Broken Function Level Authorization) occurs when the server-side fails to enforce hierarchical access controls. Attackers exploit this by directly hitting administrative or sensitive endpoints that developers erroneously assumed were hidden by the UI. In Spring Boot, this usually manifests as exposed @RestController methods that lack explicit role-based or permission-based checks, allowing any authenticated user—or even unauthenticated ones—to execute privileged operations.

The Vulnerable Pattern

@RestController
@RequestMapping("/api/v1/management")
public class AdminController {
@Autowired
private UserService userService;

// VULNERABLE: No authorization check. 
// Any user with a valid JWT/Session can delete any user.
@DeleteMapping("/users/{id}")
public ResponseEntity<Void> deleteUser(@PathVariable Long id) {
    userService.deleteUserById(id);
    return ResponseEntity.ok().build();
}

}

The Secure Implementation

To kill BFLA, stop relying on 'security by obscurity' and UI-side restrictions. 1. Enable `@EnableMethodSecurity` in your configuration. 2. Implement the Principle of Least Privilege by tagging every sensitive endpoint with `@PreAuthorize`, `@PostAuthorize`, or `@Secured`. 3. For complex logic, use SpEL (Spring Expression Language) to verify if the authenticated user owns the resource or has a specific permission (e.g., `hasPermission`). 4. Ensure your `SecurityFilterChain` is configured with a 'deny-all' fallback to catch any endpoints you forgot to protect.

@Configuration
@EnableMethodSecurity
public class SecurityConfig {}

@RestController @RequestMapping(“/api/v1/management”) public class AdminController {

@Autowired
private UserService userService;

// SECURE: Enforces 'ADMIN' role at the method level.
// Rejects requests with 403 Forbidden if the authority is missing.
@DeleteMapping("/users/{id}")
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<Void> deleteUser(@PathVariable Long id) {
    userService.deleteUserById(id);
    return ResponseEntity.ok().build();
}

}

System Alert • ID: 1852
Target: Spring Boot API
Potential Vulnerability

Your Spring Boot API might be exposed to BFLA (Broken Function Level Authorization)

74% of Spring Boot apps fail this check. Hackers use automated scanners to find this specific flaw. Check your codebase before they do.

RUN FREE SECURITY DIAGNOSTIC
GuardLabs Engine: ONLINE

Free Tier • No Credit Card • Instant Report

Verified by Ghost Labs Security Team

This content is continuously validated by our automated security engine and reviewed by our research team. Ghost Labs analyzes over 500+ vulnerability patterns across 40+ frameworks to provide up-to-date remediation strategies.