Repository navigation
Description
sudo and env prefixes are re-attached in front of the rewritten command, so sudo <tool> becomes sudo rtk <tool>. The user elevated one program; rtk inserts itself into that elevation.
Provenance: AI-assisted source audit, human-directed, at v0.44.2 (700bdde). The rewrites below were produced by the shipped binary. This is a privilege-hygiene report, not a vulnerability claim — see "What I am not claiming".
Observed
$ rtk rewrite sudo iptables -L → sudo rtk iptables -L
$ rtk rewrite sudo du -sh /var → sudo rtk du -sh /var
$ rtk rewrite sudo docker ps → sudo rtk docker ps
$ rtk rewrite env FOO=1 git status → env FOO=1 rtk git status
ENV_PREFIX (src/discover/registry.rs:60-67) matches a leading run of sudo , env and VAR=value and re-attaches it ahead of the rewrite (registry.rs:959-977).
Why the placement matters
sudo iptables -L elevates exactly one binary. sudo rtk iptables -L elevates rtk, which then does its own work as root before and after running the real tool:
- opens and writes the SQLite history database
- writes tee files
- loads and parses configuration
- fires the telemetry ping (
main.rs:1578, on every invocation) - resolves the target binary through
PATH
None of that needed root. The user's intent was "run iptables as root", not "run a wrapper, its database layer and its config parser as root".
Two concrete consequences worth considering:
- File ownership. Files rtk creates during an elevated run are created by a root process. On a normal desktop that can leave root-owned entries in a user-owned data directory, which the subsequent non-elevated runs then have to write to.
PATHresolution under sudo. rtk resolves the wrapped tool itself rather than lettingsudodo it. Distributions that setsecure_pathinsudoersdo so specifically to control which binaries a root invocation can reach; a wrapper that performs its own lookup inside the elevated process is working against that intent.
What I am not claiming
I checked, and want to be explicit about the negative:
- The project-filter trust gate still applies.
src/core/toml_filter.rs:191-211routes project-local filter files throughhooks::trust::gated_filter_paths()andcheck_trust_with_content, so the.rtk/filters.tomlpath fixed in GHSA-fvvm-949w-qj4w is not re-opened by this. An untrusted repository file does not get parsed as root. - I have not demonstrated privilege escalation, and I do not believe this is one. It is a widening of what runs with elevated privilege, not a way to gain it.
Suggested directions (untested — no programmer has reviewed these)
The cleanest fix keeps rtk outside the elevation: rewrite sudo <tool> … to rtk sudo <tool> … rather than sudo rtk <tool> …, so rtk runs as the user and sudo elevates only the tool — the same shape the user typed. If that breaks output capture in ways I have not thought through, the alternatives are to skip rewriting sudo-prefixed commands entirely (they are rare and usually short-output), or to detect an elevated run and disable the database/tee/telemetry side effects for it.
Note there is currently no root awareness anywhere in the codebase — grepping src/ for geteuid, getuid or similar returns nothing — so option three would be new machinery, whereas the first two are changes to existing logic.
Not checked
The audit machine is Windows, so I verified the rewrite but not the runtime consequences: file ownership after an elevated run, secure_path interaction, and whether sudo is even in a typical rtk user's path for these commands are all unverified. If the elevated-run consequences turn out to be harmless in practice, the rewrite shape is still worth a look, but the priority drops.
Activity
pszymkowiak commentedon Aug 4, 2026
🔍 Automated Triage
bughighSummary
sudo/env prefixes are re-attached ahead of the rewrite (sudo rtk ) instead of after it, causing rtk's DB writes, tee writes, config parsing, PATH resolution and telemetry to run as root unnecessarily — recommend restructuring rewrite to preserve elevation scope to just the wrapped tool.
📁 Relevant files
src/discover/registry.rssrc/main.rssrc/core/toml_filter.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
fix(rewrite): never rewrite sudo-prefixed commands
HetCreep commentedon Sep 16, 2026
Following up on this one — confirmed fixed at current
develop(5e0f92c).Provenance: AI-assisted source audit, human-directed, at
develop@5e0f92c. Built the binary (cargo build --bin rtk) and ran live probes against it, plus the actual test suite — this was not a read-only check.The original report showed
sudo/envprefixes being re-attached in front of the rewrite (sudo docker ps→sudo rtk docker ps), via theENV_PREFIXregex and re-attachment logic insrc/discover/registry.rs. That regex no longer matchessudoat all.src/discover/registry.rs:69-73now carries an explicit note:and the regex right after it (
registry.rs:73:Regex::new(&format!(r#"^(?:env\s+|{}\s+)+"#, env_assign))) only alternates onenvand assignment prefixes —sudois absent.This landed in
a8bb67a("fix(rewrite): stop rewriting sudo commands (pass them through)", 2026-07-04) — not present at0de9610(the baseline the original report was written against), present at current HEAD. The commit message's rationale names both the runtime breakage in #146 and the unnecessary-privilege concern raised here, so this reads as a deliberate fix of this case, not a side effect of something else.It's pinned by tests, not just the comment:
test_rewrite_sudo_passthrough(registry.rs:5936-5961—sudo docker ps,sudo -u root docker ps,sudo git status,FOO=1 sudo docker ps,env FOO=1 sudo docker ps, baresudo, andsudoedit /etc/hosts, all asserted →None),test_classify_sudo_not_stripped(registry.rs:2726-2733), andtest_sudo_with_builtin_not_rewritten(registry.rs:6657-6664,sudo noglob git status→None).I also went looking for a regression, since
b17dda3("feat(rewrite): peel process wrapper prefixes", 2026-09-08) landed only 8 days before this HEAD and is exactly the kind of new prefix-stripping machinery that could reopen this by accident.PROCESS_WRAPPERS(registry.rs:1338-1368:timeout/time/nice/nohup) excludessudo, andsudois in neitherROUTABLE_WRAPPER_PREFIXESnorSHELL_KEYWORD_PREFIXES. None of the existing tests coversudostacked with one of those wrappers, so I built the binary and probed the compositions directly rather than trusting the gap in coverage:Exit 1 with empty stdout is rtk's "no rewrite, pass through unchanged" path (
HookDecision::Defer); every composition above hits it, none reintroduce a rewrite. Also rancargo test --bin rtk sudo— 4 passed, all green. Asrc/-wide grep forsudoturns up only thisENV_PREFIXregex/comment and an unrelated permission-verdict matcher insrc/hooks/permissions.rs(used for the hook allow/deny UI, not command rewriting) — no rules or filter TOML reintroduces a sudo rewrite either.Thanks for fixing this — closes the concern as originally filed. Fine to close.