Skip to content

Commit 259011f

Browse files
kwacky1Copilot
andcommitted
fix: guardrail hooks fail-open instead of fail-closed
Remove `set -e` from _common.sh and add `trap 'exit 0' ERR` so that unexpected errors (empty input, malformed JSON, non-bash tool payloads) result in allowing the tool call rather than blocking it. Previously, when non-bash MCP tools (e.g. Zendesk, GitHub MCP) triggered the preToolUse hooks, the script could error out before reaching the 'toolName != bash' check. The CLI interprets hook errors as denials, which blocked ALL tool calls — including reads, shell commands, and MCP. Also adds early JSON validation: if input is empty or invalid JSON, exit immediately with allow. Fixes #579 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 0ea0456 commit 259011f

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)