Skip to content

remove_iso_files.sh: prefix can escape the repo root and rm -rf runs unquoted #12134

Closed

Description

@dezren39

Finding

lib/remove_iso_files.sh takes its prefix argument from the command line without checking it, builds a glob from it, and deletes the matches with an unquoted rm -rf. A prefix containing / or .. escapes the repository root, and with -force the confirmation prompt is skipped, so the deletion happens with no warning.

Evidence (verified in the current tree)

  • lib/remove_iso_files.sh:19-37: prefix="$1" with no validation beyond the empty check.
  • lib/remove_iso_files.sh:66-67: cd "$repo_root" then prefix="${prefix}_", with no check that prefix is a plain name.
  • lib/remove_iso_files.sh:70: pattern=./${prefix}*.iso.
  • lib/remove_iso_files.sh:103: rm -rf $pattern. The variable is unquoted, so word splitting and globbing apply again to the already-built pattern.
  • Reproduction in a scratch tree: repo at .../repo with a sibling ../outside/victim_x.iso. Running bash remove_iso_files.sh ../outside/victim -force printed ./../outside/victim_*.iso, found 1 file, and deleted ../outside/victim_x.iso. Return code 0.
  • A prefix with a space ('a b') does not delete anything, but it still reports "Exiting without error" under -force, because the unquoted glob splits into two words.
  • Callers: lib/build_iso.sh:127 passes "$hostname" with -force. The risk is an operator typo or a hostname value that carries a path, not a remote attacker.

Why it matters

Deleting files outside the repo is irreversible and gives no prompt when -force is used. The script's own header says it only erases ISO files "in the repository root".

Suggested fix shape

  • Accept only a plain name: reject any prefix that contains /, starts with ., or contains characters outside [A-Za-z0-9._-], with a usage error and non-zero exit. The operator script argument contract (AGENTS.md, doc/agents/operator-script-argument-contract.md) asks for exactly this kind of strict parse.
  • Use a bash array or find -maxdepth 1 -name ... -print0 and rm -f -- on the array instead of rm -rf $pattern.
  • Add a test that a prefix containing ../ is refused and that a file outside the root survives.

Activity

  1. added
    kind/bug
    app/lib
    on Nov 20, 2026
  2. developing-today commented on Nov 20, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Claim — Lane VH (archer) taking code#12134 now.

    Plan: verify the premise on current main (lib/remove_iso_files.sh — prefix escape + unquoted rm -rf). A sibling fix (commit 8034f4b3934, for #12135) reportedly rewrote this script but the rewrite was never runtime-verified against this issue's reproduction. I will re-run the issue's scratch-tree reproduction against current main: if the escape is refused and the outside file survives, close as completed with fresh evidence; if it still escapes, implement the suggested fix shape (plain-name prefix validation, array/rm -f -- deletion, regression test), PR, merge, close.

  4. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    Done — Lane VH (archer), 2026-11-23: premise STALE; the vulnerability is fixed on main. Closing as completed.

    The fix landed 2026-11-21 in commit 8034f4b39343c7d480ae6ee78dd5c399ef918009 ("lib: keep remove_iso_files inside the repo root", Refs #12134) — the same commit that fixed sibling #12135. It implements this issue's suggested fix shape: the prefix must match ^[A-Za-z0-9_][A-Za-z0-9._-]*$ (no /, no leading ., no glob/shell metacharacters), matches are collected into a bash array under nullglob, and deletion is rm -f -- "${files[@]}" — no unquoted rm -rf $pattern remains. That commit was never runtime-verified against this issue's reproduction; this pass supplies that verification.

    Runtime verification (laptop, script extracted verbatim from current origin/main, scratch tree with a sibling ../outside/victim_x.iso, run from a scratch git repo):

    1. bash remove_iso_files.sh ../outside/victim -force → refused: Error: prefix must be a plain name, exit 1, victim file survived. (The issue's original reproduction deleted the victim and exited 0.)
    2. Prefix 'a b' → refused, exit 1.
    3. Prefix .hidden → refused, exit 1.
    4. Prefix 'h*' → refused, exit 1; matching in-root file untouched.
    5. Normal path intact: prefix host1 -force deleted exactly the two in-root host1_*.iso files, exit 0; a non-matching in-root ISO and the outside victim were untouched.

    Caller compatibility: the only caller, lib/build_iso.sh:127, passes "$hostname" — a plain name, accepted by the new validation.

    Noted gap (no action taken): no checked-in regression test or verifier references remove_iso_files anywhere on main (git grep finds only the caller); the runtime evidence above is the verification of record for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/libkind/bugstatus:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions