T09 · Insecure Skill Coding Practices
- Location
scripts/analyze_tiktok.sh:12- Finding
Predictable Shared Temporary Files Permit File Clobbering and Cross-Run Interference
- Content
View full analysis
&1 | tail -3 echo "" echo "🖼️ Extracting thumbnail frames..." ffmpeg -i /tmp/tiktok-ref.mp4 -vf "fps=1/5" /tmp/tiktok-frame-%03d.jpg -update 1 -y 2>/dev/null echo "Frames saved to /tmp/tiktok-frame-*.jpg" echo "" echo "📝 Attempting subtitle extraction..." yt-dlp --write-auto-sub --sub-lang "vi,en,zh" --skip-download \ -o "/tmp/tiktok-sub" "$URL" 2>&1 | grep -E "Writing|ERROR|no subtitles" ``` The same unsafe pattern is also presented as operational guidance in `SKILL.md`, lines 48-54. ### Technical Analysis The script stores downloaded videos, extracted frames, and subtitles under fixed, globally predictable paths in the shared `/tmp` directory. It does not create a private per-execution directory, verify file ownership, reject symbolic links, or prevent concurrent runs from sharing the same files. The `ffmpeg` invocation additionally uses `-y`, which enables unconditional output replacement. A local attacker who can write to the shared temporary directory may pre-create a predicted output path as a symbolic link or manipulate the path during execution. Depending on the target program's file-opening behavior and operating-system protections, output may be redirected to another file writable by the victim account. Even where system-level symbolic-link protections prevent a direct overwrite, deterministic names still allow concurrent or malicious executions to replace, corrupt, disclose, or mix video files, frames, and subtitles. The fixed `/tmp/tiktok-ref.mp4` input can also contain stale or attacker-substituted content rather than the video downloaded for the current invocation. ### Attack Path 1. A local attacker identifies the predictable paths, such as `/tm ...[truncated 1738 chars]- Remediation
View remediation
&2 exit 1 } trap 'rm -rf -- "$WORKDIR"' EXIT VIDEO_TEMPLATE="$WORKDIR/reference.%(ext)s" FRAME_TEMPLATE="$WORKDIR/frame-%03d.jpg" SUBTITLE_TEMPLATE="$WORKDIR/subtitles" yt-dlp -o "$VIDEO_TEMPLATE" --no-playlist -- "$URL" VIDEO_FILE="$(find "$WORKDIR" -maxdepth 1 -type f -name 'reference.*' -print -quit)" if [ -z "$VIDEO_FILE" ]; then echo "Downloaded video was not found" >&2 exit 1 fi ffmpeg -nostdin -n -i "$VIDEO_FILE" \ -vf "fps=1/5" "$FRAME_TEMPLATE" yt-dlp --write-auto-sub --sub-lang "vi,en,zh" --skip-download \ -o "$SUBTITLE_TEMPLATE" -- "$URL" ``` Additional hardening measures: 1. Do not reuse fixed paths across users or executions. 2. Use `umask 077` so generated media is accessible only to the executing account. 3. Avoid `ffmpeg -y` for security-sensitive temporary outputs; use `-n` to reject unexpected collisions. 4. Keep every intermediate file inside the private directory created by `mktemp -d`. 5. Add a cleanup trap so temporary media is removed on normal exit and most failures. 6. Pass the generated frame path directly to the analysis tool rather than relying on a global fixed filename. 7. Validate that the downloaded file exists inside the private directory before processing it. 8. Run the workflow as an unprivileged, isolated account with no access to sensitive files. 9. Update the command examples in `SKILL.md`, lines 48-54, to use the same secure temporary-directory pattern. ]]>
