T09 · Insecure Skill Coding Practices
- Location
scripts/process.sh:203- Finding
Arbitrary Python Code Execution Through Crafted JSON or CSV Filenames
- Content
View full analysis
20: print(f'{k}: {v}') else: extract_text(v, depth+1) elif isinstance(obj, list): for item in obj: extract_text(item, depth+1) extract_text(data) " } process_csv() { local file="$1" log "处理CSV文件..." # 转为可读格式 python3 -c " import csv with open('$file', 'r', encoding='utf-8') as f: reader = csv.DictReader(f) for row in reader: for k, v in row.items(): if v and len(str(v)) > 10: print(f'{k}: {v}') print('---') " } ``` ### Technical Analysis The user-controlled file path is interpolated directly into source code passed to `python3 -c`. Shell quoting around `"$file"` does not protect the Python program because the path is inserted inside a Python single-quoted string. A filename containing a single quote can terminate the `open()` argument and inject arbitrary Python statements. The injected statements execute with the same user account and filesystem permissions as the Skill process. Both the JSON and CSV handlers are affected. ### Attack Path 1. An attacker creates or supplies a JSON or CSV file whose path contains Python syntax, including a single quote. 2. The file extension causes `detect_type()` to select `json` or `csv`. 3. `process_json()` or `process_csv()` inserts the path into the `python3 -c` program. 4. The ...[truncated 891 chars]- Remediation
View remediation
