T09 · Insecure Skill Coding Practices
- Location
modules/sample-intake.md:17- Finding
Path Traversal Through Unsanitized Profile Name Enables Filesystem Writes Outside the Profile Root
- Content
View full analysis
Vulnerability Details
File Location:
modules/sample-intake.md, lines 17-30
Vulnerability Type: Path traversal and unrestricted filesystem write
Risk Level: Mediumbash PROFILE_NAME="$1" SAMPLE_DIR="$2" PROFILE_DIR="$HOME/.claude/voice-profiles/$PROFILE_NAME" mkdir -p "$PROFILE_DIR/samples" mkdir -p "$PROFILE_DIR/registers" mkdir -p "$PROFILE_DIR/learning/snapshots" # Copy and anonymize samples counter=1 for f in "$SAMPLE_DIR"/*.{md,txt} 2>/dev/null; do [ -f "$f" ] || continue padded=$(printf "%02d" $counter) cp "$f" "$PROFILE_DIR/samples/sample-${padded}.md"Technical Analysis
The user-controlled
PROFILE_NAMEvalue is directly concatenated intoPROFILE_DIRwithout an allowlist, canonicalization, or containment check. Shell quoting protects against ordinary shell metacharacter injection, but it does not prevent filesystem traversal sequences such as../.A profile name containing traversal components can cause
PROFILE_DIRto resolve outside$HOME/.claude/voice-profiles. The subsequentmkdir -pandcpoperations then create directories and write files at the escaped location.The destination filename is constrained to
samples/sample-NN.md, so this is not a completely arbitrary filename write. Nevertheless, an attacker can choose the parent destination through traversal and may overwrite an existing file with that predictable name becausecpis used without no-clobber protection.Attack Path
- An attacker or untrusted caller supplies a profile name containing traversal components, such as
../../target. - The skill constructs a path equivalent to:
$HOME/.claude/voice-profiles/../../target. - The operating system resolves the traversal components, moving the destination outside the intended voice-profile root.
mkdir -pcreatessamples,registers, andlearning/snapshotsdirectories at the escaped location.- Files controlled th ...[truncated 841 chars]
- An attacker or untrusted caller supplies a profile name containing traversal components, such as
- Remediation
View remediation
Remediation Suggestions
-
Validate profile names with a strict allowlist before using them in paths. For example, permit only letters, numbers, underscores, and hyphens:
bash case "$PROFILE_NAME" in (*[!A-Za-z0-9_-]*|'') printf '%s\n' "Invalid profile name" >&2 exit 1 ;; esac -
Explicitly reject path separators,
.and..traversal components, control characters, and empty values. -
Resolve the profile root and candidate destination to canonical absolute paths, then verify that the destination remains beneath the canonical profile root before creating directories or copying files.
-
Use safer overwrite behavior, such as
cp -n, or require explicit user confirmation before replacing an existing destination file. -
Validate that
SAMPLE_DIRis an expected readable directory and impose reasonable limits on the number and size of copied files. -
Fail closed if path validation or canonicalization cannot be completed; do not continue with partially validated paths.
-
