Spring Boot Security Standards
Priority: P0 (CRITICAL)
Configure SecurityFilterChain
- Lambda DSL: ALWAYS use Lambda DSL.
- SecurityFilterChain: Expose as
@Bean. Do not extendWebSecurityConfigurerAdapter. - Statelessness: Enforce
SessionCreationPolicy.STATELESSfor REST APIs.
See implementation examples for SecurityFilterChain configuration with Lambda DSL and JWT.
Implement Authentication and Authorization
- Authentication: Validation of credentials (Who are you?). Use
AuthenticationManagerorJwtDecoder. - Authorization: Verification of access rights (Can you do this?). Use
@PreAuthorize.
Secure JWT Tokens
- Algorithm: Enforce
RS256orHS256. Rejectnonealgorithm. - Claims: Validate
iss,aud, andexp. - Tokens: Short-lived access tokens (15m), secure refresh tokens (httpOnly cookie).
Hardening Checklist
- [ ] CSRF: Disabled for pure APIs? Enabled + Cookie for Browser Apps?
- [ ] CORS: Specific origins permitted? No
*with credentials? - [ ] Headers: HSTS, Content-Type-Options, X-Frame-Options enabled?
- [ ] Secrets: No hardcoded keys? Loaded from Vault/Env?
- [ ] Rate Limiting: Applied on login/expensive endpoints?
- [ ] Dependencies: Scanned for CVEs?
Anti-Patterns
- No Adapter: Use
SecurityFilterChainbean instead of extending legacy classes. - No .and(): Use Lambda DSL for configuration.
- No Secrets: Load from Vault or Environment variables (never git).
- No antMatchers: Use
requestMatchers(Spring Security 6+).
References
- Implementation Examples
- common/security-standards
- architecture