T09 · Insecure Skill Coding Practices
- Location
scripts/nix-run.sh:99- Finding
Arbitrary Python Code Execution Through Unvalidated --limit Input
- Content
View full analysis
- Remediation
View remediation
= 1 && 10#$2 <= 100 )) || die "--limit must be between 1 and 100" SEARCH_LIMIT="$2" ``` 2. Never interpolate the value into Python source. Pass it as a positional argument: ```bash printf '%s\n' "$json" | nix run "${NIXPKGS_REF}#python3" -- -c ' import json import sys limit = int(sys.argv[1]) data = json.load(sys.stdin) # ... items = list(seen.items())[:limit] ' "$SEARCH_LIMIT" ``` 3. Keep both controls: - Bash validation ensures invalid values are rejected early. - Parsing `sys.argv[1]` with `int()` ensures Python treats the value as data rather than executable source. 4. Add regression tests using nonnumeric input, Python syntax, quotes, semicolons, newlines, negative values, and excessively large integers. Tests should verify rejection and confirm that no injected command runs. ]]>
