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-054 --project .About This Rule
Understanding the vulnerability and how it is detected
http.client.HTTPConnection creates an unencrypted HTTP connection that transmits all data in plaintext. Any data sent over this connection including authentication tokens, session cookies, API keys, user data, and sensitive parameters can be intercepted by anyone on the network path between the client and server.
HTTP (without TLS) should not be used for any endpoint that transmits sensitive data. HTTPSConnection (http.client.HTTPSConnection) uses TLS to encrypt the connection, protecting data confidentiality and authenticating the server.
HTTPConnection is appropriate for: internal health check endpoints on localhost, connections to infrastructure components on a private, isolated network where TLS termination occurs at a load balancer, and specific protocol requirements. For all other use cases, HTTPSConnection or the requests library with HTTPS URLs should be used.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Credential Interception
Authentication headers (Basic auth, Bearer tokens, API keys), form credentials, and session cookies transmitted over HTTP are visible in plaintext to any observer on the network, including the ISP, corporate network monitoring, and MITM attackers.
Session Hijacking
HTTP cookies visible on the network allow session hijacking: an attacker who captures the session token can use it to authenticate as the victim without knowing the password.
Data Integrity Failure
HTTP provides no integrity protection. An attacker on the network path can inject, modify, or suppress HTTP traffic. Responses can be modified to serve malicious content, and requests can be altered to change transaction parameters.
Compliance Violations
Transmitting cardholder data (PCI DSS), health information (HIPAA), or personal data (GDPR) over unencrypted HTTP violates regulatory requirements and may result in significant fines and mandatory breach notifications.
How to Fix
Recommended remediation steps
- 1Replace http.client.HTTPConnection with http.client.HTTPSConnection for all external service calls.
- 2Use the requests library with https:// URLs as a higher-level, safer alternative to http.client.
- 3For internal service-to-service communication in containerized environments, use HTTPS even on private networks to protect against internal threats and lateral movement.
- 4If HTTP must be used for specific infrastructure reasons (health checks, load balancer endpoints), ensure sensitive data is never transmitted over these endpoints.
- 5Configure HSTS (HTTP Strict Transport Security) on servers to prevent clients from accidentally connecting over HTTP.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule detects calls to http.client.HTTPConnection() and the equivalent httplib.HTTPConnection() (Python 2 compatibility) constructor. All call sites are flagged since plaintext HTTP is inappropriate for sensitive data transmission and requires review to confirm the use case is safe.
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
Unverified SSL Context Created
ssl._create_unverified_context() disables certificate verification entirely, making TLS connections vulnerable to man-in-the-middle attacks.
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.
HTTP Request Without TLS (requests library)
HTTP URLs in requests calls transmit data in plaintext without encryption. Use HTTPS URLs for sensitive data transmission.
Frequently Asked Questions
Common questions about Insecure HTTP Connection via http.client
New feature
Get these findings posted directly on your GitHub pull requests
The Insecure HTTP Connection via http.client rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.