S
SafeVibe.io
FeaturesHow It WorksPricingDocs
S
SafeVibe.io

The Guardrail for the Vibe Coding Era. Production-grade security for AI-generated code.

Product

  • Features
  • Pricing
  • Security
  • Documentation
  • Learn

Resources

  • Security Guides
  • Next.js Security
  • OWASP Top 10

Legal

  • Privacy Policy
  • Security Docs
  • Terms of Service

© 2026 SafeVibe.io. All rights reserved.

PrivacyTerms
  1. Home
  2. Learn
  3. How to Fix Server-Side Request Forgery (SSRF) in Spring Boot
High SeverityA10:2021 - Server-Side Request ForgeryCWE-918

How to Fix Server-Side Request Forgery (SSRF) in Spring Boot

Learn how to prevent and fix Server-Side Request Forgery (SSRF) vulnerabilities in Spring Boot applications. Step-by-step guide with code examples, security checklists, and best practices.

In This Guide

  • What Is Server-Side Request Forgery (SSRF)?
  • Why It Matters
  • How to Fix It in Spring Boot
  • Security Checklist
  • Spring Boot Security Tips

What Is Server-Side Request Forgery (SSRF)?

Server-Side Request Forgery (SSRF) is a vulnerability where an attacker can cause the server-side application to make HTTP requests to an arbitrary URL chosen by the attacker. The server becomes a proxy, making requests from its own network position, which typically has access to internal services, cloud metadata endpoints, and private network resources that are not directly accessible from the internet.

SSRF attacks exploit any server-side functionality that fetches remote resources based on user-supplied URLs. Common attack surfaces include: URL preview/unfurling features (link previews in chat applications); webhook configurations; file import from URL; PDF generation from URLs; image processing that fetches remote images; and API integrations where the target URL is user-controlled.

In cloud environments (AWS, GCP, Azure), SSRF is particularly dangerous because cloud metadata services (e.g., `http://169.254.169.254`) are accessible from the server and can expose temporary credentials, instance configurations, and secrets. The 2019 Capital One breach, which exposed 100 million records, was enabled by SSRF combined with overly permissive IAM roles.

Why It Matters

SSRF effectively gives attackers network access from the server's perspective. This can expose internal services that assume network-level trust (databases, caches, admin panels), cloud metadata endpoints containing credentials and configuration, private APIs and microservices not intended for external access, and resources behind firewalls or VPNs. In serverless environments, SSRF can access the function's IAM role credentials. The attack can be used for port scanning internal networks, accessing internal dashboards, reading local files (using file:// protocol), and pivoting deeper into the infrastructure.

How to Fix It in Spring Boot

Validate and sanitize all user-supplied URLs. Implement allowlists of permitted domains and IP ranges. Block requests to private IP ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 127.0.0.0/8) and cloud metadata endpoints (169.254.169.254). Use a DNS resolution step before making requests and validate the resolved IP is not internal. Disable unnecessary URL schemes (only allow http/https). Use network segmentation to limit the server's access to internal resources. Implement IMDSv2 on AWS instances to require token-based metadata access. Run URL-fetching operations in isolated network environments. For webhook features, validate the URL at configuration time and at request time (DNS rebinding prevention).

Spring Boot-Specific Advice

  • Use Spring Security for authentication and authorization. Configure it properly -- the default configuration may be too permissive or too restrictive.
  • Use JPA/Hibernate with parameterized queries. Avoid `@Query` with string concatenation and native queries with user input.
  • Spring Security includes CSRF protection by default for server-rendered forms. Keep it enabled for session-based authentication.
  • Use `@Valid` and Bean Validation annotations (`@NotNull`, `@Size`, `@Pattern`) on request DTOs for input validation.

Spring Boot Security Checklist for Server-Side Request Forgery (SSRF)

Validate and sanitize all user-supplied URLs before making server-side requests
Block requests to private IP ranges (10.x, 172.16.x, 192.168.x, 127.x) and cloud metadata endpoints
Implement URL allowlists for features that fetch external resources
Use DNS resolution validation to prevent DNS rebinding attacks
Disable unnecessary URL schemes (only allow http and https)
Enable IMDSv2 on cloud instances to protect metadata endpoints
Run SafeVibe's SSRF scan on your Spring Boot application

Spring Boot Security Best Practices

1

Use Spring Security for authentication and authorization. Configure it properly -- the default configuration may be too permissive or too restrictive.

2

Use JPA/Hibernate with parameterized queries. Avoid `@Query` with string concatenation and native queries with user input.

3

Spring Security includes CSRF protection by default for server-rendered forms. Keep it enabled for session-based authentication.

4

Use `@Valid` and Bean Validation annotations (`@NotNull`, `@Size`, `@Pattern`) on request DTOs for input validation.

5

Disable Spring Boot Actuator endpoints in production or protect them with authentication. Actuator can expose sensitive internals.

6

Use Spring Security's password encoder (BCryptPasswordEncoder) for password hashing. Never use MD5 or SHA for passwords.

7

Configure CORS using `@CrossOrigin` annotations or `WebMvcConfigurer` with explicit allowed origins.

8

Use `spring-boot-starter-security` and configure `SecurityFilterChain` with method-level security (`@PreAuthorize`) for fine-grained access control.

Scan Your Spring Boot App with SafeVibe

Stop guessing if your Spring Boot app is vulnerable to Server-Side Request Forgery (SSRF). Run an automated penetration test in minutes and get actionable results.

Start Free Scan

Related Guides

Server-Side Request Forgery (SSRF) in Other Frameworks

Next.jsNuxtSvelteKitRemix
View all Server-Side Request Forgery (SSRF) guides

More Spring Boot Security Guides

Cross-Site Scripting (XSS)SQL InjectionCross-Site Request Forgery (CSRF)Insecure Direct Object References (IDOR)
View all Spring Boot guides