Repository navigation
harden(discover): fix RTK_DISABLED bypass + symlink/slice findings (#100 G7) - #104
Merged
Merged
Conversation
Group G7 of the full-codebase audit (#100): discover/analytics path. CRITICAL — RTK_DISABLED substring bypass (registry.rs): prefix_contains_rtk_disabled() substring-searched the whole env-prefix, so a crafted prefix like `FOO=RTK_DISABLED=1 git status` disabled rewriting (and any gates riding on it) without genuinely setting RTK_DISABLED. Now parses the prefix into individual KEY=VALUE assignments (splitting at the FIRST `=`) and only honours a key named exactly RTK_DISABLED. rewrite_segment_inner() updated to use it. strip_absolute_path (registry.rs): Stripped any first token containing `/`, so `./git` and `repo/bin/git` normalised to `git` and got rewritten as the real binary. Now strips only true absolute paths (token starts with `/`). provider.rs symlink escape: read_dir entries were trusted via path.is_dir(), which follows symlinks — a symlinked project dir under ~/.claude/projects/ could redirect scanning outside the tree. Now rejects symlinked entries via symlink_metadata().file_type().is_symlink() and prefix-checks each entry's canonical path against the resolved projects root. codex.rs silent log truncation: reader.lines().map_while(|l| l.ok()) stopped at the first I/O/UTF-8 error, dropping the rest of the log and undercounting commands. Now handles each line's error explicitly — logs and skips the bad line, keeps iterating. gain.rs / session_cmd.rs byte-slice truncation: &s[..n] on user-controlled command strings panics when a multibyte char straddles the boundary. Switched to char-safe truncation (core::utils::truncate / chars().take()). Branding (report.rs, cc_economics.rs, session_cmd.rs): User-facing headings RTK -> contextcrawler; issue URL -> github.com/thehoff/contextcrawler/issues. Internal identifiers untouched. "RTK Equivalent" column header shortened to "Equivalent" to stay within its fixed width. Tests: crafted FOO=RTK_DISABLED=1 prefix does NOT disable rewriting while a real RTK_DISABLED=1 does; ./git and repo/bin/git are not normalised; symlinked project dir rejected; gain truncation on multibyte command strings does not panic. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Codex-review follow-up for the G7 portion of #100. The branch already rejects symlinked project directories under ~/.claude/projects/, but the per-file walk inside an accepted project dir did not reject symlinked .jsonl session files — an attacker able to drop a symlink inside an otherwise-legitimate project dir could still redirect the scanner at a file outside the tree. Adds a symlink_metadata() check on each candidate file before it is accepted, mirroring the existing directory-level guard. Regular .jsonl files are still collected. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
8 tasks
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
Fixes the G7 (discover/analytics) findings from audit #100. Codex-reviewed — the CRITICAL verified closed; one follow-up (per-file symlink) applied.
Findings fixed
discover/registry.rs—RTK_DISABLEDbypass.ENV_PREFIX's unquoted-value regex[^\s]*swallowedRTK_DISABLED=1insideFOO=RTK_DISABLED=1as oneFOO-keyed assignment; the substring check then matched it → rewriter + gates bypassed. Fix: split the env-prefix into properKEY=VALUEtokens, match the key name exactly. Verified by Codex: closed, across all assignment positions; a genuineRTK_DISABLED=1still disables.discover/registry.rs—strip_absolute_pathstripped ANY/-containing first token (./git→git); now only strips true absolute paths (starts_with('/')).discover/provider.rs— symlinked project dirs and symlinked.jsonlsession files now rejected (symlink_metadata), so adiscoverscan can't be redirected outside~/.claude/projects/.discover/codex.rs—map_while(ok)silently dropped a log tail on the first decode error; now explicit per-line handling.analytics/gain.rs,session_cmd.rs— byte-slice truncation → char-safe (no panic on multibyte command strings).discover/report.rs,cc_economics.rs,session_cmd.rs—rtk→contextcrawlerin user-facing copy; issue URL →github.com/thehoff/contextcrawler/issues.Test plan
cargo test --workspace— 2300 pass, 0 fail (substring-bypass-vs-real, relative-path, symlinked dir + file, multibyte truncation)cargo build --releasecleanc4d27e3)Part of the #100 audit.
🤖 Generated with Claude Code