T09 · Insecure Skill Coding Practices
- Location
scripts/backtest_engine.py:86- Finding
Unrestricted Execution of User-Supplied Python Strategy Files
- Content
View full analysis
Vulnerability Details
File Location:
scripts/backtest_engine.py, lines 86–91
Vulnerability Type: Arbitrary code execution through an untrusted plugin
Risk Level: HighVulnerable Code:
python def load_custom_strategy(strategy_file: str, strategy_fn: str) -> Callable: """Load a user-defined strategy function from an external file.""" spec = importlib.util.spec_from_file_location("user_strategy", strategy_file) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) if not hasattr(mod, strategy_fn):Technical Analysis
The
--strategy-fileargument is treated as a Python module and executed usingexec_module(). Importing a Python module executes all of its top-level statements before the engine checks whether the requested strategy function exists.The supplied file is not subject to an allowlist, integrity check, signature verification, trust confirmation, filesystem restriction, or execution sandbox. Consequently, this is not merely data parsing: it grants the strategy file the ability to execute arbitrary Python code with the same operating-system permissions and environment as the backtest process.
This behavior may be acceptable for explicitly trusted plugins, but the CLI and documentation do not establish a security boundary or clearly warn that a strategy file is fully executable code.
Attack Path
- An attacker creates a Python strategy file containing malicious top-level statements.
- The attacker persuades a user or agent to download or otherwise use that file in a backtest.
- The user invokes the engine with
--strategy-file malicious_strategy.py. load_custom_strategy()passes the attacker-controlled path tospec_from_file_location().spec.loader.exec_module(mod)immediately executes the file's top-level code.- The malicious code can perform actions under the identity and permissions of the backtest process, eve ...[truncated 752 chars]
- Remediation
View remediation
Remediation Suggestions
- Prefer a declarative strategy format with a strictly validated schema rather than executable Python plugins.
- If Python plugins remain supported, explicitly describe them as trusted executable code and require affirmative confirmation before loading files from untrusted or newly downloaded locations.
- Execute plugins in a separate, least-privileged process or container rather than inside the main engine.
- Disable network access and restrict filesystem visibility for the plugin process where feasible.
- Apply operating-system resource limits for CPU time, memory, process creation, and output size.
- Restrict plugin paths to an administrator- or user-approved directory and reject symbolic-link escapes.
- Maintain an allowlist of approved plugin hashes or require signed plugins in managed deployments.
- Pass only the minimum required price data into the isolated process and validate the returned signal structure, dimensions, values, and size.
- Update
SKILL.mdand the CLI help to state clearly that--strategy-fileexecutes arbitrary Python and must only be used with trusted files.
