T09 · Insecure Skill Coding Practices
- Location
scripts/openclaw-switch.sh:42- Finding
Arbitrary Python Code Execution Through Model Identifier Interpolation
- Content
View full analysis
/dev/null; } get_primary() { py " import json, pathlib d = json.loads(pathlib.Path('$CFG').read_text()) print(d.get('agents',{}).get('defaults',{}).get('model',{}).get('primary','(not set)')) " } ``` ```bash list_models() { py " import json, pathlib d = json.loads(pathlib.Path('$CFG').read_text()) providers = d.get('models',{}).get('providers',{}) i = 1 for pname, pcfg in providers.items(): for m in pcfg.get('models',[]): mid = f\"{pname}/{m['id']}\" name = m.get('name', m['id']) print(f\"{i}|{mid}|{name}\") i += 1 " } set_primary() { py " import json, pathlib p = pathlib.Path('$CFG') d = json.loads(p.read_text()) d['agents']['defaults']['model']['primary'] = '$1' p.write_text(json.dumps(d, indent=2, ensure_ascii=False) + '\n') print('OK') " } ``` ```bash cmd_switch() { local target_n="$1" local target_id target_id=$(list_models | awk -F'|' -v n="$target_n" '$1==n {print $2}') [[ -z "$target_id" ]] && { echo "❌ Invalid number. Run: openclaw-switch list"; exit 1; } local cur; cur=$(get_primary) [[ "$target_id" == "$cur" ]] && { echo "⚠️ Already using ${target_id}"; exit 0; } echo -e "${C}🔄 Switching to: ${BD}${target_id}${N}" local res; res=$(set_primary "$target_id") ``` ### Technical Analysis The script builds Python programs as shell strings and executes them with `python3 -c`. The configuration path and selected model identifier are inserted directly into Python single-quoted string literals: ```python d['agents']['defaults']['model']['primary'] = '$1' ``` Shell quoting does not make the resulting Python source safe. If a model identifier contains a single quote followed by Python statements, it can terminate the intended Python literal and introduce ...[truncated 2567 chars]- Remediation
View remediation
