Repository navigation
fix(permission-manager): fail safe when analysis fails (jq depth, parse errors, write-check overflow) - #257
Merged
st0nefish-ci[bot] merged 2 commits intoNov 26, 2026
Conversation
…ngine fails
classify() discarded jq's stderr and treated any engine failure as a silent
passthrough. shfmt nests its AST two levels per pipe stage, and jq builds with
a 256-entry parse stack (jq 1.6, Debian jq 1.7) reject trees past about 61
stages, so `git push -f; ls|ls|...` lost its danger ask. Engine failures now
ask, and a direct AST depth bound makes the outcome the same on every jq build.
- gate.sh: add MAX_AST_DEPTH=120, checked against shfmt's tab indentation
before jq runs (oversize ask); a direct depth check covers $( ), { }, if and
$(( )) nesting, which a pipe/operator count would miss
- gate.sh: classify captures jq's stderr and exit status; new engine_failed
routes timeouts (124) and depth-limit errors to oversize, other failures to
an engine-error ask; an unreadable operator probe or non-JSON shfmt output
still passes through like a missing dependency
- gate.sh: new ask_reason (used by oversize) falls back to a fixed hook JSON
when jq cannot render the ask
- gate.sh: resolve_check returns 2 on a check-engine failure; a failed
write-target check after a passthrough verdict now asks
- tests: 150-stage allow case becomes 50 stages; add depth regressions
(git push -f + 130 stages, 57-stage pipeline, 20 nested $( )) and fake-jq
tests for engine crash, depth error, check failure and bypassPermissions
- README: document the depth bound and that engine failure asks
- bump permission-manager to 3.2.1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018KC1pVVZ3E6ui65fNGWfdT
…te targets Two older paths still fell open. A command shfmt cannot parse passed through, but bash runs the complete statements before a syntax error (`git push -f` then a stray `(`), and shfmt rejects some syntax bash accepts (`! ! ls`). And more than MAX_PATHS write targets (or a realpath failure) skipped the symlink check silently, so padding hid `echo x > link-to-bashrc`. - gate.sh classify: a non-zero shfmt exit (other than timeout and its depth limit, already oversize) is now a parse-error ask, at top level and for bash -c/eval payloads; shfmt exiting 0 without JSON and an unreadable operator probe still pass through as an unsupported shfmt - gate.sh resolve_check: returns 3 for a missing or non-GNU realpath (probed only after a failed call); the write-target block asks (write-check) on rc 1 (overflow, realpath failure) as on rc 2; the allow path still only drops the allow - tests: cases/structural.tsv flips 8 syntax-error cases from PASS to ASK (unterminated quote, unterminated heredoc, `ls '`, `if then`, `;;`, `)`, `echo $((`, `git push -f "`), which encoded the old parse-failure passthrough; add parse-error tests (danger prefix then `(`, `! !`, bash -c payloads with danger and harmless prefixes, single `!` still allowed), a 130-target write-check test, a plain-writes passthrough check, and a fake-jq exit-124 timeout test - gate.sh header comment and README outcome table, parse-failure and write-check sections updated Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018KC1pVVZ3E6ui65fNGWfdT
st0nefish-ci
Bot
deleted the
bug-permission-manager-jq-depth-fail-open
branch
November 26, 2026 17:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The permission-manager gate failed open whenever its analysis could not run: the command passed through with no decision, so a danger rule's ask was lost.
jq parse-depth limit (the root cause of two tests failing locally but passing in CI). shfmt nests the AST about two levels per pipe stage. jq builds with a 256 parse-depth limit (jq 1.6, Debian's jq 1.7) reject a pipeline of 62 or more stages with
Exceeds depth limit.classifytreated that as a passthrough. Reproduced on jq-1.7:git push -fasks, butgit push -f; ls|ls|…with 130 pipes passed through. CI's Ubuntu jq accepts deeper input, so CI never hit it.MAX_AST_DEPTH=120bound, checked before the engine runs. It measures the tab indentation of shfmt's JSON, which tracks the nesting exactly. It also covers$( ),{ },ifand arithmetic, which an operator count misses.engine_failed: an engine timeout (124) asks as oversize, and a depth error or any other engine failure asks.Two pre-existing fail-open paths, closed after a security review.
[parse-error]), both at top level and in thebash -c/evalpayload re-parse. bash runs a valid prefix before it reaches the syntax error, sogit push -f+ newline +(used to run the push unchecked. shfmt is also stricter than bash (it rejects! ! ls). The undecodable-shfmt and operator-probe cases keep their documented passthrough.[write-check]): more than 128 targets, over 32 KB of paths, or a realpath failure. Before, a~/.bashrcsymlink write could hide behind 130 extra targets. A missing or non-GNU realpath still passes through as a missing dependency. The allow path only drops the allow, as before.Tests
tests/permission-manager/test-gate.sh:$( )! !check.jqfailure, and bypassPermissions staying silent.tests/permission-manager/cases/structural.tsv: 8 syntax-error cases change from PASS to ASK. They encoded the old parse-failure passthrough.test.sh0 failures,lint-shell.shclean. Latency is unchanged within noise.Caveats
ls *(.)), which matters when the Bash tool runs zsh.$( ), now prompt on every jq build.🤖 Generated with Claude Code
https://claude.ai/code/session_018KC1pVVZ3E6ui65fNGWfdT