T09 · Insecure Skill Coding Practices
- Location
scripts/feishu_image.py:33- Finding
TLS Certificate and Hostname Verification Disabled for All Feishu API Requests
- Content
View full analysis
Vulnerability Details
File Location:
scripts/feishu_image.py, lines 33–36; the insecure context is used at lines 79, 134, 173, 195, and 231
Vulnerability Type: Improper TLS certificate validation
Risk Level: HighVulnerable Code
python # Create a context that does not verify SSL certificates SSL_CONTEXT = ssl.create_default_context() SSL_CONTEXT.check_hostname = False SSL_CONTEXT.verify_mode = ssl.CERT_NONEThe context is passed to every Feishu API request, for example:
python with urllib.request.urlopen(req, timeout=30, context=SSL_CONTEXT) as resp: result = json.loads(resp.read().decode("utf-8"))Equivalent uses occur in token acquisition, image upload, message delivery, image download, and image viewing.
Technical Analysis
Setting
check_hostnametoFalseprevents verification that the server certificate belongs toopen.feishu.cn. Settingverify_modetossl.CERT_NONEdisables certificate-chain validation. Consequently, TLS encrypts the connection but does not authenticate the remote endpoint.This affects all requests made by the script. Of particular concern, the token endpoint receives the Feishu
app_idandapp_secretin the request body. Subsequent operations transmit the tenant bearer token, uploaded image contents, recipient identifiers, image keys, and message data.A network-positioned attacker who can intercept or redirect traffic can present an arbitrary certificate, impersonate the Feishu API, and read or modify these requests. No certificate warning or validation failure will stop the connection.
The base64 conversion in the
viewcommand is not independently malicious: it encodes downloaded image bytes for the documented local output behavior. Likewise, communication with the fixed Feishu API endpoint is required by the declared functionality. The security issue is that these necessary communications occur without authenticating the endpoin ...[truncated 1774 chars]- Remediation
View remediation
Remediation Suggestions
-
Remove the global context that disables certificate and hostname verification.
-
Use Python's default verified TLS behavior:
python with urllib.request.urlopen(req, timeout=30) as resp: result = json.loads(resp.read().decode("utf-8")) -
Apply the same change to every request at lines 79, 134, 173, 195, and 231.
-
If a custom certificate authority is genuinely required, create a validating context using an explicitly trusted CA bundle:
python SSL_CONTEXT = ssl.create_default_context(cafile="/path/to/trusted-ca.pem")Keep hostname verification enabled and use
ssl.CERT_REQUIRED. -
Do not use
ssl.CERT_NONEor disablecheck_hostnameas a workaround for local certificate-store problems. Repair the host CA store or configure the correct CA bundle instead. -
Avoid exposing credentials or bearer tokens in exceptions and logs. Maintain the current behavior of not printing them directly.
-
After deploying the fix, rotate the Feishu application secret and revoke or refresh relevant tokens if the insecure version was used on an untrusted network.
-
Add an automated test that connects to an endpoint with an untrusted or hostname-mismatched certificate and verifies that the request fails.
-
