T09 · Insecure Skill Coding Practices
- Location
scripts/scaffold_site.sh:12- Finding
Caller-Controlled Output Directory Permits File Clobbering and Symlink-Following Writes
- Content
View full analysis
"$OUT/index.html" <<'HTML' ``` The same overwrite pattern is used for the other generated files: ```bash cat > "$OUT/style.css" <<'CSS' ``` ```bash cat > "$OUT/app.js" <<'JS' ``` ### Technical Analysis The script accepts its output directory directly from the first command-line argument and creates it with `mkdir -p`. This permits the destination to be an existing directory. It then uses ordinary shell redirection to create or truncate `index.html`, `style.css`, and `app.js` without checking whether those paths already exist or are symbolic links. Shell redirection follows symbolic links by default. Consequently, if an attacker can influence the output-directory argument or prepare files inside the selected directory, the generated content can overwrite other files accessible to the account running the script. The flaw does not independently elevate privileges. Its practical scope is limited to files writable by the executing user. The consequences become more serious if an agent runs the script with elevated privileges or broad filesystem access. ### Attack Path 1. The attacker identifies or creates a directory that the executing account can access. 2. The attacker creates one of the expected output paths as a symbolic link, for example: ```bash mkdir -p /tmp/runner-output ln -s /path/to/writable/target /tmp/runner-output/index.html ``` 3. The attacker causes the agent or user to execute: ```bash ./scripts/scaffold_site.sh /tmp/runner-output ``` 4. `mkdir -p` accepts the existing directory. 5. The redirection to `/tmp/runner-output/index.html` follows the symbolic link and truncates or replaces the linked target with ...[truncated 894 chars]- Remediation
View remediation
&2 exit 1 fi done ``` 3. Enable shell no-clobber behavior before redirection: ```bash set -o noclobber ``` This protects existing regular files but should be combined with explicit symbolic-link checks. 4. Canonicalize and validate the requested destination against an approved workspace root when the script is invoked by an automated agent. 5. Create generated files in a securely created temporary directory, verify them, and then move the complete directory into a new destination. 6. Run the scaffolder as an unprivileged account with filesystem access restricted to the intended workspace. 7. Clearly document that the output argument must not point to an existing project or sensitive system directory. ]]>
