Skip to content

fix(system): grep -- argument boundary; tree/find path fixes (#111 G5) - #112

Merged
thehoff merged 1 commit into
developfrom
fix/g5-audit-111
May 20, 2026
Merged

thehoff merged 1 commit into
developfrom
fix/g5-audit-111

Conversation

@thehoff

@thehoff thehoff commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes the G5 findings from the independent Claude review (#111). Codex-reviewed: mergeable.

Findings fixed

Sev Fix
CRITICAL grep_cmd.rs had no -- argument boundary — a --pre=<cmd>-shaped pattern reached rg as a flag, unscanned (check_forbidden_rg_args only scans extra_args). rg --pre runs an arbitrary preprocessor command (RCE). The ls/tree siblings got the -- boundary in #100; grep was missed. Now the rg argv is fixed flags → optional --type → forbidden-checked extra_args → "--" → pattern → path. The plain-grep fallback got the identical treatment.
IMPORTANT tree -o verified a real option (-o file = output to file) — kept in VALUE_FLAGS, splitter extracted to split_flags_and_paths() for testability.
IMPORTANT find_cmd.rs — walk_root strips a trailing slash so strip_prefix reliably yields relative paths instead of falling back to absolute.

Test plan

  • cargo test --workspace — 2347 lib tests pass, 0 fail; system_hardening 4/4
  • New tests: --pre=-shaped pattern never executes (marker-file PoC), --leading path searched correctly, tree splitter, find trailing-slash
  • cargo build --release clean
  • Codex review — mergeable

Part of the #111 audit.

🤖 Generated with Claude Code

…fixes (#111 G5)

grep_cmd.rs (CRITICAL): the rg/grep argv placed pattern and path with no
`--` separator, so a pattern shaped like `--pre=<cmd>` reached rg unscanned
and ran an arbitrary preprocessor (RCE, #32). Restructure both the rg path
and the plain-grep fallback as: fixed flags, then forbidden-checked
extra_args, then `--`, then pattern, then path. Mirrors the #100 G5#1/#2
boundary already in ls.rs/tree.rs.

tree.rs: confirmed `-o filename` is genuine native tree (v2.x) output-file
flag — kept in VALUE_FLAGS with a clarifying comment; extracted the
flag/path splitter into a testable helper.

find_cmd.rs: a trailing slash on the search root made strip_prefix fail and
emit absolute paths, breaking the relative-path contract. Normalise the
walk root (strip trailing slash) before walking and stripping.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thehoff
thehoff merged commit 5c143b6 into develop May 20, 2026
4 checks passed
@thehoff
thehoff deleted the fix/g5-audit-111 branch May 20, 2026 10:39
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