T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/run_dispatch.sh:73
- Finding
- Path Traversal Through Unvalidated Project and Task Names<![CDATA[ ## Vulnerability Details **File Location**: `scripts/run_dispatch.sh:73-92` **Vulnerability Type**: Path traversal and unrestricted filesystem path construction **Risk Level**: High ### Vulnerable Code ```bash PROJECT="$1" TASK_NAME="$2" shift 2 PROMPT="$*" WORKDIR="${REPOS_ROOT}/${PROJECT}" mkdir -p "$WORKDIR" "$LAUNCH_LOG_DIR" NEED_TEAMS=0 if echo "$PROMPT" | grep -Eiq '(Agent Team|Agent Teams|多智能体|并行|testing agent)'; then NEED_TEAMS=1 fi RUN_ID="$(date -u +%Y%m%d-%H%M%S)-${PROJECT}-${TASK_NAME}" RESULT_DIR="$RESULTS_BASE/$PROJECT/$RUN_ID" RUN_LOG="$LAUNCH_LOG_DIR/${RUN_ID}.log" mkdir -p "$RESULT_DIR" ``` ### Technical Analysis The user-controlled `PROJECT` and `TASK_NAME` arguments are inserted directly into filesystem paths without validation, canonicalization, or containment checks. Although later command execution uses Bash arrays and therefore avoids ordinary shell metacharacter injection, array usage does not prevent path traversal. A project value containing components such as `../` can cause `WORKDIR` and `RESULT_DIR` to resolve outside `REPOS_ROOT` and `RESULTS_BASE`. Path separators in `TASK_NAME` can similarly alter the intended result or log path. The script subsequently creates these directories and launches Claude Code with the derived directory as its working directory. The effective access is limited to the privileges of the account running the Skill, but the configured root boundaries are not enforced. ### Attack Path 1. An attacker or untrusted caller supplies a project argument containing traversal components, such as: ```text /dispatch ../../unintended-target audit-task <prompt> ``` 2. The script constructs: ```text ${REPOS_ROOT}/../../unintended-target ``` 3. `mkdir -p` creates the resolved directory if the process account has permission. 4. The dispatcher launches Claude Code with that unintended location as its working directory. 5. Claude Code can inspect or modify files available to the process ...[truncated 733 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Restrict both identifiers to a conservative allowlist: ```bash if [[ ! "$PROJECT" =~ ^[A-Za-z0-9._-]+$ ]] || [[ "$PROJECT" == "." || "$PROJECT" == ".." ]]; then echo "Invalid project name" >&2 exit 2 fi if [[ ! "$TASK_NAME" =~ ^[A-Za-z0-9._-]+$ ]] || [[ "$TASK_NAME" == "." || "$TASK_NAME" == ".." ]]; then echo "Invalid task name" >&2 exit 2 fi ``` 2. Reject path separators, traversal components, control characters, and newline characters. 3. Canonicalize the configured root and candidate path with `realpath`. 4. Verify that the canonical candidate begins with the canonical root followed by `/`. 5. Perform equivalent containment checks independently for work, result, and log paths. 6. Prefer an internally generated opaque run identifier rather than embedding user-controlled names in filenames. 7. Refuse to create a project directory automatically unless directory creation is an explicitly intended and authorized operation. ]]>
