Repository navigation
harden(gh/glab/gt): zero-trust env strip + arg deny + passthrough fix (#50) - #58
Merged
Merged
Conversation
…#50) Wraps gh, glab, and gt (Graphite) with the same secure_*_command pattern already applied to git, kubectl, docker, aws, psql, curl, wget. Each gets its own env-strip list, optional arg deny-list, and end-to-end integration tests. ## What gets stripped - gh: GH_CONFIG_DIR, GH_EDITOR, GH_BROWSER, GH_PAGER, GH_PATH, BROWSER - glab: GLAB_CONFIG_DIR, GLAB_EDITOR, GLAB_BROWSER, GLAB_PAGER, BROWSER - gt: GT_EDITOR, GT_BROWSER, GT_PAGER, BROWSER + full git env deny set (gt shells out to git on every operation) - Plus UNIVERSAL_ENV_STRIP via apply_universal_env_strip (EDITOR, VISUAL, PAGER, LD_PRELOAD, DYLD_*, BASH_FUNC_*, etc.) ## What gets preserved (AUTH CONTRACT) Auth tokens MUST stay in inherited env or non-interactive use breaks. Pinning tests assert these are NOT in the strip lists: - gh: GH_TOKEN, GITHUB_TOKEN, GH_ENTERPRISE_TOKEN, GITHUB_ENTERPRISE_TOKEN (no GH_ prefix; gh GHES fallback per cli.github.com docs), GH_HOST, GH_REPO - glab: GITLAB_TOKEN, GLAB_TOKEN, GITLAB_HOST - gt: GRAPHITE_TOKEN ## Arg deny-list - gh: extension exec NAME is rejected (runs arbitrary extension binary). extension install IS allowed (deliberate user action, no inline exec). Other gh subcommands (workflow run, secret set, repo edit, codespace) reviewed and intentionally not denied -- they don't fit the env-hijack threat model and restricting them would kill normal usage. - glab, gt: no eval-equivalent subcommands; checks are stubs for shape. ## Pre-PR review fixes (in same commit) Pre-merge independent review caught 4 must-fix items: - P0 critical: run_passthrough helpers in gh/glab/gt_cmd.rs called the shared runner::run_passthrough which uses resolved_command() not secure_*_command(). Every passthrough path inside the typed routes (gh pr merge, glab api, unknown gt subcommands) was spawning children with the FULL unsanitised environment -- the wrap was documentation- only on those paths, same class of bug as F8 from #51. Fixed by switching all inner passthrough helpers to run_passthrough_cmd with the secure_*_command. - P1: GITHUB_ENTERPRISE_TOKEN (no GH_ prefix) is a real gh GHES fallback token. Behaviour already correct (not in strip list) but pinning test didn't cover it. Added. - P2: check_forbidden_gh_args had a take(8) cap that let an attacker pad with global flags to push extension exec past the detector. Removed the cap; loop already short-circuits on second positional. - P3: shared cloud_deny_message hardcoded issue #38 (cloud-tools issue). Added cloud_deny_message_with_issue(tool, op, issue) variant so the gh deny correctly cites #50. ## Pinning tests added (8 unit + 4 integration) Unit (src/core/utils.rs secure_cloud_tests): - gh_strip_list_contains_redirect_overrides - gh_strip_list_preserves_auth_tokens (incl GITHUB_ENTERPRISE_TOKEN) - rejects_gh_extension_exec - gh_extension_exec_detected_through_many_global_flags (P2 pin) - gh_deny_message_cites_issue_50 (P3 pin) - allows_normal_gh_args - glab_strip_list_contains_redirect_overrides_preserves_tokens - gt_strip_list_chains_to_git_env_deny Integration (tests/gh_glab_gt_hardening.rs): - gh_config_dir_is_stripped (skip if gh not on PATH) - glab_config_dir_is_stripped (skip if glab not on PATH) - gh_extension_exec_is_rejected (binary-independent; proves deny path) - gh_auth_tokens_are_preserved_in_proxy_path (positive baseline) ## Verified - cargo build clean - cargo test --bin contextcrawler: 2153 pass, 0 fail - 8 integration suites green (branding_lint, cargo_hardening, node_hardening, runtime_hardening, cloud_hardening, harness_standalone, proxy_nudge, new gh_glab_gt_hardening) - Empirical: gh extension exec evil and gh --foo --bar extension exec evil both deny with #50 message ## Not in this PR - #57 -- git_hardening test fragility (gpg agent dependency). Reproduces on develop tip independent of this branch; environmental, not a #50 regression. Closes #50.
This was referenced May 18, 2026
Merged
noogalabs
pushed a commit
to noogalabs/contextcrawler
that referenced
this pull request
Jun 4, 2026
…off#57) `tests/git_hardening.rs::make_repo()` ran `git commit` with the developer's global git config inherited. When the host has `commit.gpgsign=true` pointing at a signing agent (1Password, gpg-agent, ssh-agent) and that agent is unavailable or locked, ALL 5 fixture-using tests die at `commit -q -m init` with "1Password: agent returned an error" / "fatal: failed to write commit object" — and the failure looks like the security test broke, not the fixture. This bit the thehoff#50 (gh/glab/gt) and thehoff#58 (review fixups) commits in the same session: the bug-bypass tests passed, the env-strip tests panicked at the fixture, and the user had to context-switch to figure out it was 1Password not the security work. ## Fix Two layers of insurance in `make_repo()`: 1. Pass `-c commit.gpgsign=false -c tag.gpgsign=false` on every git invocation in the helper. These override the inherited global config for the duration of the call. 2. Also `git config commit.gpgsign false` + `tag.gpgsign false` on the freshly-init'd repo so any future helper that forgets the `-c` flags still gets a hermetic commit. Belt-and-braces because layer 1 alone is sufficient today, but layer 2 protects against drift in helpers that add new git calls later. ## Verified Before this PR (on develop tip `b5442fe`): test result: FAILED. 1 passed; 5 failed. After this PR: test result: ok. 6 passed; 0 failed. All other 8 integration suites continue to pass. Closes thehoff#57.
noogalabs
pushed a commit
to noogalabs/contextcrawler
that referenced
this pull request
Jun 4, 2026
…+ annotate scaffolding `cargo build` was emitting 80+ unused-* warnings, drowning real signal from genuine new dead-code introductions (e.g. PR thehoff#58 unused imports went unnoticed for a session). Zero-warning cargo build is the baseline. ## Orphan files deleted (-2953 lines) Audited as fully unreferenced (zero external `use crate::...::X` paths outside the file itself); confirmed by checking that all module-level items are unused in production and the deleted .rs files have no external test depending on their public API. - `src/analytics/security_cmd.rs` (617 lines) -- superseded by `src/hooks/tirith_gate.rs::run_security_dashboard` which backs the current `contextcrawler security` subcommand - `src/analytics/jsonl_rewriter.rs` (557 lines) - `src/analytics/session_compact_cmd.rs` (292 lines) -- session-compact feature inherited from the contextzip merge that never got wired - `src/analytics/ansi_filter.rs` (198 lines) -- only used by the jsonl_rewriter above - `src/cmds/cloud/web_cmd.rs` (472 lines) -- contextzip HTML extractor that was never wired through clap; `cmds/cloud/mod.rs` uses `automod::dir!` so the file got auto-imported as a module without a call site - `src/core/error_cmd.rs` (817 lines) -- language-specific stack-trace compactors that also never got wired Also dropped from mod.rs: - `src/analytics/mod.rs` -- 4 `pub mod` lines - `src/core/mod.rs` -- `pub mod error_cmd;` line ## Legacy hook constants WIRED (instead of deleted) `LEGACY_CLAUDE_HOOK_COMMAND` and `LEGACY_CURSOR_HOOK_COMMAND` were defined as constants but only ever referenced as literal strings elsewhere. Wiring them properly closes two latent bugs: - `src/hooks/integrity.rs::run_verify`: only checked the legacy literal "rtk hook claude" in `settings.json`. Freshly-installed users running the current `CLAUDE_HOOK_COMMAND` ("contextcrawler hook claude") saw "hook not installed" even after a successful `contextcrawler init -g`. Fixed: accept either current or legacy. - `src/hooks/init.rs` cursor hook detection (line 3083 + 3258): only matched the current command. Legacy installs got missed by the skip-install detector AND the uninstall remover. Fixed: accept both. ## Intentional scaffolding annotated #[allow(dead_code)] These are future-wired structures that earn their warnings by design. Annotating with intent so the next reader knows they're not orphans: - `core::utils::ToolPolicy` + `secure_command_with_policy` + `check_args_with_policy` + `policy_deny_message` -- the worked refactor target documented in the module header. Per-tool helpers will migrate onto it. - `main::web_ssrf_block_reason` -- IP classification helper from the deleted web_cmd.rs. Preserved for future SSRF wiring of curl/wget filter or a Rust HTTP client; the classification logic is the expensive part to re-derive. - `cmds::git::git::filter_branch_output` -- back-compat wrapper kept for the back-compat test surface (production switched to filter_branch_output_with_mode in thehoff#56). - `cmds::system::grep_cmd::has_format_flag_raw` -- OsString-typed sibling of the existing String-typed helper; one helper per arg-type so callers don't need to allocate. ## Unused imports removed - `src/cmds/js/lint_cmd.rs` -- `resolved_command` (replaced by `secure_python_command` / `package_manager_exec` earlier this session) - `src/cmds/system/grep_cmd.rs` -- `resolved_command` moved under `#[cfg(test)]` (production uses `secure_rg_command`, tests use the raw baseline) ## Verified - cargo build clean: **0 warnings** (was 80+) - cargo test --bin contextcrawler: 2116 pass / 0 fail (was 2156; delta is the ~40 tests inside the deleted orphan files) - All 9 integration suites green No production behaviour changes apart from the two latent-bug fixes (integrity check + cursor hook detection) which are pure improvements.
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
Wraps
gh,glab,gtwithsecure_*_commandpattern: per-tool env strip + optional arg deny + UNIVERSAL_ENV_STRIP. Auth tokens preserved.What gets stripped vs preserved
GH_CONFIG_DIR,GH_EDITOR,GH_BROWSER,GH_PAGER,GH_PATH,BROWSERGH_TOKEN,GITHUB_TOKEN,GH_ENTERPRISE_TOKEN,GITHUB_ENTERPRISE_TOKEN,GH_HOST,GH_REPOGLAB_CONFIG_DIR,GLAB_EDITOR,GLAB_BROWSER,GLAB_PAGER,BROWSERGITLAB_TOKEN,GLAB_TOKEN,GITLAB_HOSTGT_EDITOR,GT_BROWSER,GT_PAGER,BROWSER+ full git env denyGRAPHITE_TOKENAll three also inherit
UNIVERSAL_ENV_STRIP(LD_PRELOAD, DYLD_, BASH_FUNC_, EDITOR, VISUAL, PAGER, etc.).Arg deny
gh extension exec <name>rejected (arbitrary extension binary).extension installallowed (deliberate user action).Pre-PR review fixes (4 caught + addressed in commit
cc7b3bd)P0 critical —
run_passthroughhelpers insidegh_cmd.rs/glab_cmd.rs/gt_cmd.rswere calling sharedrunner::run_passthroughwhich usesresolved_command(), notsecure_*_command(). Every passthrough path (gh pr merge,glab api, unknown gt subcommands) was spawning with the FULL unsanitised environment — same class of bug as F8 from #51 (doc-only wrap). Fixed by switching all inner passthrough helpers torun_passthrough_cmd(secure_X_command()).P1 —
GITHUB_ENTERPRISE_TOKEN(noGH_prefix) is a real gh GHES fallback per cli.github.com docs. Behaviour was already correct (not stripped) but pinning test didn't cover it. Added.P2 —
check_forbidden_gh_argshad a.take(8)cap that let an attacker pad with global flags to pushextension execpast the detector. Removed; loop short-circuits on second positional anyway.P3 — shared
cloud_deny_messagehardcodedissue #38. Addedcloud_deny_message_with_issue(tool, op, issue)variant so gh deny correctly cites #50.Pinning tests (8 unit + 4 integration)
Unit in
secure_cloud_tests:gh_strip_list_contains_redirect_overrides,gh_strip_list_preserves_auth_tokens,rejects_gh_extension_exec,gh_extension_exec_detected_through_many_global_flags(P2 pin),gh_deny_message_cites_issue_50(P3 pin),allows_normal_gh_args,glab_strip_list_contains_redirect_overrides_preserves_tokens,gt_strip_list_chains_to_git_env_deny.Integration
tests/gh_glab_gt_hardening.rs: 4 tests includinggh_extension_exec_is_rejected(binary-independent).Verified
cargo buildcleancargo test --bin contextcrawler— 2153 pass / 0 failgh_glab_gt_hardening)gh extension exec evilandgh --foo --bar extension exec evilboth deny with harden(gh/glab/gt): wrap GitHub/GitLab/git-town CLIs with secure_* helpers (chain to git) #50 refNot in this PR
Closes #50.