T08 · Insecure Dependencies
Warning
- Location
- commands/generate-tearsheet.md:54
- Finding
- Untrusted External Module Import Through Hardcoded Search Path## Vulnerability Details **File Location**: `commands/generate-tearsheet.md`, lines 54-58 **Vulnerability Type**: Insecure dependency resolution and arbitrary local code execution **Risk Level**: Medium **Complete Code Snippet**: ```python import sys import pandas as pd sys.path.insert(0, '/Users/DanBot/Desktop/dev/Backtests') from backtesting.tearsheets.strategy_comparison_tearsheet import StrategyComparisonTearsheet ``` The dependency is also explicitly documented in `SKILL.md`, lines 101-110: ```text ## Dependencies - Python 3.10+ - pandas, numpy, matplotlib - StrategyComparisonTearsheet from backtesting.tearsheets ## Installation The skill uses the tearsheet generator at: `/Users/DanBot/Desktop/dev/Backtests/backtesting/tearsheets/strategy_comparison_tearsheet.py` Ensure this path is accessible or update the script paths accordingly. ``` ### Technical Analysis The implementation prepends a user-specific external directory to `sys.path` and then imports executable Python code from that directory. Because the inserted path has the highest module-resolution priority, Python will load `backtesting.tearsheets.strategy_comparison_tearsheet` from that location before normally installed packages. Python executes module-level statements during import. Therefore, the imported module does not need to wait for `StrategyComparisonTearsheet` to be instantiated: arbitrary statements placed at module scope execute immediately. The external component is not bundled with this project, version-pinned, integrity-checked, or otherwise authenticated, so its effective behavior cannot be established through an audit of this repository alone. This is an unsafe local dependency and supply-chain trust boundary. Exploitation requires an attacker to control or modify the referenced directory, or to induce the user to place an untrusted project there. ### Attack Path 1. An attacker obtains write access to `/Users/DanBot/ ...[truncated 1350 chars]
- Remediation
- ## Remediation Suggestions 1. Bundle the required tearsheet generator in the Skill package so that the reviewed code is the code executed at runtime. 2. Alternatively, publish it as a trusted package and pin an exact version and cryptographic hashes in a lock file or requirements file. 3. Remove the `sys.path.insert(0, ...)` modification and use standard package imports from an isolated virtual environment. 4. Do not rely on a user-specific absolute path. Resolve packaged resources relative to the installed Skill only. 5. If loading a configurable local component is unavoidable: - Require an explicit trusted path rather than silently assigning highest import priority. - Resolve and validate the canonical path. - Reject directories writable by untrusted users. - Verify file ownership and permissions. - Verify the component against a pinned cryptographic digest or trusted signature before importing it. - Load it in a restricted subprocess with minimal filesystem, network, environment, and credential access. 6. Document the exact dependency source, supported version, expected digest, and update procedure. 7. Add automated tests that fail if module resolution escapes the packaged or locked dependency environment.
