T09 · Insecure Skill Coding Practices
Warning
- Location
- a_stock_watcher.py:115
- Finding
- Financial Market Data Retrieved over Unauthenticated Plaintext HTTP<![CDATA[ ## Vulnerability Details **File Location**: `a_stock_watcher.py:115-142`, `a_stock_watcher.py:202-235`, `a_stock_watcher.py:293-311`, `historical_data.py:38-45`, `historical_data.py:114-120`, and `health_check.py:18-35` **Vulnerability Type**: Cleartext transmission and missing server authentication **Risk Level**: Medium ### Vulnerable Code #### `a_stock_watcher.py:115-142` ```python """ 接口文档:http://push2.eastmoney.com/api/qt/stock/get ... """ ... fields = "f43,f44,f45,f49,f50,f55,f57,f58,f169,f170" url = f"http://push2.eastmoney.com/api/qt/stock/get?secid={secid}&fields={fields}" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", "Referer": "https://quote.eastmoney.com/" } response = requests.get(url, headers=headers, timeout=5) data = response.json() ``` #### `a_stock_watcher.py:202-235` ```python """ 接口文档:http://qt.gtimg.cn/q=[市场代码] ... """ ... url = f"http://qt.gtimg.cn/q={tencent_code}" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", "Referer": "https://stockapp.finance.qq.com/" } response = requests.get(url, headers=headers, timeout=5) ``` #### `a_stock_watcher.py:293-311` ```python """ 接口文档:http://hq.sinajs.cn/list=[市场代码] """ ... url = f"http://hq.sinajs.cn/list={sina_code}" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" } response = requests.get(url, headers=headers, timeout=10) ``` #### `historical_data.py:38-45` ```python url = f"http://web.ifzq.gtimg.cn/appstock/app/fqkline/get?param={tencent_code},day,,,60,qfq" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", "Referer": "https://stockapp.finance.qq.com/" } response = requests.get(url, headers=headers, timeout=10) ``` #### `historical_data.py:114-120` ```python url = f"http://money.finance.sina.com.cn/quotes_service/api/json_v2.php/CN_MarketData.getKLineData?symbol={sina_code}&scale=24 ...[truncated 3292 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Replace every market-data endpoint with an HTTPS endpoint whose certificate can be validated. 2. Remove a data source if it cannot provide HTTPS rather than silently falling back to plaintext HTTP. 3. Enforce HTTPS after redirects and reject any redirect that downgrades the connection to HTTP. 4. Call `response.raise_for_status()` before parsing a response. 5. Validate response schemas, field types, required fields, and plausible numeric ranges. 6. Cross-check security-sensitive alerts against at least two independent HTTPS sources before presenting them as confirmed. 7. Reject impossible values such as negative prices, malformed dates, or unreasonable percentage changes. 8. Distinguish stale, incomplete, and unverified data in reports rather than treating all successful parses as authoritative. 9. Add tests that verify all configured URLs use HTTPS and that downgrade redirects are rejected. 10. Invalidate existing cache entries after transport-security changes so previously unverified data is not reused. ]]>
