UAT: Shell danger detection missing several spec-required patterns — fork bomb with spaces, rm -r, chmod 777, fdisk, parted, kill -9, sudo #1428

Open
opened 2026-04-02 17:50:16 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: bugfix/m8-shell-danger-detection-missing-patterns
  • Commit Message: fix(tui): add missing spec-required danger patterns to shell_exec looks_dangerous
  • Milestone: v3.7.0
  • Parent Epic: #341

Bug Report

What was tested: Shell mode dangerous command detection (src/cleveragents/tui/input/shell_exec.py)

Expected behavior (from spec):
The specification (Section "Shell Danger Detection") lists these patterns that should be detected:

Pattern Risk Level
rm -rf / rm -r High
chmod 777 Medium
> /dev/sda / dd if= High
`:(){ : :& };:` (fork bomb)
mkfs / fdisk / parted High
kill -9 / killall Medium
sudo / su Low

Actual behavior:
The implementation in src/cleveragents/tui/input/shell_exec.py only detects these patterns:

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

The following spec-required patterns are not detected:

  1. rm -r (without /) — rm -r /tmp is not flagged as dangerous
  2. :(){ :|:& };: (fork bomb with spaces) — the implementation uses :(){:|:&};: (no spaces), so the standard fork bomb pattern with spaces is not detected
  3. chmod 777 — not detected
  4. > /dev/sda — not detected
  5. fdisk — not detected
  6. parted — not detected
  7. kill -9 / killall — not detected
  8. sudo / su — not detected

Steps to reproduce:

from cleveragents.tui.input.shell_exec import looks_dangerous

print(looks_dangerous("rm -r /tmp"))          # Returns False (should be True)
print(looks_dangerous(":(){ :|:& };:"))        # Returns False (should be True)
print(looks_dangerous("chmod 777 /var/www"))   # Returns False (should be True)
print(looks_dangerous("fdisk /dev/sda"))       # Returns False (should be True)
print(looks_dangerous("kill -9 1234"))         # Returns False (should be True)
print(looks_dangerous("sudo rm -rf /"))        # Returns True (correct, but only because rm -rf / matches)

Code location: src/cleveragents/tui/input/shell_exec.py function looks_dangerous()

Note: The spec states "Danger detection is controlled by the shell.warn_dangerous setting (default: true). The detection is advisory only — it never prevents command execution." So this is about warning display, not blocking.

Severity: Medium — users may not receive warnings for potentially destructive commands.

Subtasks

  • Add rm -r (without trailing /) to the danger patterns in looks_dangerous()
  • Add :(){ :|:& };: (fork bomb with spaces) alongside the existing no-spaces variant
  • Add chmod 777 to the danger patterns
  • Add > /dev/sda to the danger patterns
  • Add fdisk to the danger patterns
  • Add parted to the danger patterns
  • Add kill -9 and killall to the danger patterns
  • Add sudo and su to the danger patterns
  • Tests (Behave): Add/update scenarios in features/ covering each newly added pattern, asserting looks_dangerous() returns True for each
  • Tests (Behave): Add regression scenarios asserting previously-passing patterns still return True
  • Tests (Robot): Add/update integration smoke test verifying the TUI shell danger warning is displayed for the new patterns
  • Run nox -e typecheck — confirm 0 errors
  • Verify coverage >= 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

  • All subtasks above are completed and checked off.
  • looks_dangerous() correctly returns True for all patterns listed in the spec: rm -r, :(){ :|:& };: (with spaces), chmod 777, > /dev/sda, fdisk, parted, kill -9, killall, sudo, su.
  • No previously-passing danger patterns are broken by the change.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
  • All nox stages pass
  • Coverage >= 97%
## Metadata - **Branch**: `bugfix/m8-shell-danger-detection-missing-patterns` - **Commit Message**: `fix(tui): add missing spec-required danger patterns to shell_exec looks_dangerous` - **Milestone**: v3.7.0 - **Parent Epic**: #341 ## Bug Report **What was tested:** Shell mode dangerous command detection (`src/cleveragents/tui/input/shell_exec.py`) **Expected behavior (from spec):** The specification (Section "Shell Danger Detection") lists these patterns that should be detected: | Pattern | Risk Level | |---------|-----------| | `rm -rf` / `rm -r` | High | | `chmod 777` | Medium | | `> /dev/sda` / `dd if=` | High | | `:(){ :|:& };:` (fork bomb) | High | | `mkfs` / `fdisk` / `parted` | High | | `kill -9` / `killall` | Medium | | `sudo` / `su` | Low | **Actual behavior:** The implementation in `src/cleveragents/tui/input/shell_exec.py` only detects these patterns: ```python patterns = ( "rm -rf /", "git push --force", "mkfs.", "dd if=", ":(){:|:&};:", ) ``` The following spec-required patterns are **not detected**: 1. `rm -r` (without `/`) — `rm -r /tmp` is not flagged as dangerous 2. `:(){ :|:& };:` (fork bomb with spaces) — the implementation uses `:(){:|:&};:` (no spaces), so the standard fork bomb pattern with spaces is not detected 3. `chmod 777` — not detected 4. `> /dev/sda` — not detected 5. `fdisk` — not detected 6. `parted` — not detected 7. `kill -9` / `killall` — not detected 8. `sudo` / `su` — not detected **Steps to reproduce:** ```python from cleveragents.tui.input.shell_exec import looks_dangerous print(looks_dangerous("rm -r /tmp")) # Returns False (should be True) print(looks_dangerous(":(){ :|:& };:")) # Returns False (should be True) print(looks_dangerous("chmod 777 /var/www")) # Returns False (should be True) print(looks_dangerous("fdisk /dev/sda")) # Returns False (should be True) print(looks_dangerous("kill -9 1234")) # Returns False (should be True) print(looks_dangerous("sudo rm -rf /")) # Returns True (correct, but only because rm -rf / matches) ``` **Code location:** `src/cleveragents/tui/input/shell_exec.py` function `looks_dangerous()` **Note:** The spec states "Danger detection is controlled by the `shell.warn_dangerous` setting (default: `true`). The detection is advisory only — it never prevents command execution." So this is about warning display, not blocking. **Severity:** Medium — users may not receive warnings for potentially destructive commands. ## Subtasks - [ ] Add `rm -r` (without trailing `/`) to the danger patterns in `looks_dangerous()` - [ ] Add `:(){ :|:& };:` (fork bomb with spaces) alongside the existing no-spaces variant - [ ] Add `chmod 777` to the danger patterns - [ ] Add `> /dev/sda` to the danger patterns - [ ] Add `fdisk` to the danger patterns - [ ] Add `parted` to the danger patterns - [ ] Add `kill -9` and `killall` to the danger patterns - [ ] Add `sudo` and `su` to the danger patterns - [ ] Tests (Behave): Add/update scenarios in `features/` covering each newly added pattern, asserting `looks_dangerous()` returns `True` for each - [ ] Tests (Behave): Add regression scenarios asserting previously-passing patterns still return `True` - [ ] Tests (Robot): Add/update integration smoke test verifying the TUI shell danger warning is displayed for the new patterns - [ ] Run `nox -e typecheck` — confirm 0 errors - [ ] Verify coverage >= 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done - [ ] All subtasks above are completed and checked off. - [ ] `looks_dangerous()` correctly returns `True` for all patterns listed in the spec: `rm -r`, `:(){ :|:& };:` (with spaces), `chmod 777`, `> /dev/sda`, `fdisk`, `parted`, `kill -9`, `killall`, `sudo`, `su`. - [ ] No previously-passing danger patterns are broken by the change. - [ ] A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - [ ] The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - [ ] The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. - [ ] All nox stages pass - [ ] Coverage >= 97%
Author
Owner

Dependency note: This issue is a child of the TUI Epic #341 (feat(ui): add TUI/Web interface). Per the project hierarchy rules, this issue blocks #341 — the Epic cannot be considered complete until this bug is resolved.

This issue is independent of any currently-open issue and does not block any other in-progress work. It can be picked up in parallel with other TUI work.

**Dependency note:** This issue is a child of the TUI Epic #341 (`feat(ui): add TUI/Web interface`). Per the project hierarchy rules, this issue **blocks** #341 — the Epic cannot be considered complete until this bug is resolved. This issue is **independent** of any currently-open issue and does not block any other in-progress work. It can be picked up in parallel with other TUI work.
freemo self-assigned this 2026-04-02 18:45:11 +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.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#1428
No description provided.