T09 · Insecure Skill Coding Practices
- Location
watch.sh:8- Finding
Path Traversal in Completion Marker Label
- Content
View full analysis
Vulnerability Details
File Location:
watch.sh, lines 8-9 and 26-31
Vulnerability Type: Path traversal caused by insufficient input validation
Risk Level: MediumVulnerable Code
bash LABEL="${1:-}" WAIT_SECONDS="${2:-}" if [[ -z "$LABEL" ]]; then echo "usage: watch.sh <label> [wait_seconds]" >&2 exit 2 fi STATE_DIR="${STATE_DIR:-$(pwd)/state}" MARKER="$STATE_DIR/${LABEL}.done" mkdir -p "$STATE_DIR" sleep "$WAIT_SECONDS" if [[ -f "$MARKER" ]]; then exit 0 fiTechnical Analysis
The caller-controlled
LABELvalue is directly incorporated intoMARKERwithout rejecting path separators or parent-directory components such as... Shell quoting prevents word splitting and command injection, but it does not prevent filesystem path traversal.Consequently, a label such as
../../shared/completedproduces a marker path equivalent to:text <STATE_DIR>/../../shared/completed.doneThe
[[ -f "$MARKER" ]]test follows normal filesystem path resolution and can therefore inspect a file outside the intended state directory. The script treats any matching regular file as authoritative evidence that the monitored subagent completed, without verifying that the resolved marker remains underSTATE_DIR.Attack Path
- An attacker or untrusted caller obtains control over the label passed as the first argument to
watch.sh. - The attacker identifies or creates an accessible regular file outside the watchdog state directory whose name ends in
.done. - The attacker supplies a traversal label pointing to that file, for example:
bash ./watch.sh "../../shared/completed" 1 - The script constructs
$STATE_DIR/../../shared/completed.done. - After the wait expires,
[[ -f "$MARKER" ]]succeeds if that external file exists. - The watchdog exits with status
0, falsely reporting successful completion and suppressi ...[truncated 686 chars]
- An attacker or untrusted caller obtains control over the label passed as the first argument to
- Remediation
View remediation
Remediation Suggestions
Apply strict validation before using the label in a filesystem path:
bash if [[ ! "$LABEL" =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ ]] || [[ "$LABEL" == "." || "$LABEL" == ".." ]]; then echo "invalid label: use only letters, digits, dots, underscores, and hyphens" >&2 exit 2 fiIn addition:
- Reject all path separators and parent-directory components rather than attempting to sanitize them.
- Canonicalize
STATE_DIRand verify that the resolved marker's parent directory is exactly the intended state directory. - Consider using an encoded or hashed representation of arbitrary labels as marker filenames.
- Ensure the state directory has restrictive ownership and permissions so untrusted users cannot create forged completion markers.
- Add tests covering labels containing
../,/, repeated dots, whitespace, and symbolic-link edge cases.
