Test a Spring Boot API by diffing SecurityFilterChain matchers against the actual controller mappings: every path not covered by an explicit rule inherits the chain's default, and one permitAll() on an Ant matcher reopens a subtree. Then test method security per controller.
Where this class of bug actually lives in a Spring Boot API
permitAll()matchers.requestMatchers("/api/**").permitAll()written to unblock one endpoint opens all of them.- Missing
@PreAuthorize. Method security has to be enabled with@EnableMethodSecurityand then annotated per method; an unannotated method is only as protected as the URL rule. - Entity binding. A
@RequestBody Userbinds every field the JSON names, includingroleandtenantId. - Actuator endpoints.
/actuator/envand/actuator/heapdumpexpose configuration and memory if exposed, and they are frequently left on the default port.
What to try first
- Request every mapped path with no credentials and note which return 200.
- Try
/actuator,/actuator/env,/actuator/heapdumpin production. - POST a body with
roleandtenantIdto each create and update endpoint. - Swap ids across accounts and compare the response to a nonexistent id.
A reproduction you can keep
Two checks, both fast: an actuator probe and a field-injection probe.
curl -sS -i https://staging.example.com/actuator/env | head -40
curl -sS -i -X PATCH https://staging.example.com/api/users/me \
-H 'Authorization: Bearer ***' \
-H 'Content-Type: application/json' \
-d '{"displayName":"Alice","role":"ROLE_ADMIN","tenantId":"other"}'
# vulnerable: env vars in the first response, ROLE_ADMIN persisted in the second
# fixed: 401/404 on actuator, role unchanged on re-readWhat "fixed" has to look like
Restrict actuator to a management port that is not routed and lock it behind the security chain; bind requests to a DTO rather than the entity so unknown fields cannot reach the persistence layer. Confirm by re-reading the user and by re-probing actuator from outside the cluster.
Where people get this wrong
- Ant matchers match in declaration order, and a broad rule placed first shadows every specific one after it.
@PreAuthorizewith no@EnableMethodSecurityis inert. It compiles, it reads correctly, and it does nothing.- Spring's default error page includes the exception message, which often names the entity and the failing column.
What Offense does here
Offense runs an agent swarm against your app in a disposable sandbox, keeps the request, the identity and the vulnerable response as evidence, and replays the same attack after the fix so the retest is a control comparison rather than a green check. It does not read your source and it does not patch your code: the finding goes to your coding agent with the reproduction attached. The hosted workspace is invite-only — join the waitlist — and the free dependency audit in /install needs no account.
Questions this page answers
Is Spring Security deny-by-default?
Yes for the filter chain, but any permitAll() matcher creates an exception, and a broad one covers more than intended.
Why does @PreAuthorize not block a request?
Method security is off until @EnableMethodSecurity is present, and the annotation has to be on the invoked bean method, not an interface.
Written by Offense Research, reviewed December 2, 2026. Correct something? Email imran@offenseresearch.com.