From 87d54689badfb6e64f8678773fa0db872db2ec40 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Fri, 27 Mar 2026 22:14:08 -0700 Subject: [PATCH] fix: freeze hook symlink bypass and prefix collision (MEDIUM-03) - Add POSIX-portable path resolution (cd + pwd -P, works on macOS) - Fix prefix collision: /project-evil no longer matches /project freeze dir - Use trailing slash in boundary check to require directory boundary --- freeze/bin/check-freeze.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/freeze/bin/check-freeze.sh b/freeze/bin/check-freeze.sh index ed748e93..825bc227 100755 --- a/freeze/bin/check-freeze.sh +++ b/freeze/bin/check-freeze.sh @@ -51,9 +51,20 @@ esac # Normalize: remove double slashes and trailing slash FILE_PATH=$(printf '%s' "$FILE_PATH" | sed 's|/\+|/|g;s|/$||') +# Resolve symlinks and .. sequences (POSIX-portable, works on macOS) +_resolve_path() { + local _dir _base + _dir="$(dirname "$1")" + _base="$(basename "$1")" + _dir="$(cd "$_dir" 2>/dev/null && pwd -P || printf '%s' "$_dir")" + printf '%s/%s' "$_dir" "$_base" +} +FILE_PATH=$(_resolve_path "$FILE_PATH") +FREEZE_DIR=$(_resolve_path "$FREEZE_DIR") + # Check: does the file path start with the freeze directory? case "$FILE_PATH" in - "${FREEZE_DIR}"*) + "${FREEZE_DIR}/"*|"${FREEZE_DIR}") # Inside freeze boundary — allow echo '{}' ;;