T09 · Insecure Skill Coding Practices
- Location
scripts/generate_sop.sh:4- Finding
Path Traversal Allows File Creation or Overwrite Outside the SOP Output Directory
- Content
View full analysis
Vulnerability Details
File Location:
scripts/generate_sop.sh, lines 4-9
Vulnerability Type: Path traversal and unsafe file overwrite
Risk Level: MediumVulnerable Code
bash TASK_NAME=$1 shift mkdir -p SOPs FILE="SOPs/${TASK_NAME// /_}.md" echo "# SOP: $TASK_NAME" > "$FILE"Technical Analysis
The script uses the first command-line argument to construct an output path. Its only sanitization replaces spaces with underscores; directory separators,
..path components, and other filesystem-significant input remain unchanged.For example, a task name of
../READMEproduces the path:text SOPs/../README.mdThis resolves to
README.mdoutside the intendedSOPs/directory. The>redirection creates the destination or truncates it if it already exists. The script also does not reject symbolic-link destinations, so filesystem links may redirect the write to another location.Quoting
"$FILE"prevents shell word splitting and command substitution during path use, but it does not prevent path traversal because traversal is handled by filesystem path resolution.Attack Path
- An attacker or untrusted caller controls the task-name argument supplied to
generate_sop.sh. - The attacker supplies a traversal-bearing name, such as
../README. - The script constructs
SOPs/../README.md. - Filesystem path resolution places the destination outside
SOPs/. - The redirection operator creates or truncates the destination file.
- The script writes attacker-controlled task and workflow-step content into that file.
Exploitation is limited to locations writable by the account executing the script and normally to filenames ending in
.md. Existing symbolic links may expand the effective write target.Impact Assessment
Successful exploitation allows creation or overwrite of writable Markdown files outside the documented output directory. This can corrupt pro ...[truncated 410 chars]
- An attacker or untrusted caller controls the task-name argument supplied to
- Remediation
View remediation
Remediation Suggestions
- Reject task names containing
/,\,.., control characters, or an empty value. - Convert task names to a strict filename slug using an allowlist such as
[A-Za-z0-9_-]. - Resolve the output directory and destination parent to canonical paths, then verify that the destination remains beneath the canonical
SOPs/directory. - Refuse symbolic-link destinations and consider checking each relevant path component.
- Avoid silently truncating existing files. Use an exclusive creation mechanism or require explicit authorization before overwriting.
- Return a nonzero status when validation or safe file creation fails.
Example validation approach:
bash set -euo pipefail TASK_NAME=${1-} [[ -n "$TASK_NAME" ]] || { printf 'Error: task name is required\n' >&2 exit 1 } [[ "$TASK_NAME" != *"/"* && "$TASK_NAME" != *"\\"* && "$TASK_NAME" != *".."* ]] || { printf 'Error: invalid task name\n' >&2 exit 1 } SAFE_NAME=$(printf '%s' "$TASK_NAME" | sed 's/[^A-Za-z0-9_-]/_/g') mkdir -p -- SOPs FILE="SOPs/${SAFE_NAME}.md" [[ ! -e "$FILE" && ! -L "$FILE" ]] || { printf 'Error: destination already exists\n' >&2 exit 1 }- Reject task names containing
