T09 · Insecure Skill Coding Practices
- Location
apply-logo.sh:107- Finding
Unsafe temporary-file construction enables symlink race and arbitrary file overwrite
- Content
View full analysis
"$MASTER" 2>/dev/null; then base64 -D -i "$SETDIR/favicon-master.txt" > "$MASTER" fi ``` The same pattern is used for ICO generation: ```bash write_ico() { local src="$1" dst="$2" size="$3" local tmp tmp="$(mktemp "$TMPROOT/fav.XXXXXX").png" resize_png "$src" "$tmp" "$size" case "$TOOL" in sips) sips -s format ico "$tmp" --out "$dst" >/dev/null 2>&1 || cp "$tmp" "$dst" ;; magick) magick "$tmp" "$dst" 2>/dev/null || cp "$tmp" "$dst" ;; convert) convert "$tmp" "$dst" 2>/dev/null || cp "$tmp" "$dst" ;; pillow) python3 - "$tmp" "$dst" <<'PY' || cp "$tmp" "$dst" import sys from PIL import Image Image.open(sys.argv[1]).save(sys.argv[2], "ICO", sizes=[(64,64),(32,32),(16,16)]) PY ;; *) cp "$tmp" "$dst" ;; esac rm -f "$tmp" } ``` ### Technical Analysis `mktemp` securely creates a randomly named file, but the script subsequently appends `.png` to the returned pathname. For example, `mktemp` creates: ```text /tmp/logo-master.ABC123 ``` while the script writes to: ```text /tmp/logo-master.ABC123.png ``` The latter path was not created securely and is not protected by `mktemp`. The original empty file is also not removed because `CLEANUP` refers only to the suffixed pathname. On a shared system, a local attacker can monitor temporary-directory creation, learn the securely generated base name, and create the corresponding `. ...[truncated 1659 chars]- Remediation
View remediation
