Interactive Playground
Experiment with the vulnerable code and security rule below. Edit the code to see how the rule detects different vulnerability patterns.
pathfinder scan --ruleset python/PYTHON-DJANGO-SEC-030 --project .About This Rule
Understanding the vulnerability and how it is detected
This rule detects Server-Side Request Forgery (SSRF) vulnerabilities in Django applications where untrusted user input from HTTP request parameters flows into the URL argument of the requests library (requests.get(), requests.post(), requests.put(), requests.delete(), requests.head(), requests.Session().get()).
SSRF occurs when an application fetches resources from a URL that an attacker controls. The server-side HTTP request originates from inside the application's network, allowing attackers to: access cloud provider metadata endpoints (http://169.254.169.254/), reach internal services not exposed to the internet, bypass network firewalls that trust the application server, scan the internal network topology, and in some cases read sensitive files via file:// URLs.
In cloud environments (AWS, GCP, Azure), the instance metadata service is a particularly dangerous target. An attacker can use SSRF to retrieve IAM credentials, user-data scripts containing secrets, and other sensitive configuration from the metadata endpoint.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Cloud Metadata Service Credential Theft
Cloud providers expose instance metadata at http://169.254.169.254/ (AWS, GCP) or http://169.254.169.254/metadata/ (Azure). An attacker who controls the URL can make the application fetch its own IAM credentials, which can then be used to access all AWS S3 buckets, RDS databases, and other cloud resources the application role can access.
Internal Network Service Scanning and Access
The application server typically has access to internal services like Redis, Elasticsearch, databases, and admin panels that are not exposed to the internet. SSRF enables attackers to send requests to these internal services, potentially triggering unauthenticated operations on Redis (FLUSHALL), Elasticsearch (index deletion), or internal admin endpoints.
Sensitive File Read via file:// Scheme
Some HTTP client libraries honor file:// URLs, allowing SSRF to read local files from the application server, including /etc/passwd, application secrets, private keys, and Django settings files containing database credentials.
Security Control Bypass via Internal Endpoints
Internal microservices often skip authentication for requests from trusted internal IP ranges. SSRF bypasses perimeter security by making the trusted application server send the request, allowing attackers to invoke privileged internal API endpoints without credentials.
How to Fix
Recommended remediation steps
- 1Validate user-supplied URLs against a strict allowlist of trusted domains before making server-side HTTP requests.
- 2Block all requests to private IP ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), loopback (127.0.0.0/8), and link-local (169.254.0.0/16) addresses.
- 3Restrict allowed URL schemes to http and https only, blocking file://, gopher://, ftp://, and other schemes.
- 4Set allow_redirects=False and validate redirect targets separately, as redirects can bypass initial URL validation.
- 5Consider using an egress proxy or network-level controls to restrict outbound HTTP requests to known-safe destinations regardless of application logic.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule performs inter-procedural taint analysis with global scope. Sources include calls("request.GET.get"), calls("request.POST.get"), calls("request.GET.__getitem__"), calls("request.POST.__getitem__"), calls("request.body"), and calls("request.read"). Sinks include calls("requests.get"), calls("requests.post"), calls("requests.put"), calls("requests.delete"), calls("requests.head"), calls("requests.request"), and calls("requests.Session.get") with tainted URL argument tracked via .tracks(0). Sanitizers include URL validation functions that check against allowlists and block private IP ranges. The rule follows taint across file and module boundaries.
Compliance & Standards
Industry frameworks and regulations that require detection of this vulnerability
References
External resources and documentation
Similar Rules
Explore related security rules for Python
Frequently Asked Questions
Common questions about Django SSRF via requests Library
New feature
Get these findings posted directly on your GitHub pull requests
The Django SSRF via requests Library rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.