T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/send_whatsapp_otp.py:32
- Finding
- TLS Certificate and Hostname Verification Disabled## Vulnerability Details **File Location**: `scripts/send_whatsapp_otp.py:20`, `scripts/send_whatsapp_otp.py:32-44`, and `scripts/send_whatsapp_otp.py:115-124` **Vulnerability Type**: Improper certificate validation **Risk Level**: High ### Vulnerable Code ```python # Suppress SSL warnings for this specific endpoint import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) ``` ```python class SSLAdapter(HTTPAdapter): """Custom adapter to handle problematic SSL configurations""" def init_poolmanager(self, *args, **kwargs): # Create a very permissive SSL context for legacy servers context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) context.check_hostname = False context.verify_mode = ssl.CERT_NONE # Enable legacy server support context.options |= 0x4 # OP_LEGACY_SERVER_CONNECT # Use default minimum TLS version (TLSv1.2) to avoid deprecation warning # but allow legacy server connections via OP_LEGACY_SERVER_CONNECT kwargs['ssl_context'] = context return super().init_poolmanager(*args, **kwargs) ``` ```python # Create a session with custom SSL adapter for problematic endpoints session = requests.Session() session.mount('https://', SSLAdapter()) # Send POST request # Note: Using custom SSL adapter to handle the API endpoint's certificate configuration response = session.post( url, json=payload, headers=headers, timeout=60 ) ``` ### Technical Analysis The custom HTTPS adapter explicitly sets `verify_mode` to `ssl.CERT_NONE` and disables hostname checking. Consequently, the client does not establish that it is communicating with the legitimate `cpaas-rcs.cmidict.com` server. Suppressing `InsecureRequestWarning` also hides an important signal that transport authentication has been disabled. The transmitted JSON includes the tenant access-key secret, applicat ...[truncated 1585 chars]
- Remediation
- ## Remediation Suggestions 1. Remove the custom `SSLAdapter` and use the default `requests` certificate and hostname validation. 2. Remove the global suppression of `InsecureRequestWarning`. 3. If the service uses a private certificate authority, obtain the legitimate CA certificate through a trusted channel and configure a narrowly scoped CA bundle: ```python response = requests.post( url, json=payload, headers=headers, timeout=60, verify="/secure/path/cmi-ca-bundle.pem" ) ``` 4. Do not use `verify=False` as a fallback. 5. Work with the API provider to correct incomplete certificate chains, hostname mismatches, or obsolete TLS settings. 6. Restrict outbound traffic to the documented destination and rotate API credentials if this implementation has been used across untrusted networks.
