T09 · Insecure Skill Coding Practices
- Location
search.sh:23- Finding
Arbitrary Python Code Execution Through Unvalidated MAX_RESULTS
- Content
View full analysis
- Remediation
View remediation
&2 exit 2 fi if (( MAX_RESULTS < 1 || MAX_RESULTS > 100 )); then echo "MAX_RESULTS must be between 1 and 100" >&2 exit 2 fi ``` 2. Never interpolate the value into Python source. Pass it as a positional argument: ```bash python3 - "$MAX_RESULTS" <<'PY' import json import sys max_results = int(sys.argv[1]) data = json.load(sys.stdin) results = data.get("results", [])[:max_results] PY ``` 3. Move the Python logic into a static `.py` file or a single-quoted heredoc. 4. Add regression tests using quotes, semicolons, newlines, Python expressions, negative values, and oversized integers. ]]>
