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-050 --project .About This Rule
Understanding the vulnerability and how it is detected
ssl._create_unverified_context() creates an SSL context that does not verify the server's certificate. With certificate verification disabled, a TLS connection provides only encryption confidentiality — it does not authenticate the server, meaning an attacker on the network path can perform a man-in-the-middle (MITM) attack by presenting any TLS certificate and intercepting all traffic.
The leading underscore in the function name signals that it is a private, internal function not intended for general use. It exists to provide a workaround for legacy code that cannot use valid certificates. The public API ssl.create_default_context() is the correct function to use, as it enables certificate verification with proper CA chain validation.
This function is sometimes used as a quick fix for certificate errors in development, then accidentally committed to production code. Its presence in production code is always a critical security finding.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Man-in-the-Middle Attack
Without certificate verification, any attacker on the network path can present a self-signed or fraudulent TLS certificate. The Python client accepts it without validation, and the attacker can read and modify all "encrypted" traffic.
Credential and Session Token Interception
Unverified TLS connections protect data from passive eavesdropping but not from MITM attacks. Login credentials, session tokens, API keys, and sensitive data transmitted over these connections can be captured by an attacker positioned between the client and server.
Data Integrity Failure
MITM attackers can modify request and response data in transit, injecting malicious content into responses, altering financial transaction amounts, or replacing software downloads with malicious binaries.
Regulatory Compliance Violation
Disabling certificate verification violates PCI DSS Requirement 4.2.1 (secure transmission of cardholder data), HIPAA technical safeguards, and most data protection regulations that mandate proper TLS implementation.
How to Fix
Recommended remediation steps
- 1Replace ssl._create_unverified_context() with ssl.create_default_context() which enables certificate verification with the system CA store.
- 2If connecting to a server with a self-signed or private CA certificate, use ssl.create_default_context(cafile=path_to_ca) to specify the trusted CA.
- 3Never disable certificate verification as a workaround for certificate errors; fix the underlying certificate issue instead.
- 4In development environments, use a local CA (such as mkcert) to issue development certificates trusted by your machine rather than disabling verification.
- 5Audit all SSL context creation in the codebase to ensure CERT_REQUIRED is the validation mode and no custom cert verification bypass is present.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule detects calls to ssl._create_unverified_context() in Python source code. All call sites are flagged since this function unconditionally disables certificate verification and is never appropriate for production use.
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
Weak SSL/TLS Protocol Version
SSLContext configured with SSLv2, SSLv3, TLSv1.0, or TLSv1.1 uses deprecated protocols with known vulnerabilities. Use TLS 1.2 or TLS 1.3.
Deprecated ssl.wrap_socket() Usage
ssl.wrap_socket() is deprecated since Python 3.7 and should be replaced with SSLContext.wrap_socket() for proper TLS configuration.
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.
Frequently Asked Questions
Common questions about Unverified SSL Context Created
New feature
Get these findings posted directly on your GitHub pull requests
The Unverified SSL Context Created rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.