T09 · Insecure Skill Coding Practices
- Location
investment_system/etf_monitor.py:27- Finding
Hard-Coded Tushare API Token in ETF Monitor
- Content
View full analysis
Vulnerability Details
File Location:
investment_system/etf_monitor.py:27-29
Vulnerability Type: Hard-coded API credential
Risk Level: Mediumpython token = 'b8ef516ff4abecadc1cdb55956458c3fed0378f8f85c30460f0d4500' ts.set_token(token) pro = ts.pro_api()Technical Analysis
A reusable Tushare API token is embedded directly in the source code. Anyone with access to the source package can recover the token without authentication and configure a separate Tushare client to act under the associated account.
The token is passed to
ts.set_token()and subsequently used by the Tushare Pro client. Although the reviewed code uses it only to retrieve northbound-capital data, the credential is not technically restricted by this local implementation. Its effective privileges are determined by the associated Tushare account and provider-side controls.Attack Path
- An attacker downloads, installs, or otherwise obtains read access to the project.
- The attacker reads
investment_system/etf_monitor.py. - The attacker extracts the plaintext token from line 27.
- The attacker initializes an independent Tushare client with the recovered token.
- Requests are made against the provider under the token owner's account until the token is revoked or provider-side limits are reached.
No local privilege escalation or host compromise follows directly from this flaw.
Impact Assessment
An attacker may consume the account's API quota, trigger rate limits, access data available to the associated Tushare subscription, and cause account suspension or service disruption. The precise data-access scope depends on the provider privileges assigned to the token.
The issue does not provide operating-system privileges and does not expose unrelated user credentials based on the reviewed evidence.
- Remediation
View remediation
Remediation Suggestions
- Revoke and rotate the exposed token immediately because removing it from the current source does not invalidate copies in package archives or version history.
- Read the replacement token from a protected environment variable or secret manager:
python import os token = os.environ.get("TUSHARE_TOKEN") if not token: raise RuntimeError("TUSHARE_TOKEN is not configured") ts.set_token(token) - Never commit
.envfiles containing real credentials. Provide an.env.examplecontaining only placeholder values. - Restrict the replacement token's provider-side permissions and quota to the minimum required by the feature.
- Add automated secret scanning to pre-commit checks and CI.
- Review repository history and distributed release artifacts for additional copies of the exposed token.
