Back to skill

Security audit

Okx Data Collector

Security checks for vulnerabilities and agentic risk

Overview

This OKX market-data skill is mostly purpose-aligned, but its helper script can write or overwrite files outside the intended output directory if run with crafted arguments.

Review the helper script before running it. Use a dedicated output directory, avoid untrusted or generated values for --symbol and --bar, and run it as a low-privilege user until path validation is added.

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 (1)

T09 · Insecure Skill Coding Practices

Warning
Location
fetch_history.py:133
Finding

User-Controlled Path Traversal and File Overwrite

Content
View full analysis

Vulnerability Details

File Location: fetch_history.py, lines 133-145
Vulnerability Type: Path traversal and unrestricted file placement
Risk Level: Medium

Vulnerable Code

python
output_path = Path(output_dir)
output_path.mkdir(parents=True, exist_ok=True)

# 保存为 JSON
output_file = output_path / f"{inst_id}_{bar}_{days}d.json"
with open(output_file, 'w') as f:
    json.dump(all_candles, f, indent=2)
print(f"已保存:{output_file}")

# 保存为 CSV
csv_file = output_path / f"{inst_id}_{bar}_{days}d.csv"
with open(csv_file, 'w') as f:
    f.write("timestamp,open,high,low,close,volume\n")

The filename components originate from command-line arguments without validation:

python
parser.add_argument('--symbol', '-s', required=True, help='品种 ID (如 BTC-USDT-SWAP)')
parser.add_argument('--bar', '-b', required=True, help='周期 (1m, 5m, 1H, 4H, 1D 等)')
parser.add_argument('--days', '-d', type=int, default=365, help='采集天数')
parser.add_argument('--output', '-o', default='./output', help='输出目录')

Technical Analysis

The inst_id and bar values are incorporated directly into output filenames. Neither value is restricted to an expected character set, and bar is not checked against the existing BAR_SECONDS allowlist.

An attacker who controls the invocation can supply path separators, .. components, or an absolute path. When an absolute child path is combined with a pathlib.Path, it can replace the intended base directory. Traversal components can similarly cause the resolved destination to leave the configured output directory.

Both files are opened in w mode. Consequently, a destination that already exists is truncated and replaced. The attacker cannot choose a completely unrestricted final filename because the program appends components such as _{bar}_{days}d.json or .csv, but the attacker can still target compatible filenames and create files in unintended directories where ...[truncated 1661 chars]

Remediation
View remediation

Remediation Suggestions

  1. Validate --symbol with a strict allowlist appropriate for OKX instrument identifiers, such as uppercase letters, digits, and hyphens:

    python
    import re
    
    if not re.fullmatch(r'[A-Z0-9-]+', args.symbol):
        parser.error('--symbol contains invalid characters')
    
  2. Require --bar to match a supported interval:

    python
    parser.add_argument(
        '--bar',
        '-b',
        required=True,
        choices=sorted(BAR_SECONDS),
        help='Supported candle interval'
    )
    
  3. Reject absolute paths, path separators, null characters, and . or .. path components in every filename-derived argument.

  4. Resolve and verify each destination before opening it:

    python
    output_root = Path(output_dir).expanduser().resolve()
    output_root.mkdir(parents=True, exist_ok=True)
    
    output_file = (
        output_root / f"{inst_id}_{bar}_{days}d.json"
    ).resolve()
    
    if output_root not in output_file.parents:
        raise ValueError('Output file escapes the configured directory')
    
  5. Apply the same containment check independently to both JSON and CSV paths.

  6. Where overwriting is not required, use exclusive creation mode (x) or require explicit overwrite authorization. Run the collector under a least-privileged account with access limited to its designated data directory.

Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
Findings (3)

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

This markdown file contains end-user-facing natural language exclusively in Chinese, and nowhere indicates that the skill is region-specific or that users may choose another language. Under the policy, forcing a specific language without user opt-in is a natural-language locale violation.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
95% confidence
Finding

This markdown file uses Chinese for the skill's core instructions and operational guidance, but it does not indicate that the language is optional or that the skill is intended only for a Chinese-speaking audience. Under the policy, forcing a specific language without user opt-in can be a natural-language policy violation.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
89% confidence
Finding

This code file contains natural-language instructions and descriptions only in Chinese, including the module docstring and command usage text. Under the stated policy, forcing a specific language without offering a choice or documenting a justified locale restriction is a natural-language policy violation.

Content

No source excerpt is available for this finding.