Skip to content

harden(discover): fix RTK_DISABLED bypass + symlink/slice findings (#100 G7) - #104

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

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

Conversation

@thehoff

@thehoff thehoff commented May 20, 2026

Copy link
Copy Markdown
Owner

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

Sev Fix
CRITICAL discover/registry.rs — RTK_DISABLED bypass. ENV_PREFIX's unquoted-value regex [^\s]* swallowed RTK_DISABLED=1 inside FOO=RTK_DISABLED=1 as one FOO-keyed assignment; the substring check then matched it → rewriter + gates bypassed. Fix: split the env-prefix into proper KEY=VALUE tokens, match the key name exactly. Verified by Codex: closed, across all assignment positions; a genuine RTK_DISABLED=1 still disables.
IMPORTANT discover/registry.rs — strip_absolute_path stripped ANY /-containing first token (./git → git); now only strips true absolute paths (starts_with('/')).
IMPORTANT discover/provider.rs — symlinked project dirs and symlinked .jsonl session files now rejected (symlink_metadata), so a discover scan can't be redirected outside ~/.claude/projects/.
IMPORTANT discover/codex.rs — map_while(ok) silently dropped a log tail on the first decode error; now explicit per-line handling.
IMPORTANT analytics/gain.rs, session_cmd.rs — byte-slice truncation → char-safe (no panic on multibyte command strings).
NICE discover/report.rs, cc_economics.rs, session_cmd.rs — rtk → contextcrawler in 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 --release clean
  • Codex review — CRITICAL verified closed; per-file symlink follow-up applied (c4d27e3)

Part of the #100 audit.

🤖 Generated with Claude Code

thehoff and others added 2 commits May 20, 2026 18:40
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]>
@thehoff
thehoff merged commit 7fe20fe into develop May 20, 2026
4 checks passed
@thehoff
thehoff deleted the harden/g7-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