Preventing Internal Network Access
You'll learn how to stop attackers from using your server to reach internal systems and sensitive metadata endpoints.
Why Block Internal Addresses?
When an attacker exploits SSRF, their first target is often your internal network — resources that should never be accessible from the outside. This includes private IP ranges (like 10.0.0.0/8, 192.168.0.0/16), localhost (127.0.0.1), link-local addresses (169.254.0.0/16), and cloud metadata services (like 169.254.169.254 on AWS).
Think of it like building a fence around your house: even if someone tricks your mail carrier (your server) into delivering packages (requests), the fence prevents deliveries to your bedroom or safe.
Defense Layers
Application Layer: Your code should validate and reject URLs pointing to internal resources before making requests:
- Block private IP ranges entirely
- Reject
localhost,127.0.0.1, and loopback addresses - Blacklist
169.254.169.254(cloud metadata) - Parse and validate the resolved IP, not just the URL string (prevents DNS rebinding)
Network Layer: Configure firewalls and network segmentation:
- Use separate VLANs or security groups for application servers
- Block outbound access to internal networks from application hosts
- Restrict metadata endpoint access using cloud provider controls (e.g., IMDSv2 requiring tokens)
- Implement egress filtering rules
Defense in Depth
The best approach uses both layers: your application validates requests and your network infrastructure enforces boundaries. If an attacker bypasses one layer, the other still protects you.
Key Takeaway: Prevent SSRF attacks from reaching internal resources by blocking private IPs, localhost, and metadata endpoints at both the application code level and through network-layer restrictions like firewalls and segmentation.