Skip to content

Commit 7c4356c

Browse files
committed
fix: correct managed-hook dedup regex and block unresolvable symlinks
install-codex-hooks.sh: managed_pattern only matched commands ending with whitespace or end-of-string after the .sh filename, missing shell-quoted forms produced by shlex.quote when runtime_root contains spaces. Updated the trailing anchor to also accept quote characters so duplicate Stop hooks are not inserted on reinstall. loop-read-validator.sh: the realpath-unavailable fallback used the raw unresolved path for prefix checks, allowing a symlink outside the project root pointing to a project file to bypass the methodology analysis read restriction. Added a symlink check that blocks the read when the path cannot be canonicalized (fail closed).
1 parent e61b570 commit 7c4356c

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

hooks/loop-read-validator.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ if [[ -n "$_MA_CHECK_DIR" ]]; then
104104
Path contains traversal segments that cannot be resolved without realpath." >&2
105105
exit 2
106106
fi
107+
# Fail closed if the file is a symlink we cannot resolve; the raw
108+
# path would skip the project-root prefix guard, allowing a symlink
109+
# outside the project to point back at restricted project content.
110+
if [[ -L "$FILE_PATH" ]]; then
111+
echo "# Read Blocked During Methodology Analysis
112+
113+
Path is a symlink that cannot be resolved without realpath." >&2
114+
exit 2
115+
fi
107116
if [[ "$FILE_PATH" == /* ]]; then
108117
_ma_real_path="$FILE_PATH"
109118
else

scripts/install-codex-hooks.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ if stop_groups is None:
135135
if not isinstance(stop_groups, list):
136136
raise SystemExit(f"existing hooks config has invalid Stop array: {hooks_file}")
137137
138-
managed_pattern = re.compile(r"(^|/)hooks/(loop-codex-stop-hook\.sh|pr-loop-stop-hook\.sh)(\s|$)")
138+
managed_pattern = re.compile(r"(^|/)hooks/(loop-codex-stop-hook\.sh|pr-loop-stop-hook\.sh)(['\"\s]|$)")
139139
140140
filtered_groups = []
141141
for group in stop_groups:

0 commit comments

Comments
 (0)