Repository navigation
Restrict agent gh commands and alias setup (T197) - #86
Conversation
|
Code/security and QA review of
Each finding now has a failing parser-only regression. Fixes are local and under validation; this comment does not claim they are in the pushed commit. The previous partial-edit alias bypass and Python assignment false refusal are fixed in Current pushed-commit evidence: build and check pass; full suite 663/663. Independent QA: 28/28 focused tests pass, but its additional NotebookEdit probe found the gap above. All probes used fake process tools and fake gh files. No attack string executed. |
|
The alias-body identity finding is fixed in Validation: build 212 files; check passes; full suite 668/668; focused checks 21/21. All 18 new test groups fail on detached main The next review found two further cases: same-line Git config section assignments and shell-text wrapper handling when a spaced executable filename exists. I am fixing both on this branch. The PR remains a draft, and both clean review cycles will restart after the repair. |
|
Follow-up repairs are pushed in
All reported cases failed before their repairs. The final watch regression table covers 64 cases, including permitted neighboring cases. On Both clean review cycles restart on |
|
Cycle 1 on
The findings used fake files and parser or hook JSON input. Git was used only as a configuration reader; no alias or attack payload executed. The repair will preserve executable identity evidence separately from the leaf-program view and keep each wrapper interpretation local. Both clean review cycles must restart after repair. The PR remains a draft. |
|
The executable-evidence and native Git subsection repairs are in Validation on this commit: build 212 files; check passes; full suite 671/671; focused checks 24/24. All 21 new test groups fail on detached main Cycle 1 found two integration gaps: native shell modifiers change to argv mode too early, and nested env split-string commands do not reach all alias/copy/stash/process checks. The repair will use one semantic traversal with separate wrapper and leaf views for the rule consumers. These findings used parser/JSON inputs only; no payload executed. The PR remains a draft and both review cycles must restart after repair. |
|
The wrapper-boundary finding is repaired in Build and check pass; the full suite passes 674/674. All 24 T197 groups fail on detached main with only the test file copied. The restarted QA review found a separate package-runner gap: |
|
Repaired the option-parsing findings in
The implementation follows a 66-case parser check using npm 11.19.1 and nopt 9.0.0; no payload executed. The initial three regression groups and later grammar cases failed before their repairs. All 27 T197 groups fail on detached main with only the final test file copied. Build: 212 files. Check: all checks pass. Full suite: 677 tests, 677 pass, zero failures or skips. Focused suite: 38/38. All test runs used fake process tools first on PATH. Code/security and QA cycle 1 have restarted on the exact revision. This PR remains draft until two clean cycles and CI pass. |
|
The attached-flag, whitespace-call, negated-alias, and npx normalization findings are repaired in Build: 212 files. Check passes. Full suite: 678/678. Focused suite: 39/39. Detached-main proof: 28 tests, 0 pass, 28 fail, with only the final test file copied. Test runs use fake process tools and never execute submitted command strings. QA cycle 1 is clean: 50 focused groups pass, and 71 comparable native-parser cases match. Code/security found one remaining delimiter gap in unregistered option values ( |
|
The delimiter finding is repaired in Build: 212 files. Check passes. Full suite: 679/679, zero failures or skips. Focused suite: 40/40. Detached-main proof: 29 tests, 0 pass, 29 fail, with only the final test file copied. All tests used fake process tools and no submitted command executed. Code/security and QA cycle 1 are clean on this exact revision. Independent evidence includes 51 QA groups and native parser checks for delimiter and typed-call behavior. Cycle 2 has started on the unchanged commit, with the reviewers exchanging roles. The PR remains draft until that cycle and CI pass. |
|
The cycle 2 alias-destination finding is repaired in Validation: build 212 files; check passed; focused 101/101; full suite 681/681, no skips. The exact final test file on detached main gives 31/31 failing new groups. The initial repair regressions recorded 11 native and 10 shell bypasses before the fix. A separate inert cp-to-gcp probe also failed before its correction. An intermediate run found a refusal-message regression, which was corrected without changing existing assertions. Its local HTTPS fixture also failed because sandbox loopback binding was denied; direct binding checks confirmed the cause. The final full run used the required loopback-capable environment. No submitted payload ran. Both review cycles restart on this commit. Cycle 1 code/security and QA are underway; the PR stays draft. |
|
The two cycle 1 findings are repaired in Validation: build 212 files; check passed; focused 103/103; full suite 683/683, no skips. The exact final test file on detached main gives 33/33 failing new groups. The saved independent security matrix changed from 12 mismatches in 18 cases to 18/18 passing. All submitted command strings remained parser/hook data. Code/security and QA cycle 1 have restarted on this exact commit. The PR remains draft until two clean cycles pass. |
|
Repair in
Validation: build produced 212 files; check passed; full suite passed 687/687; focused compatibility passed 107/107. All 37 T197 test groups fail by assertion on detached main, using the exact final test file. Four new groups also failed before this repair. Tests used fake process tools and inert fixtures; no submitted command payload ran. Cycle 1 confirmed the prior cases pass, but found remaining CDPATH context gaps in called functions and env reset handling. The bounded review batch is still in progress. The PR stays in draft pending two clean cycles and CI. |
|
Repair in
Build produced 212 files; check passed; full tests passed 690/690; focused tests passed 110/110. The exact final 40 T197 test groups all fail by assertion on detached main. All tests used fake process tools; submitted payloads remained parser/hook input. Cycle 1 confirms the prior 17-case review matrix passes, but found remaining export-removal/unset and function-shadowing gaps. QA is still active. The PR remains a draft pending repairs, two clean cycles, and CI. |
|
Repair in
Build produced 212 files; check passed; full tests passed 692/692; focused tests passed 112/112. All 42 final T197 groups fail by assertion on detached main. The saved 12-case review matrix now has zero mismatches. Tests used fake process tools; submitted payloads stayed parser/hook input. Cycle 1 QA is clean on this commit. Code/security review remains active; two complete clean cycles and CI are required before this draft becomes ready. |
|
Repair in Build produced 212 files; check passed; full tests passed 694/694; focused tests passed 114/114. All 44 final T197 groups fail by assertion on detached main. The saved ten-case review matrix now has zero mismatches. Tests used fake process tools; submitted payloads stayed parser/hook input. Cycle 1 code/security found a remaining stale summary when a called function is redefined after its caller was defined. QA is still active. This PR stays in draft pending repair, two clean cycles, and CI. |
|
Fixed the stale callee-binding finding in Function calls now resolve effects against current definitions. Called-body policy evidence remains visible; known function calls retain gh-name and body checks. Recursive analysis stops at a fixed depth. Validation: build produced 212 files; check passed; full suite passed 696/696 with no failures or skips. The independent eight-case reproduction passes all eight cases. All 46 new T197 test groups fail by assertion on detached main Two clean independent review cycles remain required on this commit. Review agents reached the account usage limit, so those cycles have not run. The PR stays draft. CI on this new commit is pending; no merge requested. |
|
Fixed the forward-definition false refusal in The reader now resolves provisional evidence by its parsed call position. A known call does not clear a later unknown call or a call in another scope. Explicit gh names and protected function bodies remain checked. Validation: build 212 files; check passed; targeted 6/6; focused 117/117; full suite 697/697 with no failures or skips. The independent four-case reproduction now passes all four cases. The exact final test file fails all 47 T197 groups by assertion on detached main Security and QA have restarted cycle 1 on this commit. Two clean cycles and CI are still required; the PR remains draft. |
|
Fixed the derived-dispatch false refusals in The reader now ties wrapper and shell argument interpretation to the command that owns it. Resolving that command to a function removes its obsolete synthetic evidence. Known functions do not apply shell-text or find-exec rules to literal argument data. Real dispatch, substitutions, caller redirections, and protected bodies remain checked. The gh write check uses the surviving scoped commands and redirects; T83 is unchanged. Validation: build 212 files; check passed; targeted 7/7; focused 118/118; full suite 698/698, no failures or skips. Root replayed both independent matrices: 13/13 and 17/17. The exact final test file fails all 48 T197 groups by assertion on detached main Code/security and QA have restarted cycle 1 on this commit. Two clean cycles and CI remain required. The PR stays draft. |
|
Fixed the copy/source operand and provisional-error findings in The hook uses one surviving non-function dispatch list for program-specific checks, including copy destinations, aliases, source paths, and export operands. Declaration-only interpretation errors remain attached to their owning parsed call site. Only a confirmed function at that site can retire the error; real, unresolved, and bypassed commands still refuse. Validation: build 212 files; check passed; targeted 9/9; focused 120/120; full suite 700/700, no failures or skips. Root independently replayed both matrices: 10/10 and 9/9. The exact final test file fails all 50 T197 groups by assertion on detached main Code/security and QA have restarted cycle 1 on this commit. Two clean cycles and CI remain required. The PR stays draft. |
|
Ready for owner review and merge at
The PR body records scope and limits. No payload command, real gh fixture, or real process utility executed in tests. Native PowerShell and a live authenticated GitHub session remain unverified. This is static hook enforcement, not complete automatic Codex lifecycle verification. No merge was performed. The next implementation is #58 after this PR merges, per the agreed order. |
Closes #70
Sage task T197
Agent commands can hide gh behind a copied executable, a link, a wrapper, or an alias. The hook now checks executable identity before wrapper interpretation and refuses visible copy and alias setup.
Agents retain plain
gh pr create,view,comment,edit,checks,gh issue view, and GET-onlygh api. Other resolved gh forms are refused. The refusal lists the permitted forms. The main session keeps its existing rules.Scope
packages/sage-claude/hooks/sage-hook.mjs.packages/sage-core/command-reader.mjsproduces command leaves and executable evidence from one traversal. Wrapper identities, quoting, PATH, working folders, and wrapper-owned options remain available to the rules. Copies, aliases, stash, and process checks use the same interpreted command leaves.Validation
Validation on
d1f2571:npm run buildbuilt 212 filesnpm run checkall checks passnpm testtests 700; pass 700; fail 0; cancelled 0; skipped 0git diff --checkEvery test command used fake ps, pgrep, and kill first on PATH and ran under
caffeinate -i. Fixtures contain fake executable files. Submitted command strings went only to parsers and hook JSON. No real GitHub command, process inspection, or attack payload ran. Git was used only as a configuration reader in the alias syntax probes.Detached-main proof uses
git worktree add --detach <scratch> origin/main, ata033102, with only the updated hook test file copied in.node --test --test-name-pattern=T197 scripts/sage-hook.test.mjs:tests 50; pass 0; fail 50. Review regressions also have failing evidence against the commits that preceded their repairs. Paired assertions cover permitted commands and ordinary data arguments.Risk flag: auth. All program-specific operand checks now use the surviving external dispatch evidence. Known function arguments do not become copy, alias, source, or export operands. Provisional declaration errors follow their owning call position and clear only when that same position resolves to a function. Actual, unresolved, and bypassed commands retain their checks.
Independent repair matrices pass 10/10 and 9/9. Targeted tests pass 9/9; focused hook/provider tests pass 120/120. CI passed on
d1f2571. Both code/security and QA completed two clean review cycles on the unchanged commitd1f2571226234a7fbae5cedd83e47f75d878417a. No actionable finding remains within the issue and repaired behavior reviewed. The PR is ready for the owner’s review and merge.Independent reviews
Both cycles reviewed the same final commit. Payload strings went only to parsers and hook JSON.
The second cycle checked the original issue acceptance: permitted plain forms, API write refusals, executable identities, copies and aliases, main-session controls, and the repaired function boundaries. Existing assertions remain unchanged, generated copies match sources, and the final worktree is clean.
Not verified
This is static hook enforcement, not an operating-system sandbox. It does not prove detection of a preexisting renamed physical copy with a different inode, arbitrary executable scripts, encoded program construction, or changes outside the observed tools. Reader options that launch programs remain tracked separately in #58. Native PowerShell execution and a live authenticated GitHub session were not used in tests. This Claude hook change does not establish complete automatic Codex lifecycle enforcement.