Skip to main content

lean_ctx/core/shell_allowlist/
mod.rs

1//! Shell allowlist with AST-based command parsing.
2//!
3//! Security model (Information Bottleneck principle):
4//! - When allowlist is set: ALL segments of a compound command must be allowed (deny-by-default)
5//! - When empty: all commands pass (backwards-compatible blocklist-only mode)
6//! - Dangerous patterns (subshells, eval, backticks) are blocked in restricted mode
7
8mod case_construct;
9mod compound;
10mod config;
11mod enforcement;
12mod heredoc;
13mod mode;
14mod substitution;
15mod tokenizer;
16
17use crate::core::error::ShellError;
18
19use case_construct::find_shell_word;
20use compound::expand_to_leaf_segments;
21use config::{allowlist_block_message, effective_allowlist};
22use enforcement::SHELL_BUILTINS;
23#[cfg(test)]
24use enforcement::{
25    check_all_segments, check_pipe_to_bare_interpreter, check_unconditional_blocked_only,
26    enforce_shell_allowlist, is_bare_interpreter_stdin, is_project_root_binary,
27    normalize_line_continuations,
28};
29use tokenizer::{
30    extract_all_commands, extract_base_from_segment, quote_aware_token_end, skip_env_assignments,
31    split_on_operators,
32};
33
34pub(crate) use case_construct::{contains_double_semicolon, rewrite_case_constructs};
35pub use config::*;
36pub use enforcement::*;
37pub(crate) use heredoc::heredoc_delims;
38pub(crate) use heredoc::read_heredoc_delim;
39pub use heredoc::strip_all_heredoc_bodies;
40pub(crate) use heredoc::{strip_comments, strip_quoted_heredoc_bodies};
41pub use mode::ShellSecurity;
42pub(crate) use substitution::check_substitution_in_args;
43#[cfg(test)]
44pub(crate) use substitution::has_expanding_substitution_in_args;
45#[cfg(test)]
46pub(crate) use tests::allow;
47pub use tokenizer::*;
48
49#[cfg(test)]
50mod tests;
51#[cfg(test)]
52mod tests_tokenizer;