Skip to content

Check PowerShell and every command input field (T196) - #85

Merged
erickb336 merged 1 commit into
mainfrom
codex/t196-powershell-inputs
Oct 8, 2026
Merged

erickb336 merged 1 commit into
mainfrom
codex/t196-powershell-inputs

Conversation

@erickb336

@erickb336 erickb336 commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Closes #69
Sage task T196

The hook now checks merge and push commands in every string field, including nested inputs. Terminal commands use the tool's working directory for the check that refuses pushes from main.

For PowerShell, the hook refuses backticks or parentheses when the text names gh, git, pr, merge, or push. It removes backticks only for word detection. This conservative choice avoids treating PowerShell expansion as Bash syntax. Plain commands and ordinary unprotected expressions retain their behavior.

The change lives in packages/sage-claude/hooks/sage-hook.mjs; shared core policy APIs are unchanged. The plugin hook is regenerated by the build.

Review repairs

Initial review found two issues, both reproduced before repair:

  • Deeply nested input could break the error handler. Field extraction now has a guarded fallback that refuses unreadable command input.
  • Multiple first-upload commands could show an approval for the wrong target. The hook now refuses multiple candidates before any GitHub lookup, deduplicates repeated text, and lets a refusal in another field take precedence.

Two clean code/security and QA cycles passed on 92618e4c27ad4fa739fcf032b12335d50694cdb3 after the repairs. Cycle 2 used a different code/security reviewer and independently reran all seven T196 groups. No commit followed either clean cycle.

Validation

Fake ps, pgrep, and kill were first on PATH for every test. First-upload tests used fake gh responses. Attack strings reached only hook JSON inputs; no test ran a real merge, push, or attack command.

Command Result
npm run build built 212 files
npm run check all checks pass
node --test --test-name-pattern=T196 scripts/sage-hook.test.mjs 7 tests; 7 pass; 0 fail
npm test 650 tests; 650 pass; 0 fail; 0 skipped
git diff --check exit 0

On detached main 86c8b2f, only the updated hook test file was copied over. The same T196 command ran all seven new named tests: 0 pass, 7 fail. They cover the main session and an agent, the three reported PowerShell forms, nested fields, terminal directory selection, and first-upload approval ambiguity. Existing test assertions are unchanged.

Not verified / seen, not fixed

No live Claude session, native PowerShell execution, or real GitHub write was tested. This task does not provide a complete PowerShell parser. Existing agent parsing can still reject escaped-quote PowerShell text; that behavior predates this change. The existing SDK dependency advisory is unchanged.

@erickb336 erickb336 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex review result for 92618e4c27ad4fa739fcf032b12335d50694cdb3: two clean cycles.

Cycle Code/security QA
1 No remaining findings after nested-input and approval-target repairs 7/7 T196 tests and 5/5 adjacent regressions; generated hook matches source
2 Different reviewer independently traced all-field handling, PowerShell rules, terminal cwd, fallback refusal, and approval precedence; no findings Independently ran 7/7 T196 tests; checked exact main-red names and both before-fix regression failures

Both cycles reviewed this same commit. Full suite: 650 pass, 0 fail. On detached main 86c8b2f, all seven new named tests fail with only the test file copied over. Existing assertions are unchanged. No native PowerShell execution or real GitHub write was performed; limitations remain in the PR body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

T196: Hook reads PowerShell by its own rules and every field of a command tool

1 participant