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.
- Shell
Security - 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
ShellSecuritymode (GL #788). This is the single chokepoint shared by MCPctx_shelland 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+ additiveshell_allowlist_extra+ env), deduplicated. Empty means blocklist-only mode (all commands pass). Used bylean-ctx allowandlean-ctx doctorto 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 bylean-ctx doctorto surface a count, and by--fixto 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 thelean-ctx doctorupgrade advisory (§2 of the design doc). Always empty whenshell_allowlist_subcommand_scoping = false, since those entries’ meaning didn’t change under the compat path. - passes_
enforced - True when
commandwould pass the allowlist / dangerous-pattern checks inenforcesemantics — independent of the activeShellSecuritymode 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 thelean-ctx doctoradvisory (§2). - shadowing_
entry - §2 “Shadowing warnings”: is
amade useless by a different entry already inentries? 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 bylean-ctx allow(write-time warning) andlean-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_bodiesbut 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).