Tom nash/command rules#31
Merged
Merged
Conversation
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.
Command rule hardening
Added layered command matching using:
string matcher (exact/glob/prefix)
argv matcher (token-aware flag matching)
Hardened default destructive push patterns to catch reordered flags:
git push --force
git push -f
Normalized simple command-prefix semantics so:
git commit and git commit * are treated equivalently for matching intent.
Preserved allow-overrides-deny semantics.
Wrapper-aware enforcement
Command rule checks now evaluate wrapped shell forms by unwrapping common wrappers:
sh -c, bash -c, bash -lc, etc.
Read/write shell-op extraction now also evaluates unwrapped inner commands, so wrapped commands are enforced consistently (not just direct invocations).
File rule matching improvements
Added recursive ** glob support for file rules (in addition to existing *, ?, [], exact, and directory-prefix behavior).
Documentation updates (high-level only)
Updated README.md and docs/project-overview-and-concepts.md to reflect:
recursive ** file-glob support
wrapper-aware command enforcement
high-level file vs command enforcement model
Why
This closes practical bypasses and ambiguity points:
Reordered command flags (e.g., trailing --force)
Wrapped command execution (sh -c ...)
Nested path matching needs (**)
It also improves policy authoring UX by making common command patterns behave as users expect.
Test Coverage
Added/expanded tests across store, hook, and CLI integration, including:
command matcher equivalence (cmd vs cmd *)
allow-overrides-deny behavior
wrapped command deny and allow behavior via hook
wrapper depth and option parsing paths
wrapped read/write enforcement (cat, redirection, cd inside wrapped commands)
recursive ** glob matching variants and edge cases
matcher normalization and fallback branches