Skip to content

fix(guardrails): scan the command inside an escaped backtick nested in backticks #12398

Closed

Description

@kyle-sexton

Problem

hook::bash_parse_segments in lib/hook-utils.sh (and its 20 synced copies) keeps an escaped backtick inside a backtick substitution as a literal character and never scans the nested command it opens. Bash runs that nested command, so a command the guards would block is not checked:

echo `echo \`git reset --hard\``` runs git reset --hard (verified with a harmless echo HIT in its place: HIT prints), but block-dangerous-git does not see it.

This predates #12384, which fixed the other backtick and # forms but left this one out of scope.

Fix

Parse a \` inside backticks as opening a nested backtick substitution (bash's old-style command substitution nesting) and hand its contents to the segment callback, fail-safe: when the nesting can't be resolved, scan the text as commands. Add the form above and a doubly nested one to plugins/guardrails/hooks/block-dangerous-git.test.sh, then regenerate the copies with scripts/sync-shared-copies.sh.

Related

Refs #12384, #12361.

Activity

  1. added
    needs-triage
    on Nov 2, 2026
  2. github-actions commented on Nov 2, 2026

    @github-actions
    Contributor

    Proposed work class: work-class: scoped
    Basis: automated intake triage; the lanes App applied this class.

    Size: Medium
    Complexity: Medium
    Uncertainty: Known
    Flags: none
    Blocked by: none

    Understood: the guardrails parser (hook::bash_parse_segments in lib/hook-utils.sh) treats an escaped backtick inside a backtick substitution as a literal. As a result, the nested command, such as git reset --hard, is never scanned by block-dangerous-git. The proposed fix parses the nested substitution and hands its contents to the segment callback. When the nesting can't be resolved, it scans the text as commands. Tests for the singly and doubly nested forms are added, then the synced copies are regenerated. The issue is a bounded fix to existing behavior with a clear approach, so nothing is missing. No likely duplicates found among the open issues.

    Automated triage, applied by the lanes App.

  3. added and removed
    needs-triage
    on Nov 2, 2026
  4. added
    status: ready
    on Nov 2, 2026
  5. added
    status: confirmed
    and removed
    status: ready
    on Nov 2, 2026
  6. melodic-automation-lanes commented on Nov 2, 2026

    @melodic-automation-lanes
    Contributor

    Not admitted to the issue lane: no trusted-human acceptance criteria: a listed human must put the confirmed - [ ] criteria in the body or post them as their own comment, or, on an issue a listed human filed, intake's newest refinement comment must hold them unedited. Admission takes the issue once each of those is met, when intake triages it again (.github/actions/resolve-config/admission-rules.json).

  7. melodic-automation-lanes commented on Nov 2, 2026

    @melodic-automation-lanes
    Contributor

    The latest triage verdict holds nothing: the issue is at status: ready.

  8. added
    needs-triage
    and removed
    status: confirmed
    on Nov 2, 2026
  9. melodic-automation-lanes commented on Nov 2, 2026

    @melodic-automation-lanes
    Contributor

    Refinement. A read-only run explored this repository, searched its issues and pull requests, and read the allowed docs to draft what follows. On an issue a listed human filed, it counts as the issue's spec once posted, while unedited; it is still model text, so check it.

    Intended outcome: Make hook::bash_parse_segments treat an escaped backtick inside a backtick substitution as opening a nested substitution whose contents reach the segment callback, so block-dangerous-git blocks it.

    Acceptance criteria

    • lib/hook-utils.sh hook::bash_parse_segments parses a backslash-backtick inside backticks as opening a nested backtick substitution and passes its contents to the segment callback
    • When the nesting cannot be resolved (for example an unterminated nested form), the parser scans the text as commands instead of dropping it
    • plugins/guardrails/hooks/block-dangerous-git.test.sh has a case where echo echo \git reset --hard`` is blocked
    • plugins/guardrails/hooks/block-dangerous-git.test.sh has a doubly nested case, with git reset --hard inside two levels of escaped backticks, that is blocked
    • A harmless nested form such as echo echo \echo ok`` is still allowed
    • The existing backtick, # and here-doc tests in block-dangerous-git.test.sh still pass
    • scripts/sync-shared-copies.sh has been run so all synced copies of hook-utils.sh match lib/hook-utils.sh
    • The repository's check for synced copies being up to date passes

    External state: none

    Sources read

    • /home/runner/work/claude-code-plugins/claude-code-plugins/.base/scripts/sync-shared-copies.sh: exists, used to regenerate the synced copies
    • /home/runner/work/claude-code-plugins/claude-code-plugins/.base/plugins/desktop-notification/hooks/hook-utils.sh:4458: a synced copy of hook-utils.sh containing the bash_parse_segments_uncached parser

    Automated refinement by the lanes App. Intake triages the issue again with it.

  10. removed
    needs-triage
    on Nov 2, 2026
  11. added
    status: ready
    on Nov 2, 2026
  12. added
    admission-deferred
    on Nov 2, 2026
  13. added
    agent-ready
    and removed
    admission-deferred
    on Nov 2, 2026
  14. github-actions commented on Nov 2, 2026

    @github-actions
    Contributor
    No description provided.
  15. github-actions commented on Nov 2, 2026

    @github-actions
    Contributor
    No description provided.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readystatus: ready

    Type

    Fields

    Work status

    agent-ready

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions