Skip to content

harden(python/ruby/jvm/dotnet/go): per-runtime secure_command + arg deny (#36) - #46

Merged
thehoff merged 1 commit into
developfrom
harden/pyrb-v2
May 18, 2026
Merged

thehoff merged 1 commit into
developfrom
harden/pyrb-v2

Conversation

@thehoff

@thehoff thehoff commented May 18, 2026

Copy link
Copy Markdown
Owner

Continuation of #45. Surgical rebase of agent-generated harden/pyrb-wip onto post-#44 develop. 23 unit + 12 integration tests, all passing. Closes #36.

…vm/dotnet/go (#36)

Continuation of #45. Surgical rebase of harden/pyrb-wip onto post-#44
develop. Adds secure_{python,ruby,jvm,dotnet,go}_command + 6 check_forbidden_*
helpers. Wired into all cmds/{python,ruby,jvm,dotnet,go}/*_cmd.rs.

23 unit + 12 integration tests. Total: 2100 pass.

looks_like_path is shared with PR #44; pyrb's stricter test variant
adjusted to match (bare-relative paths not denied; ./sub/path IS denied).

Closes #36

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thehoff
thehoff merged commit 3982124 into develop May 18, 2026
3 checks passed
@thehoff
thehoff deleted the harden/pyrb-v2 branch May 18, 2026 09:23
noogalabs pushed a commit to noogalabs/contextcrawler that referenced this pull request Jun 4, 2026
…psql/curl/wget (thehoff#38)

Continuation of thehoff#45. Surgical rebase of harden/cloud-wip onto post-thehoff#46
develop. Each cloud CLI has a config-file-driven exec primitive that
stripping the corresponding env vars closes:
- kubectl: KUBECONFIG (users[].user.exec credential plugins), KUBE_EDITOR,
  KUBECTL_EXTERNAL_DIFF, EDITOR, VISUAL, MANPAGER, PAGER
- docker: DOCKER_CONFIG (credsStore plugin), DOCKER_CLI_PLUGIN_EXTRA_DIRS,
  DOCKER_HOST, DOCKER_CONTEXT
- aws: AWS_CONFIG_FILE (credential_process = literal shell exec),
  AWS_SHARED_CREDENTIALS_FILE, AWS_PLUGIN_PATH
- psql: PSQLRC (\! shell escape), PSQL_HISTORY, PGSERVICEFILE, PGPASSFILE
- curl: CURL_HOME, wget: WGETRC

Per-tool arg deny: --kubeconfig + exec/port-forward/cp for kubectl,
--config for docker, --ca-bundle for aws, -K/--config + --output writes
to rc-files for curl, --execute/--use-askpass/--config for wget.

Wire-ins in src/cmds/cloud/{aws,psql,curl,wget,container}_cmd.rs.
main.rs::run_fallback also gated via cloud_fallback_hardening (load-
bearing because clap parse-failure on kubectl --kubeconfig otherwise
bypasses the Kubectl subcommand and spawns raw).

16 unit tests (secure_cloud_tests) + 14 integration tests
(tests/cloud_hardening.rs). Total: 2116 pass.

Closes thehoff#38

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
noogalabs pushed a commit to noogalabs/contextcrawler that referenced this pull request Jun 4, 2026
…n, plug 4 missed wire-ins

Pre-release codex+claude review of harden PRs thehoff#41-thehoff#47 surfaced 5
must-fix items before tagging v0.1.8. This is the consolidation PR.

## F8 (architectural) — UNIVERSAL_ENV_STRIP was documentation-only

`secure_command_with_policy` applied the universal list, but the 15
per-tool secure_*_command helpers (added by thehoff#42/thehoff#43/thehoff#44/thehoff#46/thehoff#47)
called only `resolved_command(name)` + their OWN env_strip list. So
LD_PRELOAD, DYLD_INSERT_LIBRARIES, BASH_ENV, BASH_FUNC_*,
PROMPT_COMMAND, PERL5OPT, LUA_INIT etc. were NEVER stripped from any
wrapped tool — the headline claim of PR thehoff#41 was unfulfilled.

Fix: extract `apply_universal_env_strip(&mut cmd)` from
`secure_command_with_policy` and call it as the first step of every
per-tool helper (rg, git, cargo, node, python, ruby, jvm, dotnet, go,
kubectl, docker, aws, psql, curl, wget — 15 sites).

## F9 (unsoundness) — `unsafe { env::remove_var }` race in fallback

`cloud_fallback_hardening` (main.rs) called `unsafe { env::remove_var }`
with a SAFETY note claiming "single-threaded at CLI dispatch". False:
`maybe_ping()` at the top of `run_cli` spawns a telemetry thread
BEFORE this dispatch point, and that thread calls `std::env::vars()`.
Per Rust 1.81+ `env::remove_var` contract that's UB.

Fix: drop the env mutation entirely. The per-tool secure_*_command
helpers wired into every Commands::* dispatch path already strip env
via the safe Command::env_remove method. The fallback path is rare
(only fires on clap parse failure) and an unhardened fallback is an
accepted residual surface — tracked in a follow-up if it matters.

## F1, F2, F4, F5 — missed wire-ins

- F1 `src/cmds/system/format_cmd.rs:77` — `"black" | "ruff"` formatters
  switched from raw `resolved_command` to `secure_python_command`.
- F2 `src/cmds/js/lint_cmd.rs:102` — python linter path switched to
  `secure_python_command`.
- F4 `src/core/utils.rs::ruby_exec` — bundler branch (`Command::new("bundle")`)
  switched to `secure_ruby_command("bundle")`.
- F5 `src/core/utils.rs::package_manager_exec` — all four branches
  (`pnpm`, `yarn`, `npx`, direct-tool) switched from `resolved_command`
  to `secure_node_command`. This transparently hardens prettier_cmd,
  vitest_cmd, format_cmd which call into package_manager_exec.

## Deferred to follow-up (filed separately)
- F6 — env-mutating tests in `secure_git_tests` / `secure_cargo_tests`
  don't take `GLOBAL_ENV_LOCK` (only `policy_registry_tests` does).
  Race-prone but currently passing.
- F7 — `check_forbidden_pytest_args` uses `looks_like_path` which
  doesn't recognise bare-relative paths like `sub/dir.py`. Plugin
  loader is Kernel.require-equivalent; should reject anything with
  `/` or `\` even without explicit `./` prefix.
- gh/glab/gt unhardened (these wrap git under the hood; need
  secure_gh_command / secure_glab_command).

## Verified
- `cargo build --bin contextcrawler` — clean
- `cargo test --bin contextcrawler` — 2116 pass, 0 fail
- All 7 integration suites pass: branding_lint(3), git_hardening(6),
  cargo_hardening(4), node_hardening(4), runtime_hardening(12),
  cloud_hardening(14), harness_standalone(1)

Refs PRs thehoff#41 thehoff#42 thehoff#43 thehoff#44 thehoff#46 thehoff#47

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Codex pre-release adversarial review <[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.

harden(python/ruby/jvm/dotnet): strip PYTHONPATH/RUBYOPT/JAVA_TOOL_OPTIONS/DOTNET_STARTUP_HOOKS

1 participant