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-052 --project .About This Rule
Understanding the vulnerability and how it is detected
ssl.wrap_socket() is a deprecated convenience function that wraps a plain socket with TLS. It was deprecated in Python 3.7 because it has limited configurability, poor defaults, and does not provide the same level of TLS security control as the SSLContext API.
The function has several security concerns: it defaults to ssl.PROTOCOL_TLS which may allow older protocol versions, it does not enforce certificate verification by default (unlike SSLContext(PROTOCOL_TLS_CLIENT)), and it provides limited control over cipher suites, protocol versions, and other TLS parameters.
The replacement is to create an ssl.SSLContext() with the appropriate protocol constant, configure it with minimum protocol version, cipher suites, and certificate requirements, then call context.wrap_socket() on the socket.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Weak Default Configuration
ssl.wrap_socket() may not enforce certificate verification or hostname checking by default, depending on the Python version and how it is called. This can silently create insecure TLS connections that appear to be secured.
No Minimum Protocol Version Enforcement
Without an explicit SSLContext, ssl.wrap_socket() relies on OpenSSL defaults, which may permit negotiation of TLS 1.0 or 1.1 in some configurations. An explicit context allows setting minimum_version = ssl.TLSVersion.TLSv1_2.
Limited Cipher Suite Control
The function parameters do not expose all cipher suite configuration options available in SSLContext. Weak cipher suites from OpenSSL defaults may be negotiated without explicit restriction.
Deprecated API with Reduced Security Maintenance
Deprecated APIs receive less security review and may not benefit from future TLS hardening improvements applied to the SSLContext API. Using SSLContext ensures access to all current and future TLS security controls.
How to Fix
Recommended remediation steps
- 1Replace ssl.wrap_socket() with ssl.create_default_context().wrap_socket() for client connections, which enforces certificate verification and hostname checking.
- 2For server sockets, create an explicit SSLContext(PROTOCOL_TLS_SERVER) with minimum_version set to TLSv1_2, then call context.wrap_socket().
- 3Set ctx.minimum_version = ssl.TLSVersion.TLSv1_2 explicitly on all SSLContext objects to prevent negotiation of older protocol versions.
- 4Configure cipher suites via ctx.set_ciphers() to exclude weak algorithms including RC4, DES, and export-grade ciphers.
- 5Use ctx.load_verify_locations() or ssl.create_default_context(cafile=...) for custom CA certificates.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule detects calls to the top-level ssl.wrap_socket() function from the ssl module. This is distinct from SSLContext.wrap_socket() (which is the recommended replacement). All call sites are flagged since the top-level function is deprecated and has weaker default security properties.
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.
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.
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 Deprecated ssl.wrap_socket() Usage
New feature
Get these findings posted directly on your GitHub pull requests
The Deprecated ssl.wrap_socket() Usage rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.