T09 · Insecure Skill Coding Practices
- Location
- scripts/search_wechat.py:68
- Finding
- HTTPS Certificate Validation Is Globally Disabled for WeChat Search Requests<![CDATA[ ## Vulnerability Details **File Location**: `scripts/search_wechat.py:68-70` **Vulnerability Type**: Improper certificate validation **Risk Level**: High ### Vulnerable Code ```python _ssl_ctx = ssl.create_default_context() _ssl_ctx.check_hostname = False _ssl_ctx.verify_mode = ssl.CERT_NONE ``` This insecure SSL context is subsequently used for HTTPS requests, including: ```python with urllib.request.urlopen(req, timeout=timeout, context=_ssl_ctx) as resp: ``` ```python with urllib.request.urlopen(req, timeout=10, context=_ssl_ctx) as resp: ``` ```python opener = urllib.request.build_opener( urllib.request.HTTPSHandler(context=_ssl_ctx), _NoRedirectHandler(), ) ``` ### Technical Analysis The code explicitly disables both certificate-chain validation and hostname verification. Consequently, the client accepts self-signed, expired, untrusted, or hostname-mismatched certificates. These HTTPS requests carry user-provided property research keywords, receive Sogou cookies, process search results, and resolve redirect targets. Although the network access is necessary for the declared search functionality, disabling TLS validation is not necessary and exceeds the minimum safe networking behavior. An attacker capable of intercepting the network connection can impersonate Sogou or another requested HTTPS endpoint. The attacker can observe potentially sensitive search terms and replace returned search results, article URLs, cookies, or article content. Because retrieved information is saved as research and may be used to formulate property recommendations, modified responses can also compromise the integrity of subsequent advice. ### Attack Path 1. A user invokes `search_wechat.py` to research a property, school district, family requirement, or related topic. 2. The script opens an HTTPS connection using `_ssl_ctx`. 3. An attacker with a network interception position, malicious proxy, compromised access point, or manipulated DNS response pr ...[truncated 995 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Remove the certificate-validation overrides and retain Python's secure defaults: ```python _ssl_ctx = ssl.create_default_context() ``` - Do not set `check_hostname` to `False` or `verify_mode` to `ssl.CERT_NONE`. - If a private certificate authority is genuinely required, load only the required trusted CA bundle: ```python _ssl_ctx = ssl.create_default_context(cafile="/path/to/trusted-ca.pem") ``` - Enforce an allowlist of expected HTTPS hosts, such as `weixin.sogou.com`, `v.sogou.com`, and `mp.weixin.qq.com`. - Validate redirect destinations before following or storing them. - Avoid forwarding cookies to any host other than the host that originally issued them. - Add automated tests confirming that self-signed and hostname-mismatched certificates are rejected. ]]>
