Skip to content

Commit dee964c

Browse files
committed
Fix command injection (CWE-78) in audit-harness.sh
any_file_match() used `ls $REPO/$pattern` without quoting $REPO. Because the variable was unquoted during word splitting, a crafted REPO value such as "/tmp; rm -rf /" would be split on the semicolon into a second, independent command — a classic shell injection (CWE-78). Replace the `ls | grep` pipeline with `compgen -G "$REPO/$pattern"`. The entire `$REPO/$pattern` is now double-quoted, so no splitting or pathname expansion happens on $REPO, and compgen performs the glob match without spawning an external process. All other 17 `$REPO` uses in the file were already correctly quoted (inside `[[ ]]`, `"$REPO/..."`, or `find "$REPO"`), so this was the single exploitable point.
1 parent 549121b commit dee964c

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

tools/audit-harness.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ dir_exists() { [[ -d "$REPO/$1" ]] && echo "pass" || echo "fail"; }
6767
any_file_match() {
6868
# any_file_match "pattern1" "pattern2" ...
6969
for pattern in "$@"; do
70-
# shellcheck disable=SC2086
71-
if ls $REPO/$pattern 2>/dev/null | grep -q .; then
70+
# Quote "$REPO/$pattern" to prevent word-splitting / command injection (CWE-78).
71+
# compgen -G does glob matching without spawning ls, so a crafted $REPO value
72+
# such as "/tmp; rm -rf /" can no longer be split into a second command.
73+
if compgen -G "$REPO/$pattern" > /dev/null; then
7274
echo "pass"; return
7375
fi
7476
done

0 commit comments

Comments
 (0)