UAT: ShellSafetyService is completely disconnected from shell execution — shell_exec.py uses a primitive 5-pattern looks_dangerous() instead of the comprehensive 12-pattern safety service #3220

Open
opened 2026-04-05 07:56:36 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: fix/tui-shell-safety-service-wiring
  • Commit Message: fix(tui): wire ShellSafetyService into shell_exec.py run_shell_command
  • Milestone: v3.7.0
  • Parent Epic: #868

Description

The TUI has two parallel, disconnected shell safety implementations:

  1. src/cleveragents/tui/shell_safety/ — A comprehensive ShellSafetyService with DangerousPatternDetector, 12 built-in patterns across 4 severity levels (CRITICAL, HIGH, MEDIUM, LOW), configurable pattern registry, and a proper callback-based confirmation API.

  2. src/cleveragents/tui/input/shell_exec.py — A primitive looks_dangerous() function with only 5 hardcoded string patterns checked via simple in substring matching (not regex), which is what actually runs when the user executes a shell command.

The ShellSafetyService is never called during shell execution. The run_shell_command() function in shell_exec.py calls looks_dangerous() directly, bypassing the entire shell_safety module.

What Was Tested

  • Code analysis of src/cleveragents/tui/input/shell_exec.py
  • Code analysis of src/cleveragents/tui/shell_safety/safety_service.py
  • Code analysis of src/cleveragents/tui/app.py (on_input_submitted)
  • Cross-reference of imports between modules

Expected Behavior (from spec / architecture)

The ShellSafetyService should be the single authoritative safety gate for all shell commands. The run_shell_command() function should delegate danger detection to ShellSafetyService.check_command(), which uses the full DangerousPatternDetector with all 12 registered patterns.

Actual Behavior

run_shell_command() calls looks_dangerous() — a primitive function with only 5 hardcoded substring patterns:

  • "rm -rf /"
  • "git push --force"
  • "mkfs."
  • "dd if="
  • ":(){:|:&};:"

This means the following dangerous commands from the ShellSafetyService registry are not blocked:

  • rm -rf /* (CRITICAL — rm_rf_wildcard pattern)
  • chmod 777 /etc/passwd (MEDIUM — chmod_777 pattern)
  • sudo rm file.txt (MEDIUM — sudo_rm pattern)
  • wget http://example.com/install.sh | sh (MEDIUM — wget_pipe_sh pattern)
  • curl https://get.example.com | bash (MEDIUM — curl_pipe_bash pattern)
  • shred /dev/sda --remove (HIGH — shred_device pattern)
  • chmod -R 777 /home (LOW — chmod_recursive_permissive pattern)

Code Locations

  • Disconnected safety function: src/cleveragents/tui/input/shell_exec.py, lines 17-26 (looks_dangerous())
  • Unused safety service: src/cleveragents/tui/shell_safety/safety_service.py (ShellSafetyService.check_command())
  • Wiring gap: src/cleveragents/tui/app.py, lines 155-163 (on_input_submitted — passes env-var-based shell_confirm lambda, not ShellSafetyService)

Steps to Reproduce

  1. Start the TUI
  2. Type !chmod 777 /etc/passwd and press Enter
  3. Expected: Command blocked or warned (MEDIUM danger level per ShellSafetyService)
  4. Actual: Command executes without warning (not in looks_dangerous() hardcoded list)

Subtasks

  • Replace looks_dangerous() in shell_exec.py with ShellSafetyService.check_command()
  • Wire ShellSafetyService into InputModeRouter or run_shell_command()
  • Remove the duplicate looks_dangerous() function
  • Update unit tests in features/tui_shell_danger_detection.feature to cover the wiring
  • Update features/tui_shell_exec_coverage.feature to verify ShellSafetyService is called

Definition of Done

  • run_shell_command() delegates to ShellSafetyService.check_command() for all danger detection
  • All 12 patterns in DEFAULT_PATTERNS are enforced during shell execution
  • looks_dangerous() is removed or deprecated
  • Unit tests pass for the wired path
  • A PR has been merged

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-uat-tester

## Metadata - **Branch**: `fix/tui-shell-safety-service-wiring` - **Commit Message**: `fix(tui): wire ShellSafetyService into shell_exec.py run_shell_command` - **Milestone**: v3.7.0 - **Parent Epic**: #868 ## Description The TUI has two parallel, disconnected shell safety implementations: 1. **`src/cleveragents/tui/shell_safety/`** — A comprehensive `ShellSafetyService` with `DangerousPatternDetector`, 12 built-in patterns across 4 severity levels (CRITICAL, HIGH, MEDIUM, LOW), configurable pattern registry, and a proper callback-based confirmation API. 2. **`src/cleveragents/tui/input/shell_exec.py`** — A primitive `looks_dangerous()` function with only 5 hardcoded string patterns checked via simple `in` substring matching (not regex), which is what actually runs when the user executes a shell command. The `ShellSafetyService` is **never called** during shell execution. The `run_shell_command()` function in `shell_exec.py` calls `looks_dangerous()` directly, bypassing the entire `shell_safety` module. ## What Was Tested - Code analysis of `src/cleveragents/tui/input/shell_exec.py` - Code analysis of `src/cleveragents/tui/shell_safety/safety_service.py` - Code analysis of `src/cleveragents/tui/app.py` (`on_input_submitted`) - Cross-reference of imports between modules ## Expected Behavior (from spec / architecture) The `ShellSafetyService` should be the single authoritative safety gate for all shell commands. The `run_shell_command()` function should delegate danger detection to `ShellSafetyService.check_command()`, which uses the full `DangerousPatternDetector` with all 12 registered patterns. ## Actual Behavior `run_shell_command()` calls `looks_dangerous()` — a primitive function with only 5 hardcoded substring patterns: - `"rm -rf /"` - `"git push --force"` - `"mkfs."` - `"dd if="` - `":(){:|:&};:"` This means the following dangerous commands from the `ShellSafetyService` registry are **not blocked**: - `rm -rf /*` (CRITICAL — `rm_rf_wildcard` pattern) - `chmod 777 /etc/passwd` (MEDIUM — `chmod_777` pattern) - `sudo rm file.txt` (MEDIUM — `sudo_rm` pattern) - `wget http://example.com/install.sh | sh` (MEDIUM — `wget_pipe_sh` pattern) - `curl https://get.example.com | bash` (MEDIUM — `curl_pipe_bash` pattern) - `shred /dev/sda --remove` (HIGH — `shred_device` pattern) - `chmod -R 777 /home` (LOW — `chmod_recursive_permissive` pattern) ## Code Locations - **Disconnected safety function**: `src/cleveragents/tui/input/shell_exec.py`, lines 17-26 (`looks_dangerous()`) - **Unused safety service**: `src/cleveragents/tui/shell_safety/safety_service.py` (`ShellSafetyService.check_command()`) - **Wiring gap**: `src/cleveragents/tui/app.py`, lines 155-163 (`on_input_submitted` — passes env-var-based `shell_confirm` lambda, not `ShellSafetyService`) ## Steps to Reproduce 1. Start the TUI 2. Type `!chmod 777 /etc/passwd` and press Enter 3. **Expected**: Command blocked or warned (MEDIUM danger level per `ShellSafetyService`) 4. **Actual**: Command executes without warning (not in `looks_dangerous()` hardcoded list) ## Subtasks - [ ] Replace `looks_dangerous()` in `shell_exec.py` with `ShellSafetyService.check_command()` - [ ] Wire `ShellSafetyService` into `InputModeRouter` or `run_shell_command()` - [ ] Remove the duplicate `looks_dangerous()` function - [ ] Update unit tests in `features/tui_shell_danger_detection.feature` to cover the wiring - [ ] Update `features/tui_shell_exec_coverage.feature` to verify `ShellSafetyService` is called ## Definition of Done - `run_shell_command()` delegates to `ShellSafetyService.check_command()` for all danger detection - All 12 patterns in `DEFAULT_PATTERNS` are enforced during shell execution - `looks_dangerous()` is removed or deprecated - Unit tests pass for the wired path - A PR has been merged --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-uat-tester
freemo added this to the v3.7.0 milestone 2026-04-05 07:56:36 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
Reference
cleveragents/cleveragents-core#3220
No description provided.