T09 · Insecure Skill Coding Practices
- Location
scripts/should-dream.sh:87- Finding
Arbitrary Python Code Execution Through Unsanitized dreamChance Configuration
- Content
View full analysis
/dev/null || echo "1") ``` ### Technical Analysis The script reads `dreamChance` from the workspace-controlled `data/dream-state.json` file using `jq -r`. The resulting value is then interpolated directly into source code supplied to `python3 -c`. Shell quoting does not make this safe because the untrusted value is being inserted into Python program text rather than passed as data. An attacker who can alter the state file can set `dreamChance` to a string containing valid Python syntax that changes the conditional expression and invokes functions such as `__import__`. Python then interprets the injected content as executable code. The script does not verify that `dreamChance` is a JSON number, reject non-finite values, enforce the documented range of zero through one, or pass the value through a non-code channel. The fallback `|| echo "1"` also causes malformed or failed probability checks to be treated as successful dream decisions. Although this behavior do ...[truncated 1791 chars]- Remediation
View remediation
&2 exit 1 fi ``` 2. Validate the JSON type with `jq` before using the field: ```bash if ! jq -e '.dreamChance == null or (.dreamChance | type == "number")' \ "$STATE_FILE" >/dev/null; then echo "Error: dreamChance must be a JSON number" >&2 exit 1 fi ``` 3. Enforce the documented range `0.0 <= dreamChance <= 1.0` and reject malformed, infinite, or non-numeric input. 4. Fail closed when probability processing fails. Remove the `|| echo "1"` fallback, which currently treats Python errors as approval to continue. 5. Harden the state file against unauthorized modification by using restrictive directory and file permissions appropriate to the execution environment. 6. Apply equivalent strict validation to `dreamsTonight` and `maxDreamsPerNight` before using them in shell arithmetic or numeric comparisons. ]]>
