T09 · Insecure Skill Coding Practices
- Location
SKILL.md:22- Finding
Arbitrary Python Code Execution Through Unsafely Interpolated File Paths
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 22-47
Vulnerability Type: Python code injection through dynamic source construction
Risk Level: HighVulnerable Code
bash ENV_SOURCE="${1:-.env.development}" ENV_TARGET="${2:-.env.staging}" if [ ! -f "$ENV_SOURCE" ] || [ ! -f "$ENV_TARGET" ]; then echo "Looking for environment files..." find . -maxdepth 3 -name ".env*" -not -path '*/node_modules/*' 2>/dev/null | sort fi python3 -c " import sys def parse_env(path): vars = {} try: for line in open(path): line = line.strip() if not line or line.startswith('#'): continue if '=' in line: key, val = line.split('=', 1) vars[key.strip()] = val.strip().strip('\"').strip(\"'\") except FileNotFoundError: print(f'File not found: {path}') return vars source = parse_env('$ENV_SOURCE') target = parse_env('$ENV_TARGET')Technical Analysis
The source and target paths originate from positional arguments and are expanded directly inside the source text supplied to
python3 -c. Shell quoting around the command does not make the expanded values safe Python string literals.An attacker-controlled path containing a single quote, Python statements, and a comment marker can terminate the
parse_envargument, inject additional statements, and comment out the remaining characters on that line. The Python interpreter then executes the injected statements with the privileges of the process invoking the Skill.The preceding
-fcheck does not prevent exploitation. It only prints a list when a path does not exist and does not terminate execution or sanitize the path before it reachespython3 -c.Attack Path
-
An attacker influences either environment-file argument passed to the comparison command.
-
The attacker supplies a value shaped like:
text x');
...[truncated 971 chars]
-
- Remediation
View remediation
Remediation Suggestions
Never interpolate file paths or other untrusted values into executable source code. Pass them as ordinary arguments:
bash python3 - "$ENV_SOURCE" "$ENV_TARGET" <<'PY' import sys env_source = sys.argv[1] env_target = sys.argv[2] source = parse_env(env_source) target = parse_env(env_target) PYIn addition:
- Exit with a nonzero status if either requested file does not exist.
- Validate that each input resolves to an expected regular file.
- If access should be limited to the project, resolve canonical paths and ensure they remain under the permitted project directory.
- Avoid
eval, generated scripts, or shell re-parsing as alternative implementations. - Add regression tests using paths containing quotes, semicolons, newlines, comment markers, and command-like text.
