← Java / Spring · Contents

JAVA-021 / Intermediate

Overly permissive Spring Security path rules (permitAll abuse)

A01:2021 Broken Access Control · CWE-284 Improper Access Control

Why is this a problem?

Rules following /** are ignored; wildcard ordering mistakes can expose admin APIs.

How to fix it

java
http.authorizeHttpRequests(a -> a
  .requestMatchers("/api/public/**").permitAll()
  .requestMatchers("/api/admin/**").hasRole("ADMIN")
  .anyRequest().authenticated());

Further reading