Repository navigation
harden(node): secure_node_command across npm/pnpm/vitest/jest/playwright/tsc/eslint/prettier/prisma/next (#37) - #44
Merged
Merged
Conversation
…wire-ins (#37) Zero-trust layer on the entire Node-based wrapper set. NODE_OPTIONS hijacks every Node process (npm, pnpm, npx, vitest, jest, playwright, tsc, eslint, prettier, prisma, next), so a single env strip plus arg-deny covers the whole ecosystem. src/core/utils.rs: - secure_node_command(name) — strips NODE_OPTIONS, dynamic NPM_CONFIG_* + npm_config_* sweep, PRISMA_*_ENGINE_BINARY, PLAYWRIGHT_BROWSERS_PATH, TS_NODE_PROJECT, NEXT_SHARP_PATH - check_forbidden_node_args() — always-deny on --require, --setupFiles, --globalSetup, --rulesdir, --resolve-plugins-relative-to, --userconfig, --globalconfig; path-shape-deny on --reporter/--plugin (only blocks values that look like file paths, so --reporter html / --plugin prettier-plugin-tailwindcss still work) - looks_like_path() heuristic + node_deny_message src/cmds/js/{npm,pnpm,vitest,playwright,prisma,tsc,next,lint,prettier}_cmd.rs: - resolved_command(...) → secure_node_command(...) - Each user-arg-forwarding loop gated on check_forbidden_node_args tests/node_hardening.rs (4 integration tests): - NODE_OPTIONS=--require evil.js sentinel test — does NOT execute through contextcrawler - NPM_CONFIG_USERCONFIG=/tmp/evil-npmrc does NOT leak attacker registry - contextcrawler vitest --reporter /tmp/evil.js rejected - Positive: contextcrawler npm --version still works Rebuilt from clean develop after the additive merge corrupted cargo's function bodies in an earlier rebase attempt; deltas re-applied surgically. Closes #37 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
thehoff
added a commit
that referenced
this pull request
May 18, 2026
…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]>
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Zero-trust layer across the entire Node-based wrapper set. One env-strip + arg-deny per spawn site covers 8+ JS tools simultaneously because NODE_OPTIONS hijacks every Node process.
Tests
cargo test --bin contextcrawler— 2079 passcargo test --test node_hardening— 4 passCodex review
Deferred per merge-train cadence.
Closes #37