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-LANG-SEC-060 --project .About This Rule
Understanding the vulnerability and how it is detected
Using the requests library with http:// URLs transmits all request and response data in plaintext over TCP without TLS encryption. Authentication headers, session tokens, API keys, user data, and all other HTTP content are visible to network observers and MITM attackers.
The requests library makes HTTPS requests trivially easy — simply use https:// in the URL. The library handles TLS certificate verification by default. There is rarely a legitimate reason to use http:// URLs in production application code, except for localhost health checks or explicitly non-sensitive endpoints.
This rule audits requests.get(), requests.post(), requests.put(), requests.patch(), requests.delete(), requests.head(), and requests.Session() calls to flag HTTP URLs.
Security Implications
Potential attack scenarios if this vulnerability is exploited
API Key and Token Interception
API keys, OAuth tokens, and authentication headers transmitted in HTTP requests are visible in plaintext to anyone on the network path, enabling immediate credential theft and unauthorized API access.
Sensitive Data Exposure
Request bodies, query parameters, and response data containing user information, financial data, health records, or other sensitive content are exposed to network observers without TLS encryption.
HTTP Response Tampering
Without TLS, responses can be modified in transit. An attacker can inject malicious content, alter API responses to change application behavior, or redirect to malicious endpoints by manipulating redirect responses.
Mixed Content and Redirect Downgrade
Applications that start with HTTPS but follow redirects to HTTP URLs can be downgraded to HTTP mid-session. The requests library follows redirects by default, potentially following a redirect from https:// to http:// and exposing session credentials.
How to Fix
Recommended remediation steps
- 1Replace all http:// URLs with https:// URLs in requests calls.
- 2Use HTTPS for all API endpoints, even internal service-to-service communication.
- 3Set a base URL with HTTPS in requests.Session() and use relative paths to prevent accidentally mixing HTTP and HTTPS.
- 4Configure HSTS on your servers so clients are redirected to HTTPS even if they accidentally use HTTP URLs.
- 5Add URL validation in your application that rejects or upgrades HTTP URLs to HTTPS before making requests.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule detects calls to requests.get(), requests.post(), requests.put(), requests.delete(), requests.patch(), requests.head(), requests.options(), and requests.request() where the URL argument starts with "http://" (not "https://"). This covers both literal HTTP URLs and variable URLs that can be determined to use HTTP by taint analysis.
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
Certificate Validation Disabled (verify=False)
TLS certificate validation is explicitly disabled via verify=False or CERT_NONE, making connections vulnerable to man-in-the-middle attacks.
Insecure HTTP Connection via http.client
http.client.HTTPConnection transmits data in plaintext without encryption. Use HTTPSConnection for sensitive communications.
Insecure urllib.request.urlopen() Usage
urllib.request.urlopen() over HTTP transmits data in plaintext. Verify HTTPS URLs are used and SSL context is properly configured.
Frequently Asked Questions
Common questions about HTTP Request Without TLS (requests library)
New feature
Get these findings posted directly on your GitHub pull requests
The HTTP Request Without TLS (requests library) rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.