T09 · Insecure Skill Coding Practices
- Location
scripts/workspace-init.sh:89- Finding
Unvalidated Project Name Permits Filesystem Path Traversal
- Content
View full analysis
"$file" created "$file" fi } ``` ### Technical Analysis The value supplied through `--project` is accepted without verifying that it is a safe, single directory name. It is concatenated directly into: ```bash $WORKSPACE/projects/$name ``` A name containing parent-directory components such as `../` can therefore escape the intended `projects/` directory. The script subsequently creates subdirectories and writes a `README.md` beneath the traversed destination. When `--force` is supplied, `write_if_new` overwrites an existing target file. The implementation also does not canonicalize destinations or reject symbolic-link targets. Consequently, the script's write authority is not reliably constrained to the declared workspace boundary. Configuration-derived project subdirectory and entity seed names are also used a ...[truncated 1596 chars]- Remediation
View remediation
&2; exit 1; } [[ "$value" != "." && "$value" != ".." ]] || { echo "Invalid project name: $value" >&2; exit 1; } } validate_component "$PROJECT" ``` 2. Reject `/`, `\`, `..`, control characters, leading hyphens, and empty values. 3. Apply equivalent validation to every path component loaded from `.workspace-standard.yml`, including project subdirectories and entity seed names. 4. Canonicalize the workspace and destination before writing, then verify containment: ```bash workspace_real=$(realpath "$WORKSPACE") destination_real=$(realpath -m "$workspace_real/projects/$PROJECT") case "$destination_real" in "$workspace_real/projects/"*) ;; *) echo "Destination escapes workspace" >&2; exit 1 ;; esac ``` 5. Refuse to overwrite symbolic links and validate each parent directory before writing. 6. Require explicit confirmation before `--force` overwrites an existing file, or provide a noninteractive opt-in intended specifically for trusted automation. 7. Add regression tests covering `../`, nested separators, control characters, symlink destinations, and configuration-based traversal attempts. ]]>
