Skip to content

Commit 916fc50

Browse files
committed
Reject path traversal segments in methodology analysis fallback guards
When realpath is unavailable, paths containing ".." could bypass the prefix-based allowlist check by matching the loop directory prefix as a raw string while resolving to a location outside it. Now reject any path with ".." segments in the fallback code path (fail closed).
1 parent 4326860 commit 916fc50

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

hooks/loop-read-validator.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,16 @@ if [[ -n "$_MA_CHECK_DIR" ]]; then
9797
fi
9898
_ma_real_loop=$(realpath "$_MA_CHECK_DIR" 2>/dev/null || echo "")
9999
# Fallback to raw paths when realpath is unavailable (older macOS/BSD)
100-
# Ensure paths are absolute so prefix guards cannot be bypassed
100+
# Ensure paths are absolute so prefix guards cannot be bypassed.
101+
# Reject paths with ".." segments to prevent traversal bypasses
102+
# when we cannot canonicalize (fail closed).
101103
if [[ -z "$_ma_real_path" ]]; then
104+
if [[ "$FILE_PATH" == *".."* ]]; then
105+
echo "# Read Blocked During Methodology Analysis
106+
107+
Path contains traversal segments that cannot be resolved without realpath." >&2
108+
exit 2
109+
fi
102110
if [[ "$FILE_PATH" == /* ]]; then
103111
_ma_real_path="$FILE_PATH"
104112
else

hooks/loop-write-validator.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,16 @@ if [[ -n "$_MA_LOOP_DIR" ]] && [[ -f "$_MA_LOOP_DIR/methodology-analysis-state.m
121121
fi
122122
_ma_real_loop=$(realpath "$_MA_LOOP_DIR" 2>/dev/null || echo "")
123123
# Fallback to raw paths when realpath is unavailable (older macOS/BSD)
124-
# Ensure paths are absolute so prefix guards cannot be bypassed
124+
# Ensure paths are absolute so prefix guards cannot be bypassed.
125+
# Reject paths with ".." segments to prevent traversal bypasses
126+
# when we cannot canonicalize (fail closed).
125127
if [[ -z "$_ma_real_path" ]]; then
128+
if [[ "$FILE_PATH" == *".."* ]]; then
129+
echo "# Write Blocked During Methodology Analysis
130+
131+
Path contains traversal segments that cannot be resolved without realpath." >&2
132+
exit 2
133+
fi
126134
if [[ "$FILE_PATH" == /* ]]; then
127135
_ma_real_path="$FILE_PATH"
128136
else

0 commit comments

Comments
 (0)