GuardAPI Logo
GuardAPI

Fix BFLA (Broken Function Level Authorization) in Spring WebFlux

BFLA occurs when an application exposes sensitive functions to unauthorized users because it assumes obscurity or UI-level hiding is enough security. In Spring WebFlux, this usually happens when developers secure the authentication layer but fail to enforce granular role-based access control (RBAC) on specific reactive routes or controllers. If an attacker can guess the endpoint (e.g., /api/admin/delete-user), and the backend doesn't verify the 'ADMIN' role, your system is compromised.

The Vulnerable Pattern

@RestController
@RequestMapping("/api/admin")
public class AdminController {
    private final UserService userService;
public AdminController(UserService userService) {
    this.userService = userService;
}

// VULNERABLE: Any authenticated user can hit this endpoint
// No explicit check to ensure the user has 'ADMIN' privileges
@DeleteMapping("/users/{id}")
public Mono<Void> deleteUser(@PathVariable String id) {
    return userService.deleteUserById(id);
}

}

The Secure Implementation

To fix BFLA in WebFlux, you must implement defense-in-depth. First, enable '@EnableReactiveMethodSecurity' to allow declarative security annotations. Second, use the 'SecurityWebFilterChain' to define a global security policy that restricts sensitive path patterns (e.g., /api/admin/**) to specific roles. Finally, use '@PreAuthorize' on the controller methods for granular, method-level enforcement. This ensures that even if a route is accidentally exposed in the filter chain, the method itself remains protected by a secondary authorization check.

@Configuration
@EnableReactiveMethodSecurity
public class SecurityConfig {
    @Bean
    public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
        return http
            .authorizeExchange(exchanges -> exchanges
                .pathMatchers("/api/admin/**").hasRole("ADMIN")
                .anyExchange().authenticated()
            )
            .build();
    }
}

@RestController @RequestMapping(“/api/admin”) public class AdminController { @DeleteMapping(“/users/{id}”) @PreAuthorize(“hasRole(‘ADMIN’)”) public Mono deleteUser(@PathVariable String id) { return userService.deleteUserById(id); } }

System Alert • ID: 3821
Target: Spring WebFlux API
Potential Vulnerability

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

74% of Spring WebFlux 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.