Skip to content

Commit 95a6b7b

Browse files
committed
Fix edit validator path fallback and reject whitespace-only completion markers
Edit validator had the same relative-path and traversal fallback issue as the read/write validators. Applied the same normalization and ".." rejection pattern. Methodology completion checker now trims whitespace before emptiness validation, preventing whitespace-only done markers or report files from passing the content gate.
1 parent 515f90a commit 95a6b7b

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

hooks/lib/methodology-analysis.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ complete_methodology_analysis() {
122122

123123
local done_content
124124
done_content=$(cat "$done_file" 2>/dev/null || echo "")
125+
# Trim whitespace to reject whitespace-only markers
126+
done_content="${done_content#"${done_content%%[![:space:]]*}"}"
125127
if [[ -z "$done_content" ]]; then
126128
return 1
127129
fi
@@ -134,6 +136,7 @@ complete_methodology_analysis() {
134136
fi
135137
local report_content
136138
report_content=$(cat "$report_file" 2>/dev/null || echo "")
139+
report_content="${report_content#"${report_content%%[![:space:]]*}"}"
137140
if [[ -z "$report_content" ]]; then
138141
echo "Warning: methodology-analysis-report.md is empty, blocking completion" >&2
139142
return 1

hooks/loop-edit-validator.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,27 @@ if [[ -n "$_MA_LOOP_DIR" ]] && [[ -f "$_MA_LOOP_DIR/methodology-analysis-state.m
104104
fi
105105
_ma_real_loop=$(realpath "$_MA_LOOP_DIR" 2>/dev/null || echo "")
106106
# Fallback to raw paths when realpath is unavailable (older macOS/BSD)
107-
[[ -z "$_ma_real_path" ]] && _ma_real_path="$FILE_PATH"
108-
[[ -z "$_ma_real_loop" ]] && _ma_real_loop="$_MA_LOOP_DIR"
107+
# Ensure paths are absolute and reject ".." to prevent traversal bypasses.
108+
if [[ -z "$_ma_real_path" ]]; then
109+
if [[ "$FILE_PATH" == *".."* ]]; then
110+
echo "# Edit Blocked During Methodology Analysis
111+
112+
Path contains traversal segments that cannot be resolved without realpath." >&2
113+
exit 2
114+
fi
115+
if [[ "$FILE_PATH" == /* ]]; then
116+
_ma_real_path="$FILE_PATH"
117+
else
118+
_ma_real_path="$PROJECT_ROOT/$FILE_PATH"
119+
fi
120+
fi
121+
if [[ -z "$_ma_real_loop" ]]; then
122+
if [[ "$_MA_LOOP_DIR" == /* ]]; then
123+
_ma_real_loop="$_MA_LOOP_DIR"
124+
else
125+
_ma_real_loop="$PROJECT_ROOT/$_MA_LOOP_DIR"
126+
fi
127+
fi
109128
if [[ "$_ma_real_path" == "$_ma_real_loop/"* ]]; then
110129
_ma_basename=$(basename "$_ma_real_path")
111130
case "$_ma_basename" in

0 commit comments

Comments
 (0)