SSRF in Server-Side Rendering
Description
The application performs server-side rendering or processing of user-supplied data without proper validation, allowing Server-Side Request Forgery (SSRF) attacks. An unauthenticated attacker can exploit this vulnerability to force the server to make HTTP requests to arbitrary destinations, including internal network resources that are normally inaccessible from the internet. In some configurations, this may also enable reading local files from the server's filesystem.
Remediation
Implement comprehensive input validation and request filtering to prevent SSRF attacks:
1. Use an allowlist approach: Only permit requests to explicitly approved domains and IP addresses. Reject all others by default.
2. Validate and sanitize URLs: Parse user-supplied URLs and validate each component (protocol, hostname, port). Block requests to private IP ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), localhost (127.0.0.0/8), link-local addresses (169.254.0.0/16), and internal DNS names.
3. Disable unnecessary URL schemes: Only allow HTTP and HTTPS protocols. Block file://, gopher://, ftp://, and other schemes.
4. Implement network-level controls: Use separate network segments for external requests and restrict outbound connections from application servers using firewall rules.
Example validation (Python):
import ipaddress
from urllib.parse import urlparse
def is_safe_url(url, allowed_domains):
parsed = urlparse(url)
# Only allow HTTP/HTTPS
if parsed.scheme not in ['http', 'https']:
return False
# Check against allowlist
if parsed.hostname not in allowed_domains:
return False
# Block private IP ranges
try:
ip = ipaddress.ip_address(parsed.hostname)
if ip.is_private or ip.is_loopback or ip.is_link_local:
return False
except ValueError:
pass # Not an IP address
return True5. Use dedicated libraries: Leverage security-focused HTTP client libraries that provide built-in SSRF protections and disable automatic redirects to prevent bypass attempts.