T09 · Insecure Skill Coding Practices
- Location
run.sh:14- Finding
Find Expression Injection Through a Leading-Hyphen Directory Argument
- Content
View full analysis
- Remediation
View remediation
&2 exit 1 fi if [[ ! "$DEPTH" =~ ^[1-9][0-9]*$ ]]; then echo "ERROR: DEPTH must be a positive integer, got: $DEPTH" >&2 exit 1 fi DIR_PATH="$(cd -- "$DIR_PATH" && pwd -P)" find "$DIR_PATH" -maxdepth "$DEPTH" -print | sort | sed 's|[^/]*/| |g' ``` Additional hardening measures include: 1. Reject directory arguments beginning with `-`, unless they have first been normalized into an absolute path. 2. Use `cd -- "$DIR_PATH"` so a leading-hyphen path cannot be interpreted as an option by `cd`. 3. Explicitly include `-print` to make the intended read-only `find` action clear. 4. Test the script against adversarial names such as `-delete`, `-exec`, spaces, newlines, wildcard characters, and names beginning with multiple hyphens. 5. Run the skill with the least-privileged account necessary and avoid invoking it from attacker-writable working directories. 6. Use a null-delimited pipeline if reliable handling of filenames containing newlines is required, although this is separate from the destructive expression-injection issue. ]]>
