T09 · Insecure Skill Coding Practices
- Location
scripts/qmt_autopilot.py:9- Finding
Environment-Controlled Arbitrary Python Module Execution
- Content
View full analysis
Vulnerability Details
File Location:
scripts/qmt_autopilot.py, lines 9–19 and 27
Vulnerability Type: Untrusted dynamic module loading
Risk Level: HighVulnerable Code
python PLANNER_PATH = os.getenv( "STRATEGY_PLANNER_PATH", "/opt/production_ready_skills/qmt-strategy-planner-skill/scripts/strategy_planner.py" ) def load_planner(): spec = importlib.util.spec_from_file_location( "qmt_strategy_planner_cli", PLANNER_PATH ) if spec is None or spec.loader is None: raise RuntimeError(f"无法加载策略规划器: {PLANNER_PATH}") mod = importlib.util.module_from_spec(spec) sys.modules[spec.name] = mod spec.loader.exec_module(mod) return modpython planner = load_planner()Technical Analysis
The script obtains
PLANNER_PATHdirectly from theSTRATEGY_PLANNER_PATHenvironment variable and executes the specified Python file throughexec_module(). It does not constrain the path to a trusted directory, resolve and validate symlinks, verify file ownership or permissions, or authenticate the module with a pinned cryptographic hash.Python module initialization executes top-level statements. Consequently, loading the configured file is itself a code-execution operation, regardless of which
plan,clarify, orruncommand is requested. The module is also loaded before command validation and dispatch.The default external planner dependency is documented, but the environment-controlled override is not disclosed in the project documentation. Because the referenced planner is outside this artifact, its behavior could not be audited here.
Attack Path
- An attacker gains the ability to set or influence environment variables for the Skill process.
- The attacker creates or identifies a malicious Python file readable by that process.
- The attacker sets
STRATEGY_PLANNER_PATHto the malicious file's path. - A user or automation invokes
qmt_autopilot.pywith any supported o ...[truncated 1176 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove the
STRATEGY_PLANNER_PATHenvironment override and import a packaged, version-pinned planner dependency from a fixed trusted location. - If runtime path configuration is essential:
- Maintain an explicit allowlist of approved canonical paths.
- Resolve the path with
realpath()before validation. - Reject paths outside a dedicated trusted root.
- Reject symlinks or verify their resolved targets.
- Verify that the file and parent directories are owned by an expected privileged account and are not writable by untrusted users.
- Verify the module against a pinned cryptographic hash or signed manifest before loading it.
- Validate the command before loading the planner so invalid commands cannot trigger external module execution.
- Run the Skill under a dedicated least-privileged account with only the brokerage and filesystem permissions required for its task.
- Separate simulated and live execution credentials and require an explicit, independently validated authorization step for live trading.
- Document every executable external dependency and configuration override so the deployed execution boundary can be reviewed.
- Fail closed when any path, ownership, permission, or integrity check fails.
- Remove the
