Skip to content

harden(jvm/go/dotnet): _JAVA_OPTIONS strip, binlog OOM cap, dotnet exit-code authority (#100 G6) - #105

Merged
thehoff merged 2 commits into
developfrom
harden/g6-audit-100
May 20, 2026
Merged

thehoff merged 2 commits into
developfrom
harden/g6-audit-100

Conversation

@thehoff

@thehoff thehoff commented May 20, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes the G6 (python/ruby/go/jvm/dotnet filters) findings from audit #100. Codex-reviewed; review follow-ups applied.

Findings fixed

Sev Fix
CRITICAL core/utils.rs — _JAVA_OPTIONS (a distinct undocumented HotSpot var that injects JVM args = code-exec) added to JVM_DANGEROUS_ENVS. The G1 audit pass wrongly reported this as already covered — it was not.
CRITICAL cmds/dotnet/binlog.rs, dotnet_trx.rs — .binlog/.trx read with a 256 MiB cap (read_capped); the decompressed binlog payload also hard-bounded via Read::take — gzip-bomb defence (a tiny file inflating to GB).
CRITICAL cmds/dotnet/dotnet_cmd.rs — build success was inferred from English text (Build succeeded) and normalize_build_summary never reset succeeded to false; a non-zero exit could render ok. Process exit code is now authoritative.
IMPORTANT core/utils.rs — GOENV added to GO_DANGEROUS_ENVS (it points go at an alt env config file that can set GOFLAGS/GOPROXY/CC).
IMPORTANT core/utils.rs — secure_cargo_command() sets CARGO_TERM_COLOR=never (env-side companion to the cargo ANSI fix).
IMPORTANT pytest/rspec/rubocop — ANSI stripped before failure-pattern matching (coloured failure markers no longer evade detection).
IMPORTANT cmds/go/golangci_cmd.rs — find_subcommand_index bails to passthrough on an unrecognised global flag instead of mis-parsing/dropping values.
NICE rtk_dotnet_* temp prefixes → contextcrawler_dotnet_*.

Codex review follow-up (e996566)

  • Added spawn-and-verify tests for _JAVA_OPTIONS/GOENV (build the real hardened command, spawn a child, assert the var is absent from its environment) — the original tests were structural list-checks.
  • ANSI display concern assessed: the pytest/rspec/rubocop filters emit a fully synthesised compact summary (never echo the tool's coloured lines), so the strip touches only the matcher input — no user-visible colour regression. Documented at each site.

Test plan

  • cargo test --workspace — 2307 pass, 0 fail
  • cargo build --release clean
  • Codex review — security fixes verified PASS; both review follow-ups (spawn tests, ANSI assessment) applied

Part of the #100 audit.

🤖 Generated with Claude Code

thehoff and others added 2 commits May 20, 2026 18:43
… G6)

Addresses the G6 group of the full-codebase audit in issue #100.

CRITICAL 1 — JVM env strip missing _JAVA_OPTIONS:
  core/utils.rs JVM_DANGEROUS_ENVS gained "_JAVA_OPTIONS", the distinct
  undocumented HotSpot var that prepends JVM args at startup (a code-exec
  vector separate from JAVA_OPTS / JAVA_TOOL_OPTIONS). Unit test
  jvm_command_lists_cover_known_vectors extended; added
  secure_jvm_command_strips_underscore_java_options asserting it is
  env_remove()'d from the spawned child of every JVM builder.

CRITICAL 2 — unbounded .binlog/.trx reads:
  binlog.rs gained MAX_ARTIFACT_BYTES (256 MiB) and read_capped(), which
  rejects oversize files from filesystem metadata BEFORE allocating. The
  binlog gzip payload is also capped via Read::take (gzip-bomb defence:
  a tiny file can inflate to gigabytes). dotnet_trx.rs gained
  read_trx_capped() applied to both read sites. Tests added for oversize
  rejection and within-cap acceptance.

CRITICAL 3 — dotnet build success inferred from English text:
  normalize_build_summary now treats the process exit code as
  authoritative: a non-zero exit forces succeeded=false, overriding any
  "Build succeeded" / "0 Warning(s) 0 Error(s)" text marker the binlog
  parser may have set. Regression test confirms the verdict renders
  "fail", never "ok", on a non-zero exit.

IMPORTANT 4 — GOENV missing from GO_DANGEROUS_ENVS:
  GOENV points `go` at an alternate env config file that can set
  GOFLAGS/GOPROXY/CC — an indirect path to every Go vector already
  stripped. Added; test list extended; child-env strip test added.

IMPORTANT 5 — cargo ANSI env companion:
  secure_cargo_command() now sets CARGO_TERM_COLOR=never so cargo output
  is never ANSI-coloured (env-side companion to the G5 cargo ANSI fix).
  Test secure_cargo_command_forces_term_color_never added.

IMPORTANT 6 — failure-pattern matching on un-stripped stdout:
  pytest/rspec/rubocop filters strip ANSI before the matching state
  machine, so colour codes wrapping failure markers can no longer evade
  detection. ANSI-wrapped-failure regression tests added for all three.

IMPORTANT 7 — golangci global-flag mis-parse:
  find_subcommand_index now bails to Passthrough on an unrecognised
  global flag rather than guessing whether it consumes the next arg —
  a wrong guess could misclassify the real subcommand. Added a
  GLOBAL_BOOL_FLAGS table so known boolean flags are still recognised.
  Regression test added.

IMPORTANT 8 — temp-file branding:
  dotnet temp prefixes rtk_dotnet_* renamed to contextcrawler_dotnet_*;
  the now-dead branding_lint exemption removed.

cargo test --workspace: 2305 passed, 6 ignored. cargo build --release
clean, no new warnings.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Codex-review follow-up for the G6 portion of #100.

Finding 1 — env-strip tests were structural only:
  The G6 commit asserted _JAVA_OPTIONS / GOENV appear in
  removed_env_names(&secure_*_command(...)) — it inspected
  Command::get_envs() but never confirmed the var is absent from a
  real child's environment. Added two spawn-and-verify unit tests
  (secure_jvm_command_strips_underscore_java_options_in_child,
  secure_go_command_strips_goenv_in_child): each sets the var in the
  process env, builds the command via the real secure_*_command
  builder pointed at /usr/bin/env (which resolves an absolute path to
  itself, yielding a genuine hardened spawnable Command), spawns it,
  and asserts the var is genuinely absent from the child's printed
  environment. Mirrors the spawn-and-verify model of
  tests/runtime_hardening.rs / tests/cargo_hardening.rs.

Finding 2 — ANSI strip and user-facing colour: assessed, no
  regression. pytest/rspec/rubocop filters all emit a fully
  synthesised compact summary (build_pytest_summary /
  build_rspec_summary / filter_rubocop_{json,text}) and never echo
  the tool's original lines verbatim — the tool's TTY colour was
  already discarded by the reformatting before the G6 strip was
  added. Stripping ANSI only affects the matcher's input; there is
  no original colour left to preserve, so no split matcher/display
  paths are warranted. Documented the no-regression rationale in a
  code comment at each of the three strip sites.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thehoff
thehoff merged commit ed050cb into develop May 20, 2026
4 checks passed
@thehoff
thehoff deleted the harden/g6-audit-100 branch May 20, 2026 08:58
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