Back to skill

Security audit

Strategy Backtester

Security checks for vulnerabilities and agentic risk

Overview

This is a local stock-strategy backtester with no network or persistence, but it needs review because it writes CSV reports from untrusted ticker input without spreadsheet-safety handling and advertises more capability than the scripts provide.

Install only if you are comfortable with a local backtesting helper that executes bundled Python scripts and creates report files. Use trusted signal CSVs, avoid opening generated CSVs with spreadsheet formula execution enabled, and treat its results as historical simulation only; benchmark and bias review may require manual work beyond the included script.

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
scripts/backtest_strategy.py:215
Finding

Spreadsheet Formula Injection in Generated CSV Report

Content
View full analysis
dict[str, list[tuple[str, float]]]: signals: dict[str, list[tuple[str, float]]] = {} with path.open(newline="", encoding="utf-8") as handle: reader = csv.DictReader(handle) require_columns(reader.fieldnames, {"date", "ticker", "score"}, path) for row in reader: date = required_value(row, "date", path) ticker = required_value(row, "ticker", path) score = float(required_value(row, "score", path)) signals.setdefault(date, []).append((ticker, score)) return signals ``` ```python periods.append( { "signal_date": signal_date, "entry_date": entry_date, "exit_date": exit_date, "selected_tickers": selected, "gross_return": gross_return, "turnover": period_turnover, "cost": cost, "net_return": net_return, } ) ``` ```python for period in periods: row = dict(period) row["selected_tickers"] = ";".join(period["selected_tickers"]) writer.writerow(row) ``` ### Technical Analysis The `ticker` field is read from an externally supplied signal CSV and retained without validation or output encoding. If a malicious ticker is selected by the ranking process, its value is joined into the `selected_tickers` field and written to `backtest_periods.csv`. Values beginning with spreadsheet formula-control characters such as `=`, `+`, `-`, or `@` can be interpreted as formulas when the generated CSV is opened in spreadsheet software. CSV quoting performed by `csv.DictWriter` does not reliably neutralize formula interpretation because quoting is part of the CSV representation rather than spreadsheet-safe encoding. An attacker who can influence the signal CSV can therefore ...[truncated 1652 chars]
Remediation
View remediation
str: if not TICKER_PATTERN.fullmatch(value): raise ValueError(f"{path} contains an invalid ticker value") return value ``` 2. Apply validation immediately after reading the field: ```python ticker = validate_ticker(required_value(row, "ticker", path), path) ``` 3. As defense in depth, neutralize all attacker-controlled text immediately before CSV export. After accounting for leading whitespace, prefix cells beginning with `=`, `+`, `-`, or `@` with a single quote: ```python def spreadsheet_safe(value: str) -> str: if value.lstrip().startswith(("=", "+", "-", "@")): return "'" + value return value ``` 4. Apply output neutralization separately to every ticker before joining them: ```python row["selected_tickers"] = ";".join( spreadsheet_safe(ticker) for ticker in period["selected_tickers"] ) ``` 5. Add regression tests covering every dangerous prefix, leading whitespace, tabs, legitimate ticker formats, and multiple selected tickers. 6. Document that generated CSV files contain external input and should not be opened with spreadsheet formula execution or external-content updates enabled. ]]>
Vulnerability Patterns
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • 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
Findings (3)

Tp4

High
Category
MCP Tool Poisoning
Confidence
92% confidence
Finding

The code does match part of the description: it performs a reproducible historical backtest from CSV inputs and computes turnover, drawdown, and several return/risk metrics. However, important declared capabilities are missing. There is no benchmark input, benchmark return calculation, or comparison logic. There are also no bias checks or warnings (such as lookahead, survivorship, or data leakage warnings). In addition, the implementation is specifically limited to selecting the top N scored tickers and holding them equal weight for one period, which is narrower than the broader description of validating stock ranking, factor, and portfolio-selection strategies generally. No suspicious undeclared external access or unrelated triggers are present, but the description overstates what the code actually does.

Content

No source excerpt is available for this finding.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
78% confidence
Finding

The skill invokes a local script and the static analyzer detected file-write capability, but the manifest does not declare any tool scope or permissions. Undeclared write-capable behavior weakens least-privilege controls and can allow unexpected modification of local files, outputs, or intermediate artifacts without clear operator approval. In this context the risk is moderated by the stated local/offline backtesting purpose, but it is still a real security and governance issue because users cannot accurately assess what the skill may change.

Content

No source excerpt is available for this finding.

Vague Triggers

Medium
Category
Not specified by scanner
Confidence
90% confidence
Finding

The skill enables allow_implicit_invocation without any stated trigger constraints, which means an orchestrator may activate it based on broad semantic matching rather than explicit user intent. For a finance-oriented skill, that can cause unintended backtesting, strategy evaluation, or investment-analysis outputs in contexts where the user did not request this tool, increasing the risk of overreach, confusion, and misuse of financial guidance.

Content

No source excerpt is available for this finding.