T09 · Insecure Skill Coding Practices
- Location
scripts/search_user.py:52- Finding
Disabled TLS Certificate Verification Exposes API Credentials in User Search
- Content
View full analysis
Vulnerability Details
File Location:
scripts/search_user.py, lines 52–60 and 105–125
Vulnerability Type: Improper TLS certificate and hostname validation
Risk Level: MediumComplete Code Snippet
python def _ssl_context(): """Create an SSL context compatible with multiple environments.""" try: ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE except Exception: ctx = None return ctxpython req = urllib.request.Request( API_URL, data=payload, headers={ "Content-Type": "application/json", "X-API-Key": api_key, "User-Agent": "QoderWork/1.0", }, method="POST", ) ctx = _ssl_context() try: kwargs = {"timeout": 30} if ctx: kwargs["context"] = ctx with urllib.request.urlopen(req, **kwargs) as resp: result = json.loads(resp.read().decode("utf-8"))Technical Analysis
The client creates a default TLS context but then explicitly disables both hostname checking and certificate validation:
ctx.check_hostname = Falseallows a certificate issued for an unrelated hostname.ctx.verify_mode = ssl.CERT_NONEaccepts untrusted, self-signed, expired, or attacker-provided certificates.
The resulting context is passed directly to
urllib.request.urlopen. At the same time, the request carriesREDFOX_API_KEYin theX-API-Keyheader. HTTPS encryption without certificate authentication does not establish that the remote endpoint is the intendedredfox.hkservice.An attacker capable of intercepting or redirecting the connection can terminate TLS using an arbitrary certificate. Because the client does not authenticate the server, it will transmit the API key to the impersonated endpoint and process the endpoint's JSON response as trusted RedFox data.
Attack Path
- A user invokes the Skill to search for a Dongchedi user.
search_user.pyreadsREDFOX_API_KEY...[truncated 1357 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the custom context that disables verification and rely on Python's verified default TLS behavior:
python with urllib.request.urlopen(req, timeout=30) as resp: result = json.loads(resp.read().decode("utf-8"))- If a custom SSL context is required, preserve secure validation:
python ctx = ssl.create_default_context() ctx.check_hostname = True ctx.verify_mode = ssl.CERT_REQUIRED-
If the deployment requires a private certificate authority, load only the required CA bundle with
load_verify_locations()rather than disabling validation globally. -
Fail closed when certificate validation fails. Do not retry with
CERT_NONEas a compatibility fallback. -
Revoke and rotate any API key that may have been used over an intercepted connection.
-
Apply least-privilege and expiration controls to RedFox API keys to limit the consequences of credential disclosure.
