Skip to content

fix(hooks): judge git argv instead of command substrings in guard-git - #194

Merged
danielvm-git merged 6 commits into
mainfrom
fix/guard-git-flag-normalize
Nov 3, 2026
Merged

danielvm-git merged 6 commits into
mainfrom
fix/guard-git-flag-normalize

Conversation

@danielvm-git

Copy link
Copy Markdown
Owner

Summary

Fixes #184 (defect family 5 / e86 — application & script security).

guard-git matched literal substrings against the raw command. Reordering a flag, or putting a git
global option in front of the subcommand, walked straight through — and one sanctioned shape was
blocked by mistake. The guard now judges the parsed invocation.

  • New rule table scripts/lib/git-argv.py (quote-aware tokenizer → strip -C <path>,
    -c k=v, --no-pager, --git-dir=… → decide on (subcommand, arguments)).
  • Mirrored in extensions/omp-hooks.ts (tokenizeArgs / gitInvocations /
    classifyGitInvocation / dangerousGitCommand), which is what the tool_call handler now calls,
    so the shell hooks and the extension cannot drift silently.
  • Wired into hooks/pre-tool-use.sh and hooks/pre/bash.sh. If the helper is unreachable (hook
    symlinked outside an installed package) the hooks keep the legacy literals rather than degrade to
    allow-everything. Non-git commands skip the helper entirely (per-tool-call latency).
  • skills/guard-git/SKILL.md documents the argv rule and how to add one.

Rules

reset + --hard · clean with any -f*/--force · branch -D or --delete + force ·
checkout with -f/--force or a . pathspec · restore with --worktree or . ·
push with -f/--force/+refspec unless --force-with-lease.

Evidence

Pre-fix, the same 29-row fixture table against the old hook: 20 correct, 8 bypassed, 1 false
positive
.

BYPASS: git reset -q --hard                    BYPASS: git push origin main -f
BYPASS: git reset --keep --hard                BYPASS: git push origin +main
BYPASS: git checkout -- .                      FALSE+: git push --force-with-lease origin main
BYPASS: git checkout -f main
BYPASS: git restore --staged --worktree .
BYPASS: git -C /tmp/repo branch --delete --force feature/x

Post-fix, bash scripts/test-guard-git-normalize.sh:

PASS (a) shell hook matches all 29 fixture rows
PASS (b) TS extension matches all 29 fixture rows
PASS (c) shell and TS agree on all 29 rows
PASS (d) adjacent rules: commits, pushes, gemini JSON, pi fallback
4 passed, 0 failed

Mutation check (anti-vacuity): commenting out the classifier call in the hook fails 20 of 29 rows,
so the gate bites. Wired as guard-git-normalize in scripts/lib/golden-suite-gates.sh (7s).

Two defects found while doing this (logged, one fixed here)

  1. Fixed in this PR — hooks/pre/bash.sh had a syntax error since feat(e82): upstream fork innovations — Jujutsu VCS, OMP plugin, community credit #118
    (BUG-2026-11-03-pi-shell-hook-dead): [[ =~ …([^"]+)… ]] does not parse, so the pi/OMP shell
    fallback never executed a single check. Regex hoisted to a variable; section (d) now runs
    bash -n on it.
  2. Logged, not fixed — the Co-authored-by check only inspects the first -m
    (BUG-2026-11-03-guard-attribution-second-m): git commit -m "fix(x): y" -m "Co-authored-by: bot"
    still passes, and the TS extension has no attribution check at all. That needs its own red/green
    cycle in both implementations.
  3. Logged, not fixed — the protected-branch push check matches the word main anywhere in the
    command (BUG-2026-11-03-guard-push-target-matches-text): it blocked this very branch's push
    because an echo "=== commits ahead of main ===" sat in the same command line.

Preflight

  • npm run compliance → 0
  • bash scripts/run-verification-gates.sh → PASS (omp-extension 0.8s, guard-git-normalize 7s)
  • bash scripts/sync-skills.sh → 0, idempotent on re-run (generated .cursor/.gemini/.pi
    copies of the skill doc committed with it)
  • bash scripts/trace-stories.sh --strict → 0

Test plan

  • bash scripts/test-guard-git-normalize.sh → 4 passed
  • In a Claude/Cursor/Gemini session with the hook installed:
    git -C /tmp reset -q --hard blocked, git push --force-with-lease origin feat/x allowed
  • bash scripts/validate-omp-extension.sh → passed

The guard-git parity gate compared dangerousGitCommand() (the destructive-argv
table) against the whole shell hook, so the protected-branch and Conventional
Commits rules had no TS oracle at all. The fixture also asserted 'allow' for a
push to protected main, and the harness inherited GIT_BIGPOWERS_LAND, which
turns the protected-branch block off.

- Export evaluateBashCall(), the pure function the tool_call handler decides
  with, and probe that instead of the argv table alone.
- Split the force-with-lease fixture row: feature/x allows, main blocks on the
  protected-branch rule.
- Strip GIT_BIGPOWERS_LAND from the harness environment so the verdict cannot
  depend on the developer's shell.

Refs BUG-2026-11-03-guard-normalize-parity-vacuous.
Fixes verification-gates red on run 41657748958.
assert-epic-gate release requires a fresh specs/AUDIT_LATEST.md with a
VERDICT line, and release-branch step 2a requires specs/security/REVIEW.md to
match the branch diff. Both were absent/stale for this branch, so the release
gate was red for reasons unrelated to the fix.

- AUDIT_LATEST.md: full audit-code checklist, 2 stated waivers (evaluateBashCall
  length, omp-hooks.ts size — both pre-existing or judged clearer whole).
- security/REVIEW.md: threat model for a shell-command deny-list, one documented
  medium residual (indirection bypass), no HIGH findings.

Refs BUG-2026-11-03-guard-normalize-parity-vacuous.
@danielvm-git
danielvm-git merged commit 9532372 into main Nov 3, 2026
7 checks passed
@danielvm-git
danielvm-git deleted the fix/guard-git-flag-normalize branch November 3, 2026 15:48
github-actions Bot pushed a commit that referenced this pull request Nov 3, 2026
## [2.91.1](v2.91.0...v2.91.1) (2026-11-03)

### Bug Fixes

* **hooks:** give each guard fixture row its own branch context ([#196](#196)) ([5d379df](5d379df))
* **hooks:** judge git argv instead of command substrings in guard-git ([#194](#194)) ([9532372](9532372)), closes [#184](#184)
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 2.91.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

danielvm-git added a commit that referenced this pull request Nov 7, 2026
)

* fix(tooling): name the ACTIVE_WORK trigger in version-gap check

Story e83s05. Block semantics unchanged; JSON now carries trigger.

* fix(release): mirror last_tag and stamp live skill counts

Story e83s01. sync-version-mirrors writes release.last_tag; sync-skills stamps the skill count into package.json and mcp-server.js.

* fix(cli): status counts only bigpowers-owned skill links

Story e83s02. Foreign links are reported on a separate line.

* fix(receipts): read cycle-time ledger and label sources honestly

Story e83s03. Publishes source breakdown and a staleness flag.

* docs(specs): refresh VISION criteria and re-baseline the catalog

Story e83s04. Zero drift warnings against the new baseline.

* docs(specs): mark e83 done and record gate decisions

Epic e83 stories s01-s05 complete.

* fix(ci): move drift-check python out of a heredoc that stalls

check-catalog-drift.sh hung in the story-verify gate. Logic now lives in scripts/lib/check-catalog-drift.py; behaviour unchanged.

* fix(ci): stop e83 story verify recursing into the gate

The epic.yaml verify lines called run-story-verify.sh, so a done story re-entered the gate without end. Real checks now live in verify-e83.sh, and run-story-verify.sh rejects a self-referential verify.

* fix(specs): make e83s04 task verifies runnable by the gate

Task verify lines began with ! and were rejected as prose.

* docs(specs): record story-verify recursion and green preflight

* fix(e83): address review — enforceable negations, SKILL.md count, realpath

Findings 1, 6, 8 of the independent review. Others are low severity and left.

* fix(e83): resolve remaining review findings

Receipts: per-row skip, tz-correct latest entry, backfilled label, no tree mutation in verify. Story-verify guard covers wrappers via env var, with a regression test. Bug status uses the fixed vocabulary.

* docs(specs): persist e83 verify-work evidence

Terminal verdict is a single Preflight gates run.

* test(sync): guard against a doubled skill count in host manifests

sync-post.sh built the .pi and gemini manifest descriptions from
"${skill_count} skills — ${pkg_desc}", but package.json's description is
already stamped with the count by stamp-skill-counts.sh, so a sync emitted
"80 skills — 80 agent skills …".

This test pins the invariant — the live count appears exactly once — and
fails on the current tree.

* fix(sync): stop stamping the skill count twice into host manifests

stamp-skill-counts.sh writes the live count into package.json's description
("80 agent skills …"), and sync-post.sh then prefixed the count again for
.pi/package.json and gemini-extension.json, producing
"80 skills — 80 agent skills …".

The committed artifacts predate the stamp, so sync-skills.sh could not
reproduce what the branch commits and CI's
`git diff --exit-code .pi .gemini/extensions/bigpowers` went red on every run.
Strip the leading count before re-prefixing; sync is idempotent again and
regenerates the committed text exactly.

* docs(specs): refresh traceability matrix and codebase wiki for e83

Picks up e83s01-s05 as done plus the new test-manifest-skill-count-once.sh link.
Generated content only; report timing churn was reverted rather than committed.

* docs(specs): audit and security-review e83; log the fail-open release gate

specs/AUDIT_LATEST.md and specs/security/REVIEW.md still described
fix/guard-git-flag-normalize (PR #194, 2 commits) while this branch carries 15
commits, yet assert-epic-gate.sh release reported "audit-code verified". Replace
both with reviews of the real diff and record the gate defect as
BUG-2026-11-07-assert-epic-gate-fail-open.

* docs(specs): regenerate traceability outputs for the new release-gate bug

Generated by compliance/trace runs after BUG-2026-11-07-assert-epic-gate-fail-open
was registered and the spec-version-gap bug bundle was first emitted.

* docs(specs): correct the audited commit count to 18

* fix(okf): accept the mixed receipt source and require its breakdown

e83s03 taught build-receipts.sh to label a blended reading "mixed" and
verify-e83.sh asserts that label, but validate-okf-kinds.sh allowed only
measured/estimated/backfilled/absent. CI's sync job therefore failed on the
committed specs/receipts.json.

Accept "mixed" and strengthen the validator while doing it: a mixed reading
must carry value.source_breakdown, its keys must be known sources, and the
parts must sum to value.story_count. A "mixed" label without evidence stays a
failure.

* test(gates): validate the OKF directories that CI validates

The local gate set never ran validate-okf.sh over specs/, so compliance and
run-verification-gates.sh both reported green while CI's sync job was red on
e83s03. Add an okf-bundles gate covering the same six directories CI covers,
so the two lists cannot drift apart silently.

* docs(specs): record the OKF gate parity fix in the e83 audit
github-actions Bot pushed a commit that referenced this pull request Nov 7, 2026
# [2.95.0](v2.94.2...v2.95.0) (2026-11-07)

### Features

* **e83:** truth in the cockpit — fix the drift the red team found ([#233](#233)) ([2be64ec](2be64ec)), closes [#194](#194)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(pre-tool-use): normalize git flags in dangerous pattern detection

1 participant