T09 · Insecure Skill Coding Practices
- Location
scripts/chanlun_core.py:402- Finding
Automatic Use of an Undeclared Dependency and External Network Service
- Content
View full analysis
Vulnerability Details
File Location:
scripts/chanlun_core.py:402-414
Vulnerability Type: Undeclared runtime dependency and external service
Risk Level: MediumVulnerable Code
python if not use_tushare or df is None or len(df) == 0: # 备用:使用 Yahoo Finance import yfinance as yf if period == 'daily': df = yf.download(ts_code, period='3mo', progress=False) else: df = yf.download(ts_code, period='1mo', interval=period, progress=False)The corresponding metadata only declares Tushare:
json "dependencies": { "pip": [ "pandas>=1.5.0", "numpy>=1.20.0", "matplotlib>=3.5.0", "tushare>=1.2.0" ] }, "sideEffects": { "readsFiles": true, "writesFiles": true, "networkAccess": true, "externalServices": ["Tushare API"] }Technical Analysis
The application automatically imports
yfinanceand sends requests to Yahoo Finance whenever Tushare is disabled, fails, or returns no records. However,yfinanceis absent from the declared package dependencies, and Yahoo Finance is absent from the declared external services.This discrepancy prevents users and deployment systems from accurately determining the software and network resources used by the skill. It can also cause an availability failure if
yfinanceis not already installed. If an unexpected or compromisedyfinancepackage is present in the environment, its module-level code executes at import time with the privileges of the skill process.The fallback is automatic after a broad Tushare exception rather than being subject to explicit user approval. The requested stock identifier and associated request metadata may consequently be disclosed to a second provider that is not identified in the skill manifest.
Attack Path
- The user invokes the skill to analyze a stock.
- The Tushare request fails, returns no data, or Tushare use is disabled.
- The fallback branch imports the undeclared
yfinancepackage. - Any m ...[truncated 1058 chars]
- Remediation
View remediation
Remediation Suggestions
- Add an exact, reviewed
yfinanceversion to the declared dependencies. - Add Yahoo Finance to
sideEffects.externalServices. - Document what information is sent to each provider.
- Require explicit provider selection or user approval before switching from Tushare to Yahoo Finance.
- Catch narrowly defined network and API exceptions instead of using a broad
except Exceptionto trigger fallback behavior. - Fail closed with a clear error if the selected provider is unavailable unless the user has explicitly enabled fallback.
- Use a lockfile and package hashes so an unexpected package cannot satisfy the undeclared import.
- Run the skill with restricted filesystem access, a minimal environment, and network access limited to approved provider domains.
- Add an exact, reviewed
