T09 · Insecure Skill Coding Practices
Warning
- Location
- setup.sh:37
- Finding
- Unconditional File Overwrite and Symlink-Following Write## Vulnerability Details **File Location**: `setup.sh`, lines 37–69 **Vulnerability Type**: Unconditional overwrite and unsafe symbolic-link handling **Risk Level**: Medium ### Vulnerable Code ```bash cat > "$WS/notes/cost-tracking.md" << 'EOF' # Cost Tracking Log ## Multipliers - Creative: 7.5x - Research: 3x - Technical: 2x - Simple: 1.5x | Date | Task | Model | Est. | Actual | Ratio | Notes | |------|------|-------|------|--------|-------|-------| EOF cat > "$WS/notes/README.md" << 'EOF' # Notes Directory Organized notes and tracking files. - `daily-reviews/` — Daily review logs - `decisions/` — Important decisions made - `cost-tracking.md` — Subagent cost tracking EOF cat > "$WS/docs/README.md" << 'EOF' # Documentation Project documentation, guides, and references. EOF cat > "$WS/scripts/README.md" << 'EOF' # Scripts Utility scripts for workspace maintenance and automation. EOF ``` ### Technical Analysis The setup script writes its placeholder files with the shell truncation operator (`>`), without checking whether each destination already exists or is a symbolic link. If a regular destination file exists, it is silently truncated and replaced. This conflicts with the script's initialization purpose because running it again can destroy legitimate workspace content. Shell redirection also follows symbolic links. If an attacker who can modify the selected workspace creates one of the destination paths as a symbolic link, running the setup script causes the link target to be truncated and overwritten. Quoting `"$WS"` prevents shell word splitting but does not prevent symbolic-link traversal or replacement of an existing file. Exploitation requires the attacker to control or modify one of the destination paths before another user runs the script. The target must also be writable by the account executing the setup script. ### Attack Path 1. The attacker obtains write access to the selected workspace or one of its `notes`, `docs`, or `scripts` d ...[truncated 1189 chars]
- Remediation
- ## Remediation Suggestions - Do not overwrite existing files by default. Treat an existing destination as an error or preserve it and report that initialization was skipped. - Reject symbolic-link destinations explicitly with checks such as `[ -L "$destination" ]`. - Verify that destination parent directories are real directories and are owned or trusted by the invoking user. - Create new files with exclusive-creation semantics rather than ordinary `>` redirection. A small helper using `noclobber`, a safely opened file descriptor, or a language API supporting `O_CREAT | O_EXCL | O_NOFOLLOW` is preferable. - If replacement is required, expose an explicit `--force` option and clearly warn that existing content will be destroyed. - For updates, write to a securely created temporary file in the same trusted directory and atomically rename it only after validating the destination. - Avoid recommending or requiring execution with elevated privileges.
