T09 · Insecure Skill Coding Practices
- Location
modules/snapshot-management.md:39- Finding
Unsanitized Snapshot Name Allows Path Traversal and Arbitrary Local File Overwrite
- Content
View full analysis
Vulnerability Details
File Location:
modules/snapshot-management.md, lines 39–42, 47, and 53
Vulnerability Type: Path traversal through an unsanitized filename component
Risk Level: MediumVulnerable Code
bash SNAP_DIR="$HOME/.claude/voice-profiles/$PROFILE/learning/snapshots" PIECE_NAME="$1" TIMESTAMP=$(date +%Y%m%d-%H%M%S) cp "$OUTPUT_FILE" "$SNAP_DIR/${PIECE_NAME}-${TIMESTAMP}-pre-review.md"The same unsafe destination-path construction is used for the other snapshot stages:
bash cp "$REVIEWED_FILE" "$SNAP_DIR/${PIECE_NAME}-${TIMESTAMP}-post-review.md"bash cp "$EDITED_FILE" "$SNAP_DIR/${PIECE_NAME}-${TIMESTAMP}-post-edit.md"Technical Analysis
PIECE_NAMEis populated from the first positional argument and inserted directly into the snapshot destination path without validation or normalization.Shell quoting prevents shell metacharacters in
PIECE_NAMEfrom being interpreted as commands, so this is not command injection. However, quoting does not neutralize path separators or..traversal components. An attacker who can control the piece name can therefore cause the resolved destination to escape the intended snapshot directory.The timestamp and fixed suffix constrain the resulting filename, but they do not prevent traversal into another directory. If the resulting target path exists or can be created in a writable directory,
cpcan overwrite it under the privileges of the process running the skill. The issue affects pre-review, post-review, and post-edit snapshot capture.Attack Path
-
The attacker supplies a piece name containing traversal components, such as
../../../../tmp/attacker-controlled. -
The skill assigns that value to
PIECE_NAME. -
Snapshot capture constructs a destination resembling:
text $SNAP_DIR/../../../../tmp/attacker-controlled-20260410-143022-pre-review.md -
The operating system resolves the
..components, placing the destination outside `$SN ...[truncated 1074 chars]
-
- Remediation
View remediation
Remediation Suggestions
-
Validate
PIECE_NAMEusing a strict allowlist before constructing any path. For example, permit only letters, digits, periods, underscores, and hyphens:bash case "$PIECE_NAME" in ""|*[!A-Za-z0-9._-]*) printf '%s\n' "Invalid piece name" >&2 exit 1 ;; esac -
Explicitly reject absolute paths, path separators,
.and..as complete names, and all traversal components. -
Canonicalize the snapshot directory and destination, then verify that the destination remains beneath the canonical snapshot directory before writing.
-
Ensure the snapshot directory exists with restrictive permissions:
bash install -d -m 700 -- "$SNAP_DIR" -
Use
--before path arguments so values beginning with a hyphen cannot be treated as options:bash cp -- "$OUTPUT_FILE" "$DESTINATION" -
Consider no-clobber or atomic creation behavior to prevent accidental overwrites, and reject symbolic-link destinations where appropriate.
-
Apply the same validation and containment checks consistently to pre-review, post-review, and post-edit capture operations.
-
