Skip to content

harden(cloud/git): curl/wget flag-injection gate + git exit-code propagation (#100 G4) - #107

Merged
thehoff merged 3 commits into
developfrom
harden/g4-audit-100
May 20, 2026
Merged

thehoff merged 3 commits into
developfrom
harden/g4-audit-100

Conversation

@thehoff

@thehoff thehoff commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes the G4 (git + cloud command filters) findings from audit #100 — 2 CRITICAL flag-injection holes. Codex-reviewed across 3 passes; final review: closed, mergeable.

Findings fixed

Sev Fix
CRITICAL curl -K/--config deny-list bypass. The check now normalises every arg — short-flag char-scan (catches -Kfile attached value, -sK bundling), =-split for long flags, AND prefix-match for abbreviated long options (--conf=file invokes --config via getopt_long prefix-matching).
CRITICAL wget gate missed --output-document/-O, --input-file/-i, --load-cookies entirely — all now in the deny-list, all forms (attached, bundled, abbreviated).
IMPORTANT psql verbose log scrubbed via scrub_secrets (DSN passwords no longer logged).
IMPORTANT git run_status/run_stash/run_worktree propagated git's exit code — a non-zero exit was being absorbed into filtered output as apparent success.
IMPORTANT git diff_cmd.rs normalize_diff_args — ambiguous-tail check before -- injection.
IMPORTANT gt run_other keeps OsStr end-to-end (non-UTF-8 branch names no longer mangled).
— false-positive fix: a forbidden flag appearing as a value (curl --data -K) or after -- is no longer wrongly rejected (value-flag tracking + operands_only).
NICE rtk → contextcrawler in git diff hint + docker/kubectl banners.

Review history

3 Codex passes: pass 1 caught the attached-value/bundling bypass; pass 2 caught the abbreviated-long-option bypass + the value-flag false positive; pass 3 verified all closed — every short/long/attached/bundled/abbreviated form of a forbidden flag is rejected, no false positive remains, look-ahead is bounds-safe.

Test plan

  • cargo test --workspace — 2318 pass, 0 fail; cloud_hardening 20 pass
  • cargo build --release clean
  • Codex review ×3 — final verdict: closed, mergeable

Part of the #100 audit.

🤖 Generated with Claude Code

thehoff and others added 3 commits May 20, 2026 18:41
Audit group G4 from the full-codebase audit (#100): two CRITICAL
flag-injection holes plus exit-code, secret-leak and lossy-conversion
findings in the git and cloud command filters.

CRITICAL 1 — curl attached-value flag injection (curl_cmd / utils):
the deny-list matched `-K` / `--config` as bare tokens but not the
attached-value form `-K=file` / `--config=file`, which curl accepts.
Added `option_key()` to normalise each arg (strip dashes, split on `=`,
take the key) before the deny check; `-K=file` and `--config=file` are
now rejected.

CRITICAL 2 — wget unguarded file read/write flags (wget_cmd / utils):
the gate did not block `--output-document` / `-O` (arbitrary file
overwrite), `--input-file` / `-i` (arbitrary file read), or
`--load-cookies` (cookie-theft pivot) in any form. Added all three to
the deny-list with the same attached-value normalisation; bare,
space-separated and `=`-attached shapes all rejected.

IMPORTANT 3 — psql DSN password leak: verbose mode logged the raw psql
argv, which can carry a DSN with an inline password. The verbose log
now runs the argv through `scrub_secrets` first.

IMPORTANT 4 — git diff `--` mis-placement: `normalize_diff_args` could
demote a revision to a pathspec on unusual arg ordering. Added a
defensive ordering check — if any arg after the path-start still looks
like a revision, skip injection and let git resolve the args.

IMPORTANT 5 — git exit code absorbed: `run_status` (compact),
`run_stash` (list/show) and `run_worktree` (list) applied the output
filter before checking git's exit code, so a non-zero git exit was
swallowed. All three now check `result.success()` and propagate the
real exit code with raw output on failure.

IMPORTANT 6 — gt non-UTF-8 arg mangling: `run_other` did
`to_string_lossy()` on all args before forwarding unknown `gt`
subcommands to git. The passthrough path now keeps `OsStr`/`OsString`
end-to-end; only the recognised-subcommand branches stringify.

NICE 7/8 — rebrand stale `rtk` strings to `contextcrawler` in the git
diff-truncation hint and the docker/kubectl logs usage banners; pruned
the now-dead branding-lint allowlist entries.

Tests: curl `-K=file`/`--config=file` rejection, wget `-O`/`-i`/
`--load-cookies` rejection in every shape, psql DSN scrubbing, and git
exit-code propagation for status/stash/worktree. cargo test --workspace
2309 passed, 6 ignored; release build clean, no new warnings.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…value bypass + post-`--` false positive

The first G4/#100 fix added `option_key()`, which only stripped a leading
dash and split on `=`. It missed two short-flag bypass shapes:

- attached short values: `-Kfile` (curl), `-Ofile` (wget) — value attached
  with no `=` and no space; `option_key` returned `Kfile`, never matched.
- short-flag bundling: `-sK` / `-sKfile` — curl/wget bundle short flags,
  so `-sK` means `-s` then `-K`; `option_key` returned `sK`.

Replace `option_key` with two helpers:
- `long_option_key` — long flags only (`--config[=file]`), `=`-split key.
- `short_token_has_forbidden` — char-scans a single-dash token; any
  forbidden short flag anywhere in the bundle rejects. Conservative and
  correct because forbidden short flags (`K`; `O`/`i`/`e`) are value-taking,
  so the trailing chars are an opaque value once one is hit.

Also fix a false positive: the check was context-free, so a literal `-K`
operand after a `--` separator was wrongly rejected. Both curl and wget
checks are now separator-aware — a bare `--` stops the flag check.

Tests cover every bypass (`-Kfile`, `-sK`, `-sKfile`, `-Ofile`, `-iurls.txt`,
`-qO`), the post-`--` false positive, and a benign bundle (`-sL`).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ss + value-flag false positive

Finding 1 (real bypass): curl/wget use GNU getopt_long, which accepts any
unambiguous prefix of a long option — `--conf=file` invokes `--config`,
`--out=x` invokes `--output-document`. The exact-match deny-list was bypassed
by every abbreviation. New `long_key_matches_forbidden` rejects a key when it
is a prefix of any forbidden long name (`F.starts_with(key)`); over-rejects
short ambiguous abbreviations, which is the safe direction.

Finding 2 (false positive): a `-`-looking VALUE of a separate-value flag
(`curl --data -K`) reached the short-flag scan and was wrongly rejected. Both
checkers now track value-consuming flags in their separate form and skip the
forbidden-flag scan for the immediately-following token. The attached form
(`--data=X`) does not consume the next token, so a real flag after it is
still scanned.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thehoff
thehoff merged commit 6ebad50 into develop May 20, 2026
4 checks passed
@thehoff
thehoff deleted the harden/g4-audit-100 branch May 20, 2026 09:05
noogalabs pushed a commit to noogalabs/contextcrawler that referenced this pull request Jun 4, 2026
…hoff#107)

Add token-optimized filtering for `cargo nextest` output: strip
compilation noise, PASS lines, and post-summary recaps; show only
failure details and a compact summary. Extract flush_failure_block
helper to DRY up failure block collection (was repeated 4 times).

Co-authored-by: Claude Opus 4.6 <[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