Skip to content

fix: Git output decoding, PowerShell hook conditions and shared verifier redaction (#260 follow-ups) - #312

Merged
rng1995 merged 5 commits into
mainfrom
naren/fix-260-followups
Nov 2, 2026
Merged

rng1995 merged 5 commits into
mainfrom
naren/fix-260-followups

Conversation

@rng1995

@rng1995 rng1995 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR fixes three of the items listed under "Not in this PR" in #260. A fourth item from that list, the "unused" pruned-folder walk in plugin_paths.py, is dropped: plugin_inventory.py has called _pruned_folder_findings since #257, so the walk is in use. The credential redaction item was done separately in #301.

Area Problem Change
Git output decoding (utils/helpers.py) resolve_git_root and resolve_git_remote_url ran git with text=True and no encoding. On a Windows host with the cp1252 code page, a repository in a non-ASCII folder resolved to a path that does not exist (café became café), or the call raised an uncaught UnicodeDecodeError. Both helpers feed the SARIF repository root and the plugin dependency lookups. All four git calls go through a new _git_output helper that decodes as UTF-8. The repository root uses errors="surrogateescape", so path bytes that are not valid UTF-8 still name the real directory. Remote URLs and branch names use errors="replace", because they are written to UTF-8 reports. Neither setting can raise.
PowerShell hook conditions (plugin_component_risk.py) _condition_scope rewrote every shell-tool hook if condition as a Bash rule before classifying it. PowerShell(iex *), PowerShell(pwsh *), cmd.exe and start-process were then read as narrow Bash rules, so an auto-approve PreToolUse hook scoped to them got no finding. The condition keeps its PowerShell tool (any spelling). Other shell-tool names, such as Cursor Shell and Codex exec_command, are still read as Bash. These hooks are now reported HIGH.
PowerShell grant wording (plugin_component_risk.py, plugin_inventory.py) Findings for a flagged PowerShell grant suggested Bash(git status *) or "deny Bash". A subagent's PowerShell grant was hidden by disallowedTools: Bash. Inert grants in skills or commands that only Codex loads always said "unrestricted 'Bash'". Suggestions and the deny advice name the grant's own tool. denies_every_bash_command takes an optional tool (default "Bash"), and the subagent check applies the deny per grant. disallowedTools: Bash no longer hides a PowerShell grant (now LOW, advisory). Inert-grant messages quote the actual grant and tool. Bash-only cases are unchanged.
Verifier redaction copy (tier3/harbor/templates/eval.py) The verifier template kept its own copy of the LOG_* patterns and redact_secrets_in_log_line, plus an unused _GLUED_KEY_BODY alias, although _copy_verifier already stages secret_redaction.py next to it. The template uses the shared function (_shared_checks.redact_secrets_in_log_line) and drops the copy (41 lines). The pattern drift-guard tests become one identity test. The Python 3.9 smoke now asserts that the staged verifier uses the staged secret_redaction function.

The plugin analysis changes are in private code that the public CLI does not call yet, so they have no CHANGELOG entry. The Git decoding fix has one under Fixed.

Testing

Check Result
New regression tests on main, before the fix Git decoding: 4 failed. PowerShell conditions and wording: 9 failed (the 6 controls for unchanged behaviour pass). Verifier identity: 1 failed.
Same tests with the fix All pass.
Redaction equivalence before removing the copy 600,000 generated lines in a staged flat verifier on Python 3.9 gave identical output from the template copy and the shared function. Changing one quantifier in any shared pattern was detected. A separate random corpus of 40,000 lines also gave 0 mismatches.
Real-locale repro (no monkeypatching) LC_ALL=en_US.ISO8859-1, repository under café-skills: main returns a path that does not exist; this branch returns the real root.
scripts/ci/smoke_harbor_verifier.py --python 3.9.6 Pass, overall reward 1.0.
Targeted suites: utils, validators, plugin inventory, discovery and markdown, commands, CI, tier3 redaction and staging 4,582 passed, 7 skipped.
ruff check and ruff format --check on changed files Clean.
Gitleaks, full history No leaks.

The new tests force cp1252 decoding by wrapping subprocess.check_output, so they run on every OS. The raw 0xff path-byte case is POSIX-only and is skipped on Windows.

🤖 Generated with Claude Code

rng1995 and others added 5 commits November 2, 2026 00:57
resolve_git_root and resolve_git_remote_url decoded git's UTF-8 output with
the locale code page, so on a cp1252 Windows host a repository under a
non-ASCII folder resolved to a garbled path or raised an uncaught
UnicodeDecodeError. All git calls now decode as UTF-8, keeping path bytes
losslessly with surrogateescape and replacing bad bytes in URLs and refs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[email protected]>
A hook 'if' condition such as PowerShell(iex *) was rewritten to a Bash rule, so its launcher looked narrow and an auto-approve hook went unreported; the condition now keeps its own tool. Skill, command, and subagent findings for a flagged PowerShell grant now suggest a scoped PowerShell rule, and a subagent's PowerShell grant is no longer hidden by disallowedTools: Bash.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[email protected]>
A skill or command that only Codex loads had its shell grant reworded as unrestricted 'Bash' with "it has no Bash tool", even for a PowerShell(iex *) grant. The finding now keeps the grant and tool the component analysis named.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[email protected]>
The verifier template kept its own copy of the LOG_* patterns and
redact_secrets_in_log_line although _copy_verifier stages secret_redaction.py
beside it and checks.py already imports that function. The template now
aliases the shared function, and the drift-guard tests become one identity test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Narendran Raghavan <[email protected]>
The Python 3.9 verifier smoke now asserts that the staged verifier uses the shared secret_redaction function. The JWT redaction test no longer runs every case twice against the same function, and the CHANGELOG notes the Windows Git output decoding fix.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rng1995
rng1995 merged commit b6e5d49 into main Nov 2, 2026
21 checks passed
@rng1995
rng1995 deleted the naren/fix-260-followups branch November 2, 2026 19:08
rng1995 added a commit that referenced this pull request Nov 2, 2026
…gs (#312 review) (#320)

* fix(utils): decode every Git repository root as a file name

Git prints the repository root as raw file-name bytes, so resolve_git_root, find_git_repo_root and git_root_for now decode it with os.fsdecode instead of UTF-8 or the locale code page. This keeps non-ASCII roots correct on Windows and on Linux hosts with a non-UTF-8 locale; remote URLs and branch names stay UTF-8.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(plugin): keep the Bash reading of PowerShell hook conditions

A PowerShell if condition is now broad when either its PowerShell or its Bash reading is, so prefixes every shell runs, such as PowerShell(sudo *) and PowerShell(env *), keep their HIGH auto-approve finding.

Signed-off-by: Narendran Raghavan <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Signed-off-by: Narendran Raghavan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant