T09 · Insecure Skill Coding Practices
- Location
SKILL.md:57- Finding
Unchecked Directory Change Before Recursive Deletion
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 57–58
Vulnerability Type: Unsafe shell command sequence
Risk Level: MediumVulnerable Code
bash cd $PROJECT_DIR rm -rf build/DebugTechnical Analysis
The documented build workflow changes into
$PROJECT_DIRand then recursively deletesbuild/Debug. The variable is not quoted, so shell word splitting and pathname expansion can causecdto receive an unintended path when the project directory contains spaces or wildcard characters.More importantly, the deletion is not conditional on a successful directory change. If
cdfails because the directory is invalid, inaccessible, or parsed incorrectly, shell execution continues andrm -rf build/Debugoperates relative to the process's original working directory.This is an insecure coding pattern in shell instructions. Although the affected path is relative rather than an arbitrary absolute path, it can still remove an unrelated
build/Debugtree when the workflow is run from another project or sensitive working directory.Attack Path
- A user or automation process sets
$PROJECT_DIRto an invalid, inaccessible, or whitespace-containing path. - The user executes the documented commands from a directory that already contains a
build/Debugtree. - The unquoted
cd $PROJECT_DIRfails or resolves incorrectly. - Because the command sequence does not stop after the failure,
rm -rf build/Debugexecutes in the original working directory. - The unrelated
build/Debugdirectory and all files beneath it are recursively deleted.
Exploitation requires control or influence over the project path and a useful deletion target at
build/Debugunder the caller's current directory.Impact Assessment
The command runs with the invoking user's existing privileges and does not provide privilege escalation, persistence, or code execution. Its impact is limited to destructive fi ...[truncated 339 chars]
- A user or automation process sets
- Remediation
View remediation
Remediation Suggestions
Quote the directory variable, prevent option interpretation, and make deletion conditional on a successful directory change:
bash cd -- "$PROJECT_DIR" && rm -rf -- build/DebugFor a complete shell script, also enable fail-fast behavior and validate the destination before deleting files:
bash set -euo pipefail if [ -z "${PROJECT_DIR:-}" ] || [ ! -d "$PROJECT_DIR" ]; then printf 'Invalid project directory: %s\n' "${PROJECT_DIR:-}" >&2 exit 1 fi cd -- "$PROJECT_DIR" test -f CMakeLists.txt || { printf 'Refusing cleanup outside a recognized CMake project\n' >&2 exit 1 } rm -rf -- build/DebugRun the workflow with an unprivileged account and avoid executing destructive build-cleanup commands from shared or sensitive parent directories.
