T09 · Insecure Skill Coding Practices
- Location
scripts/evomap-monitor.sh:43- Finding
Remote API Data Is Interpolated into Executable Python Code
- Content
View full analysis
/dev/null) if [ -z "$top_task" ]; then return fi IFS='|' read -r task_id amount title <<< "$top_task" # 检查是否超过阈值 amount_val=$(echo "$amount" | python3 -c "print(float(open('/dev/stdin').read().strip()) if open('/dev/stdin').read().strip() else 0" 2>/dev/null) amount_val=$(python3 -c "print($amount)") if [ $(echo "$amount_val >= $MIN_AMOUNT" | python3) -eq 0 ]; then return fi ``` ### Technical Analysis The `amount` variable is derived from the `bounty_amount` field in the remote EvoMap API response. It is then directly interpolated into Python source code: ```bash python3 -c "print($amount)" ``` The shell does not treat the variable as a numeric value. Instead, its contents become part of the Python program passed to `python3 -c`. An attacker who can control or alter the API response can therefore supply a Python expression rather than a number. For example, a value structurally equivalent to the following would execute a local command: ```python __import__('os').system('attacker-command') or 50 ``` The subsequent comparison also constructs Python source from the resulting value, creating another unsafe evaluation point. The preceding parser currently references an undefined variable named `d`, which is likely to cause task parsing to fail and may prevent the vulnerable sink from being reached in the present implementation. This reliability defect does not make dynamic source-code construction safe; if the parsing defect is corrected wit ...[truncated 1258 chars]- Remediation
View remediation
/dev/null`. - Treat every field returned by EvoMap as untrusted, including task IDs and titles. A safer pattern is: ```bash amount_val=$(printf '%s' "$amount" | python3 -c ' import sys from decimal import Decimal, InvalidOperation raw = sys.stdin.read().strip() try: value = Decimal(raw) except InvalidOperation: raise SystemExit(1) if not value.is_finite() or value < 0: raise SystemExit(1) print(value) ') || { log "Invalid bounty amount received" return } python3 - "$amount_val" "$MIN_AMOUNT" <<'PY' import sys from decimal import Decimal raise SystemExit(0 if Decimal(sys.argv[1]) >= Decimal(sys.argv[2]) else 1) PY ``` ]]>
