T09 · Insecure Skill Coding Practices
- Location
scripts/get-next-number.sh:30- Finding
Python Code Injection Through Unvalidated Invoice Prefix
- Content
View full analysis
- Remediation
View remediation
&2 exit 1 ;; esac ``` 2. Never interpolate shell variables into Python source. Pass them as arguments: ```bash NEXT_NUMBER=$(python3 -c ' import json import re import sys prefix = sys.argv[1] files = json.load(sys.stdin) pattern = re.compile(rf"{re.escape(prefix)}-(\d+)\.json$") # Process files here. ' "$PREFIX" <<< "$RESPONSE") ``` 3. Validate `YEAR` using a strict expression such as `^[0-9]{4}$`. 4. Validate `INVOICE_REPO` as an expected GitHub `owner/repository` identifier. 5. Add negative tests using prefixes containing quotes, newlines, backslashes, and Python syntax. 6. Continue using a fine-grained GitHub token limited to the single invoice repository. ]]>
