Skip to content

block-dangerous-commands hook: /dev redirect pattern false-positives on stderr null redirects — blocks legitimate read-only commands #11593

Closed

Description

@mrveiss

Symptom

After #11581 made the hooks executable, block-dangerous-commands.sh began firing — and it blocks ordinary read-only commands with "destructive disk operation detected". Four false positives in one session; every blocked command merely contained 2>/dev/null or >/dev/null. It even blocks gh issue create when the issue body quotes the pattern.

Root cause

.claude/hooks/block-dangerous-commands.sh:228:

if echo "$COMMAND_TO_CHECK" | grep -qE '(mkfs|dd[[:space:]]+if=|>[[:space:]]*/dev/)'; then

>[[:space:]]*/dev/ is intended to catch writes to raw devices (> /dev/sda) but also matches the universal shell idiom 2>/dev/null. The hook was committed non-executable (#11581), so this never fired before and the false positive went undetected.

Fix

Restrict the redirect pattern to block devices (/dev/(sd|hd|nvme|vd|xvd|mmcblk|loop|dm-|md)) instead of all of /dev/, keeping mkfs/dd if= intact. Add regression tests: 2>/dev/null and >/dev/null must pass; > /dev/sda1 must stay blocked.

Activity

  1. github-actions commented on Jul 11, 2026

    @github-actions
    Contributor

    PR #11594 (merged to Dev_new_gui) references this issue with a close keyword.

    fix(hooks): disk-redirect guard targets block devices only (#11593)

    If this issue is fully resolved, close it manually. If work remains, no action is needed.

  2. mrveiss commented on Jul 11, 2026

    @mrveiss
    OwnerAuthor

    ✅ Closed with proof of implementation

    Commit(s): f525a513a (guard narrowed + 7 regression tests) — merged to Dev_new_gui via PR #11594.
    Gate 2: check-issue-close-refs.sh 11593 → clear (exit 0).

    Acceptance criteria (quoted verbatim from issue body):

    • "Restrict the redirect pattern to block devices (/dev/(sd|hd|nvme|vd|xvd|mmcblk|loop|dm-|md)) instead of all of /dev/, keeping mkfs/dd if= intact" — ✅ block-dangerous-commands.sh line 228-231, exactly that pattern; mkfs/dd if= alternations unchanged.
    • "Add regression tests: 2>/dev/null and >/dev/null must pass; > /dev/sda1 must stay blocked" — ✅ 7 new cases in block-dangerous-commands_test.sh (3 allow: stderr discard, stdout+stderr discard, git null redirect; 4 block: sda1 write, nvme0n1 write, dd if=, mkfs). Suite: 40 passed, 0 failed.

    Edit was user-authorized in-session (protect-files hook otherwise forbids editing hook scripts).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions