Skip to content

Commit b49fd2d

Browse files
authored
Merge pull request #580 from kwacky1/fix/hooks-fail-open
fix: guardrail hooks fail-open instead of fail-closed
2 parents 0ea0456 + 259011f commit b49fd2d

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

copilot-plugin/hooks/_common.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@
44
#
55
# Exports: TOOL_NAME, COMMAND
66
# Exits 0 (allow) immediately if the tool is not bash or if there is no command.
7+
#
8+
# IMPORTANT: Do NOT use `set -e` here. These hooks must fail-open — if anything
9+
# goes wrong (bad input, missing jq, unexpected payload shape), we exit 0 (allow)
10+
# rather than erroring out and blocking all tool calls.
711

8-
set -e
12+
# Trap: any unexpected error → allow (fail-open, not fail-closed)
13+
trap 'exit 0' ERR
914

1015
_INPUT=$(cat 2>/dev/null || true)
1116

17+
# If input is empty or not valid JSON, allow
18+
if [ -z "$_INPUT" ] || ! echo "$_INPUT" | jq empty 2>/dev/null; then
19+
exit 0
20+
fi
21+
1222
# Defensive: handle missing or malformed JSON gracefully
1323
TOOL_NAME=$(echo "$_INPUT" | jq -r '.toolName // empty' 2>/dev/null || true)
1424
if [ "$TOOL_NAME" != "bash" ]; then

0 commit comments

Comments
 (0)