Back to skill

Security audit

股票全面分析v3

Security checks for vulnerabilities and agentic risk

Overview

This stock-analysis skill mostly does expected market-data lookups, but it needs review because it embeds an API key and can present simulated technical indicators as investment advice.

Review this skill before installing or using it for decisions. Stock symbols will be sent to external market/news providers, and the generated reports should not be treated as reliable trading advice until the publisher removes the hardcoded Finnhub token, rotates it, requires user-supplied credentials securely, and either replaces simulated indicators with real historical market data or labels them clearly as simulations.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (2)

T09 · Insecure Skill Coding Practices

Warning
Location
analyze_stock.py:95
Finding

Hardcoded Finnhub API Credential Committed Across the Project

Content
View full analysis

Vulnerability Details

File Location: analyze_stock.py:95-101; additional occurrences at company_info.py:3, jd_logistics.py:4, report_v2.py:114, report_v3.py:109-110, stock_analyst.py:39, and test_stock.py:5
Vulnerability Type: Hardcoded API credential and credential exposure through URL query parameters
Risk Level: Medium

Vulnerable Code

python
def get_us_stock(code):
    """获取美股行情"""
    FINNHUB_KEY = 'd6nucg1r01qse5qn5e90d6nucg1r01qse5qn5e9g'
    
    code = code.strip().upper()
    url = f'https://finnhub.io/api/v1/quote?symbol={code}&token={FINNHUB_KEY}'
    
    try:
        r = requests.get(url, timeout=10).json()

The same credential is also used as an insecure fallback in the principal Skill implementation:

python
FINNHUB_KEY = os.environ.get(
    'FINNHUB_API_KEY',
    'd6nucg1r01qse5qn5e90d6nucg1r01qse5qn5e9g'
)

Technical Analysis

A Finnhub API token is embedded directly in seven source files. Any person or automated system with read access to the project, a source archive, a fork, or repository history can recover and reuse the credential without running the Skill.

The token is also inserted into URL query strings. Query parameters may be retained by HTTP client diagnostics, proxy logs, network-monitoring systems, exception reports, or upstream access logs. Using an environment variable in stock_analyst.py does not resolve the issue because the exposed token remains the default value and is used whenever the environment variable is absent.

Attack Path

  1. An attacker downloads, clones, or otherwise obtains read access to the project.
  2. The attacker searches the source for token, FINNHUB_KEY, or the known Finnhub token format.
  3. The committed token is extracted from any of the seven affected files.
  4. The attacker submits requests to Finnhub while authenticating with the exposed token.
  5. The attacker consumes the asso ...[truncated 688 chars]
Remediation
View remediation

Remediation Suggestions

  1. Revoke the exposed Finnhub token immediately and issue a replacement.

  2. Remove every hardcoded occurrence from the current source tree.

  3. Purge the token from repository history where feasible, recognizing that rotation remains mandatory even after history rewriting.

  4. Require FINNHUB_API_KEY to be supplied through an environment variable or an approved secret manager, with no embedded fallback:

    python
    FINNHUB_KEY = os.environ.get("FINNHUB_API_KEY")
    if not FINNHUB_KEY:
        raise RuntimeError("FINNHUB_API_KEY is required")
    
  5. Centralize credential loading in one module rather than duplicating it across scripts.

  6. Avoid including credentials in diagnostic output and sanitize request URLs before logging.

  7. Add secret scanning to local hooks and CI, and block future commits containing API tokens.

  8. Review Finnhub account usage for unauthorized requests made with the exposed token.

T09 · Insecure Skill Coding Practices

Warning
Location
report_v3.py:126
Finding

Randomly Generated Prices Are Presented as Technical Indicators and Used in Financial Recommendations

Content
View full analysis

Vulnerability Details

File Location: report_v3.py:126-139, with results displayed at report_v3.py:212-228 and incorporated into the surrounding recommendation workflow at report_v3.py:279-321
Vulnerability Type: Untrusted synthetic data used in user-facing financial analysis
Risk Level: Medium

Vulnerable Code

python
def get_technical_indicators(price, change_pct):
    """
    根据当前价格生成技术指标
    实际应该从K线数据计算
    """
    # 模拟一些历史价格
    prices = []
    current = price
    for i in range(30, 0, -1):
        variation = random.uniform(-0.02, 0.02)
        current = current / (1 + change_pct/100) * (1 + variation)
        prices.append(current)
    prices.append(price)
    
    indicators = calculate_indicators(prices)

The generated values are then presented as ordinary technical indicators:

python
if price_data:
    indicators = get_technical_indicators(
        price_data['price'],
        price_data['change_pct']
    )
    
    if indicators:
        if indicators.get('rsi'):
            report.append(f"RSI(14): {indicators['rsi']}")
        if indicators.get('ma5'):
            report.append(f"MA5: {indicators['ma5']:.2f}")
        if indicators.get('ma10'):
            report.append(f"MA10: {indicators['ma10']:.2f}")
        if indicators.get('ma20'):
            report.append(f"MA20: {indicators['ma20']:.2f}")
        if indicators.get('macd'):
            report.append(f"MACD: {indicators['macd']:.4f}")

Technical Analysis

RSI, moving averages, and MACD require historical market prices. Instead of retrieving historical candles, get_technical_indicators constructs a synthetic price series using random.uniform(-0.02, 0.02). The resulting indicators therefore do not describe the analyzed security's historical price behavior.

No explicit warning is included in the generated report to tell users that these values are random simula ...[truncated 1564 chars]

Remediation
View remediation

Remediation Suggestions

  1. Remove random price generation from all production report paths.
  2. Retrieve sufficient historical OHLC or closing-price data from a documented and validated market-data API.
  3. Validate candle ordering, trading dates, currency, symbol, adjustment status, and minimum sample count before calculating indicators.
  4. If historical data is unavailable, omit the indicators and explicitly report that they could not be calculated.
  5. Keep simulation functionality, if required for development, behind an explicit test-only option and label every simulated result prominently.
  6. Ensure trading recommendations are not generated from synthetic, stale, or incomplete data.
  7. Add deterministic tests using known historical datasets and expected RSI, MA, and MACD outputs.
  8. Add a financial-risk disclaimer clarifying data-source limitations and that the report is not individualized investment advice.
Vulnerability Patterns
  • Taint TrackingDirect Taint Flow, Variable-Mediated Taint Flow, Credential Exfiltration Chain
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (87)

Tainted flow: 'url' from os.environ.get (line 109, credential/environment) → requests.get (network output)

Critical
Category
Data Flow
Confidence
90% confidence
Finding

Credentials or environment variables flow to a network sink. This is a high-confidence indicator of credential exfiltration.

Content

Scanner excerpt · stock_analyst.py (reported line 60)May include surrounding context.

python
for hk_code in [f'hk{code}', f'hk0{code}', f'hk00{code}']:
        try:
            url = f'https://qt.gtimg.cn/q={hk_code}'
            r = requests.get(url, timeout=8)
            text = r.text.strip()
            
            if 'none_match' in text:

Tainted flow: 'url' from os.environ.get (line 109, credential/environment) → requests.get (network output)

Critical
Category
Data Flow
Confidence
90% confidence
Finding

The code embeds an API token into the request URL and sends user-supplied stock symbols to an external service. Although this is not arbitrary SSRF, it does create unnecessary credential exposure risk because tokens in URLs can be logged by clients, proxies, or monitoring systems, and the code even falls back to a hardcoded token if the environment variable is absent. In a stock-analysis skill, this is more dangerous because external API usage is central to functionality and likely frequent.

Content

Scanner excerpt · stock_analyst.py (reported line 110)May include surrounding context.

python
try:
        url = f'https://finnhub.io/api/v1/quote?symbol={code}&token={FINNHUB_KEY}'
        r = requests.get(url, timeout=10).json()
        
        if r.get('c'):  # current price
            return {

Tainted flow: 'url' from os.environ.get (line 109, credential/environment) → requests.get (network output)

Critical
Category
Data Flow
Confidence
90% confidence
Finding

Credentials or environment variables flow to a network sink. This is a high-confidence indicator of credential exfiltration.

Content

Scanner excerpt · stock_analyst.py (reported line 134)May include surrounding context.

python
"""获取财经新闻"""
    try:
        url = 'https://ai.6551.io/open/free_hot?category=macro'
        r = requests.get(url, timeout=15)
        data = r.json()
        
        if data.get('success'):

Tainted flow: 'headers' from os.environ.get (line 9, credential/environment) → requests.get (network output)

Critical
Category
Data Flow
Confidence
90% confidence
Finding

Credentials or environment variables flow to a network sink. This is a high-confidence indicator of credential exfiltration.

Content

Scanner excerpt · test_longbridge.py (reported line 20)May include surrounding context.

python
for sym in symbols:
    url = f'https://api.longbridgeapp.com/v1/quote/quotes?symbol={sym}'
    try:
        r = requests.get(url, headers=headers, timeout=10)
        print(f"=== {sym} ===")
        print(r.status_code)
        print(r.text[:500])

Tp4

High
Category
MCP Tool Poisoning
Confidence
96% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
96% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
96% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
96% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
97% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
92% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
96% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
97% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
95% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Tp4

High
Category
MCP Tool Poisoning
Confidence
95% confidence
Finding

The reported behavior is limited, HK-specific, and includes 6551 hot-news sources not fully reflected in the description, with no implementation of the promised analytics or reporting. Hidden or poorly disclosed dependencies and narrow market scope increase the risk of misleading users about what evidence the tool actually uses.

Content

No source excerpt is available for this finding.

Static analysis

No suspicious patterns detected.