T09 · Insecure Skill Coding Practices
- Location
scripts/search.py:139- Finding
HTTPS Certificate and Hostname Verification Disabled
- Content
View full analysis
Vulnerability Details
File Location:
scripts/search.py, lines 139–147
Vulnerability Type: Improper TLS certificate validation
Risk Level: HighVulnerable Code
python # 禁用 SSL 验证 ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE try: with urllib.request.urlopen(req, timeout=60, context=ctx) as response: result = json.loads(response.read().decode("utf-8"))Technical Analysis
The script creates a TLS context but explicitly disables both hostname validation and certificate-chain verification. Consequently, HTTPS encryption is used without authenticating that the remote endpoint is actually
qianfan.baidubce.com.The request carries the Baidu API key in the
Authorization: Bearerheader. Its body may contain financial queries, custom instructions, and caller-supplied conversation history. A network-positioned attacker can present an arbitrary certificate, impersonate the Baidu endpoint, decrypt the request, and provide a forged response because the client accepts certificates that are untrusted or issued for a different hostname.Attack Path
- A user invokes the Skill to submit a financial search.
- An attacker obtains a network interception position, such as through a malicious proxy, compromised router, hostile Wi-Fi network, or DNS manipulation.
- The attacker redirects or intercepts the connection intended for
qianfan.baidubce.com. - The attacker's server presents an arbitrary TLS certificate.
- Because
check_hostnameisFalseandverify_modeisssl.CERT_NONE, the client accepts the certificate. - The client transmits the Bearer API key and request body to the impersonated endpoint.
- The attacker captures the credential and potentially sensitive request data.
- The attacker can return fabricated JSON containing manipulated financial analysis or references, which the script formats and presents as a legitimate result.
Impact Assessment
Su ...[truncated 616 chars]
- Remediation
View remediation
Remediation Suggestions
Remove the custom TLS context and allow
urllibto use certificate and hostname verification through the operating system's trusted CA store:python try: with urllib.request.urlopen(req, timeout=60) as response: result = json.loads(response.read().decode("utf-8"))Alternatively, create a secure context without weakening its defaults:
python ctx = ssl.create_default_context() try: with urllib.request.urlopen(req, timeout=60, context=ctx) as response: result = json.loads(response.read().decode("utf-8"))If a private CA is required, load only the necessary trusted CA bundle with
cafileorload_verify_locations(). Keepcheck_hostname = Trueandverify_mode = ssl.CERT_REQUIRED.Additional hardening should include:
- Fail closed on certificate or hostname validation errors.
- Never add an option that silently disables TLS verification in production.
- Rotate the Baidu API key if the vulnerable implementation has been used over untrusted networks.
- Restrict the API key's permissions and quota to the minimum required.
- Add a regression test confirming that self-signed, expired, and hostname-mismatched certificates are rejected.
