T09 · Insecure Skill Coding Practices
- Location
scripts/create-overlay-image.sh:42- Finding
Predictable Shared Temporary Files Permit File Clobbering and Cross-Run Interference
- Content
View full analysis
Vulnerability Details
File Location:
scripts/create-overlay-image.sh, lines 42–63 and 80
Vulnerability Type: Predictable temporary files, symlink race, and unsafe concurrent execution
Risk Level: MediumVulnerable Code:
bash magick "${CHOSEN_PIC}" \ -resize "${WIDTH}x" \ -resize "${WIDTH}x${HEIGHT}^" \ -gravity center \ -extent "${WIDTH}x${HEIGHT}" \ /tmp/oc-bg-resized.png magick -size ${WIDTH}x${HEIGHT} gradient:"rgba(0,0,0,0)-rgba(0,0,0,0.88)" \ /tmp/oc-gradient-bottom.png magick /tmp/oc-bg-resized.png /tmp/oc-gradient-bottom.png -composite /tmp/oc-bg-gradient.png magick -background none -fill white \ -font "/Users/quocmodoro/Library/Fonts/Anton-Regular.ttf" \ -pointsize 50 -size ${QUOTE_W}x160 \ caption:"${QUOTE}" /tmp/oc-quote-text.png rm -f /tmp/oc-bg-resized.png /tmp/oc-bg-gradient.png /tmp/oc-quote-text.png /tmp/oc-gradient-bottom.pngTechnical Analysis
Every invocation reads and writes the same globally predictable filenames under
/tmp. These paths are neither unique to the process nor contained in a private directory. No atomic creation mechanism, ownership validation, or locking is used.This creates two related weaknesses:
- Cross-run interference: Concurrent invocations can overwrite, consume, or remove each other's intermediate images.
- Local file-clobbering race: A local attacker able to write to
/tmpcan pre-create or race the predictable paths, including by using symbolic links. Depending on ImageMagick and operating-system file-opening behavior, writes may be redirected to another file writable by the skill process.
The cleanup operation also targets predictable paths without confirming that they still refer to files created by the current process.
Attack Path
- A local attacker identifies the fixed paths
/tmp/oc-bg-resized.png,/tmp/oc-gradient-bottom.png,/tmp/oc-bg-gradient.png, and `/tmp/oc-quote-tex ...[truncated 1523 chars]
- Remediation
View remediation
Remediation Suggestions
Create a private, uniquely named temporary directory for each invocation and remove it through an exit trap:
bash set -euo pipefail umask 077 TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/image-quote-overlay.XXXXXX")" trap 'rm -rf -- "$TMP_DIR"' EXIT HUP INT TERM BG_RESIZED="$TMP_DIR/bg-resized.png" GRADIENT="$TMP_DIR/gradient-bottom.png" BG_GRADIENT="$TMP_DIR/bg-gradient.png" QUOTE_TEXT="$TMP_DIR/quote-text.png"Pass these variables to every ImageMagick command instead of using fixed
/tmp/oc-*.pngpaths. Additional hardening should include:- Verify that
mktempsucceeded before processing. - Keep the restrictive
umask 077so other users cannot read intermediate images. - Quote every temporary-path expansion.
- Use
trapso cleanup occurs on success, error, interruption, or termination. - Do not manually delete globally predictable paths.
- If output paths may be attacker-controlled, validate the output destination against the application's allowed directory and overwrite policy.
- Add a concurrency test to verify that parallel invocations cannot affect one another.
- Verify that
