Skip to main content

Module shell_allowlist

Module shell_allowlist 

Source
Expand description

Shell allowlist with AST-based command parsing.

Security model (Information Bottleneck principle):

  • When allowlist is set: ALL segments of a compound command must be allowed (deny-by-default)
  • When empty: all commands pass (backwards-compatible blocklist-only mode)
  • Dangerous patterns (subshells, eval, backticks) are blocked in restricted mode

Enums§

Separator
The operator that ends a command segment.
ShellSecurity
Active shell-security posture. Order is least → most permissive only for readability; do not rely on ordinal values.

Functions§

check_shell_allowlist
Checks whether a command may run, honouring the active ShellSecurity mode (GL #788). This is the single chokepoint shared by MCP ctx_shell and the CLI shell entrypoints, so the mode applies consistently:
effective_allowlist_pub
Public accessor: the fully-resolved allowlist actually enforced by the MCP tools (base shell_allowlist + additive shell_allowlist_extra + env), deduplicated. Empty means blocklist-only mode (all commands pass). Used by lean-ctx allow and lean-ctx doctor to show users exactly what the runtime sees.
extract_all_commands_pub
Public accessor for extracting all command segments.
extract_base_command
invalid_allowlist_entries_pub
Public accessor: entries the effective allowlist silently dropped for invalid * placement (§4 of the design doc). Used by lean-ctx doctor to surface a count, and by --fix to know which raw config lines to comment out.
narrowed_allowlist_entries_pub
Public accessor: multi-word entries with no trailing * — their meaning changed under subcommand scoping (now exact-match only, previously “whole binary”). Used by the lean-ctx doctor upgrade advisory (§2 of the design doc). Always empty when shell_allowlist_subcommand_scoping = false, since those entries’ meaning didn’t change under the compat path.
passes_enforced
True when command would pass the allowlist / dangerous-pattern checks in enforce semantics — independent of the active ShellSecurity mode and without any logging or blocking side effects.
segments_with_separators
Every segment together with the separator that ends it; the last segment has none. Same scanner as split_on_operators, so the two never disagree about where a command ends.
shadowed_allowlist_entries_pub
All shadowed entries in entries, paired with the entry that covers each one — used by the lean-ctx doctor advisory (§2).
shadowing_entry
§2 “Shadowing warnings”: is a made useless by a different entry already in entries? Entry A is shadowed by B when B matches every command A matches: B is a single word equal to A’s first word, or B ends in * and B’s words before the * are a leading run of A’s words (ignoring A’s own trailing *). Returns the first covering entry, in list order. Shared by lean-ctx allow (write-time warning) and lean-ctx doctor (read-only advisory) so the rule can’t drift between the two.
shell_tokenize
Tokenize a shell command segment respecting single/double quotes and backslash escapes. Returns tokens with outer quotes stripped, matching how the shell would parse them. E.g. git -C "Program Files" status → ["git", "-C", "Program Files", "status"]
strip_all_heredoc_bodies
Like strip_quoted_heredoc_bodies but strips bodies for all heredocs (quoted and unquoted delimiters). Use for checks that must never interpret heredoc body content as commands or redirects (#931).
warn_only_reason
The reason of an enforce-mode block message, without the wording that only holds when the command was actually stopped (#1874).