Skip to content

discover: sudo RTK_DISABLED=$VAR … is not detected as a bypass when sudo is a transparent prefix #4412

Open

Description

@KuSh

Summary

With hooks.transparent_prefixes = ["sudo", "sudo -E"], rtk discover counts sudo RTK_DISABLED=1 docker ps and RTK_DISABLED=1 sudo docker ps as bypasses (#3808), but not the same lines with an expanded value:

sudo RTK_DISABLED=$CI docker ps     not counted
RTK_DISABLED=$CI sudo docker ps     not counted
RTK_DISABLED=$CI docker ps          counted (the ENV_PREFIX path handles it)

rtk rewrite "sudo docker ps" rewrites under that config, so dropping the assignment would recover the savings.

Cause

strip_disabled_prefix_for_analytics (src/discover/registry.rs) walks raw lexer::tokenize tokens, which split one shell word at $: RTK_DISABLED=$CI is two tokens, RTK_DISABLED= and $CI. The walk treats $CI as the command word, finds it unsupported, and falls back to strip_disabled_prefix, which does not peel sudo. Walking coalesced words (lexer::coalesce_words, as without_rtk_disabled in src/discover/mod.rs does) would keep the assignment whole.

A missed count, not a wrong one: develop does not count these lines either.

Related: #3756, #3808.

Activity

  1. added
    bug
    good first issue
    on Oct 3, 2026
  2. rtk-wshm-sync-bot commented on Oct 3, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 85%

    Summary

    discover undercounts RTK_DISABLED bypasses with expanded env var values (e.g. $CI) alongside sudo because the analytics stripper tokenizes raw lexer tokens instead of coalesced words

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • src/discover/registry.rs
    • src/discover/mod.rs

    Suggested Actions

    1. Switch strip_disabled_prefix_for_analytics to walk lexer::coalesce_words like without_rtk_disabled does
    2. Add regression tests for sudo RTK_DISABLED=$VAR cmd and RTK_DISABLED=$VAR sudo cmd
    3. Cross-check against fix(discover): count sudo RTK_DISABLED=1 commands as bypass in analytics #3808 and discover/gain: RTK_DISABLED= after a wrapper the hook rewrites through (nice, timeout, command) is never counted as a bypass #4278 fixes for consistency across bypass-detection paths
    4. Confirm fix doesn't affect sudo-rewrite-safety behavior from The rewrite preserves a sudo prefix, so rtk's filtering, SQLite writes and tee writes execute with root privileges the original command did not require for them #3412/PR fix(rewrite): stop rewriting sudo commands (pass them through) #2810/fix(rewrite): never rewrite sudo-prefixed commands #3569

    Triaged automatically by wshm · This is an automated analysis, not a human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clibuggood first issuepriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions