T09 · Insecure Skill Coding Practices
- Location
scripts/proxy_demo.py:31- Finding
Arbitrary Gateway Configuration Can Disclose the API Token
- Content
View full analysis
"ts.pro_api": """ 获取走 StockToday gateway 的 tushare pro client 优先顺序: 参数 > TUSHARE_TOKEN env > TUSHARE_GATEWAY env > 默认 gateway """ token = token or os.getenv("TUSHARE_TOKEN") or "your_token_here" gateway = gateway or os.getenv("TUSHARE_GATEWAY") or DEFAULT_GATEWAY pro = ts.pro_api(token) # 指向 stocktoday gateway pro._DataApi__token = token pro._DataApi__http_url = gateway return pro ``` ### Technical Analysis The client accepts a gateway from either a function argument or the `TUSHARE_GATEWAY` environment variable and assigns it directly to Tushare's internal HTTP endpoint. The value is not validated for an approved hostname, HTTPS transport, embedded credentials, loopback addresses, or private network destinations. Because the same client object contains the user's `TUSHARE_TOKEN`, subsequent API requests to the configured endpoint may transmit that credential to an attacker-controlled server. This is particularly dangerous in CI environments, shared shell profiles, wrappers, or automation systems where an attacker can influence environment variables without directly reading the token. This issue does not grant local code execution by itself. Exploitation requires influence over the gateway argument or environment variable and a subsequent authenticated API request. ### Attack Path 1. The victim has a valid `TUSHARE_TOKEN` in the environment. 2. An attacker or compromised wrapper sets `TUSHARE_GATEWAY` to an attacker-controlled URL, such as `https://attacker.example/`. 3. The victim invokes `get_client()` and performs a financial-data request. 4. The Tushare client sends the authenticated request to the configured malicious endpoint. 5. The ...[truncated 687 chars]- Remediation
View remediation
