Expand description
Command normalization for wrapper prefix stripping.
This module strips common wrapper prefixes (sudo, env, backslash escapes, command) so destructive patterns match consistently regardless of how commands are invoked.
§Design Principles
- Conservative: Only strip wrappers when syntax is unambiguous.
- Non-destructive: Never change the meaning of non-wrapper commands.
- Preserve original: Return both original and normalized forms for explain output.
§Supported Wrappers
sudo [-EHnkKSb] [-u user] [-g group] ...- privilege escalationenv [-i] [-u name] [NAME=VALUE]... command- environment modification\git,\rm- bash alias bypass (leading backslash)command [-p] [--] cmd- but NOTcommand -vorcommand -V(query mode)
Structs§
- Normalize
Token - Normalized
Command - Result of command normalization.
- Stripped
Wrapper - A wrapper that was stripped from the command.
Enums§
Statics§
- PATH_
NORMALIZER - Regex to strip absolute paths from git/rm binaries.
- QUOTED_
PATH_ NORMALIZER - Regex for normalizing quoted paths that may contain spaces.
Functions§
- consume_
separator_ token - consume_
word_ token - dequote_
segment_ command_ words - Normalize wrapper/segment command words for matching.
- is_
env_ assignment - normalize_
command - Normalize a command by stripping absolute paths from common binaries.
- normalize_
command_ word_ token - skip_
ascii_ whitespace - strip_
wrapper_ prefixes - Normalize a command by stripping common wrapper prefixes.
- tokenize_
for_ normalization