T09 · Insecure Skill Coding Practices
- Location
scripts/monthly-english-summary.sh:39- Finding
Python Code Injection Through a Configurable Data Path
- Content
View full analysis
Vulnerability Details
File Location:
scripts/monthly-english-summary.sh:9-12, 39-44
Vulnerability Type: Configuration-driven Python code injection
Risk Level: HighVulnerable Code
bash DATA_DIR=$(python3 -c "import json; d=json.load(open('$CONFIG_FILE')); print(d.get('data',{}).get('baseDir','$DEFAULT_DATA_DIR'))") API_URL=$(python3 -c "import json; d=json.load(open('$CONFIG_FILE')); print(d.get('api',{}).get('url',''))") API_KEY=$(python3 -c "import json; d=json.load(open('$CONFIG_FILE')); print(d.get('api',{}).get('apiKey',''))") MODEL=$(python3 -c "import json; d=json.load(open('$CONFIG_FILE')); print(d.get('api',{}).get('model','glm-5'))")bash DATA_FILE=$DATA_DIR/$(date +%Y-%m).json if [ -f "$DATA_FILE" ]; then # Read statistics voc=$(python3 -c "import json;d=json.load(open('$DATA_FILE'));print(d.get('vocabulary',{}).get('totalCount',0))") err=$(python3 -c "import json;d=json.load(open('$DATA_FILE'));e=d.get('errors',{});print(e.get('grammar',[]).__len__()+e.get('pronunciation',[]).__len__()+e.get('wordChoice',[]).__len__())") good=$(python3 -c "import json;d=json.load(open('$DATA_FILE'));print(d.get('goodExpressions',{}).get('totalCount',0))")Technical Analysis
The
data.baseDirvalue fromconfig.jsonis used to constructDATA_FILE. That path is then interpolated directly into Python source passed throughpython3 -c.Shell quoting around
"$DATA_FILE"does not make this safe because the value is being inserted into a single-quoted Python string literal. A path containing a single quote followed by valid Python syntax can terminate the literal and inject additional Python statements.This violates the separation between code and data. Configurable paths must be passed as ordinary process arguments rather than embedded in dynamically generated source code.
Attack Path
- An attacker obtains the ability to modify
config.json, such a ...[truncated 1311 chars]
- An attacker obtains the ability to modify
- Remediation
View remediation
Remediation Suggestions
Pass every path to Python as a positional argument rather than interpolating it into Python source:
bash voc=$(python3 -c ' import json import sys with open(sys.argv[1], encoding="utf-8") as stream: data = json.load(stream) print(data.get("vocabulary", {}).get("totalCount", 0)) ' "$DATA_FILE")Apply the same pattern when reading
CONFIG_FILEand for all other Python invocations.Additional hardening should include:
- Resolve the configured data directory using a canonical path.
- If arbitrary storage locations are unnecessary, require the directory to remain beneath an approved application data root.
- Reject paths containing unexpected control characters.
- Ensure
config.jsonand the project directory are writable only by the intended service user. - Replace repeated inline Python programs with a dedicated Python helper that accepts paths through
sys.argv.
