Cybrove
Framework Security

Is Spring Boot Secure? Security Features, Risks, and Hardening

Yes, Spring Boot is generally secure when configured correctly. Here is what you need to know about its built-in protections, common vulnerabilities, and how to harden it for production.

Built-in Security Features

Spring Security provides comprehensive auth and access control
CSRF protection enabled by default in Spring Security
BCrypt password encoding configured by default
Actuator endpoints secured by default in production profile
Built-in support for OAuth2 and OpenID Connect

Common Vulnerabilities

SpEL injection through user-controlled expressions
Exposed actuator endpoints in misconfigured deployments
Insecure deserialization in Jackson or Java serialization
SSRF through RestTemplate or WebClient with user-supplied URLs
SQL injection through JPA native queries with string concatenation

Hardening Checklist

1Secure all actuator endpoints and restrict to internal networks
2Use @PreAuthorize and @Secured for method-level security
3Configure CORS with specific origins in WebSecurityConfigurerAdapter
4Use parameterized JPQL or Criteria API instead of native queries
5Enable HTTPS with proper TLS configuration
6Disable unnecessary auto-configuration classes
7Configure CSP headers through Spring Security
8Use Spring Vault or environment variables for secrets management
9Implement rate limiting with Bucket4j or Resilience4j
10Keep Spring Boot and all dependencies updated

Frequently Asked Questions

Is Spring Boot secure?

Yes, Spring Boot is generally secure when configured correctly. It includes built-in protections like spring security provides comprehensive auth and access control. However, common misconfigurations and development patterns can introduce vulnerabilities.

What are the main security risks with Spring Boot?

The most common Spring Boot security risks include spel injection through user-controlled expressions, exposed actuator endpoints in misconfigured deployments, insecure deserialization in jackson or java serialization.

How do I harden Spring Boot for production?

Key hardening steps: Secure all actuator endpoints and restrict to internal networks. Use @PreAuthorize and @Secured for method-level security. Configure CORS with specific origins in WebSecurityConfigurerAdapter. Run a security check on your domain to identify specific issues.

Check if your Spring Boot application has these vulnerabilities

Free security check — SSL, headers, DNS, email authentication, and more. No signup required.

Free Security Check