Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(rules): match spaced and named fork bombs in fork-bomb-pattern (#1031)

Rudy Mizrahi Celekli0f9be515a26b
diff --git a/rules/resource-consumption/fork-bomb-pattern.rule.yaml b/rules/resource-consumption/fork-bomb-pattern.rule.yaml
index ce96b691..1be957ca 100644
--- a/rules/resource-consumption/fork-bomb-pattern.rule.yaml
+++ b/rules/resource-consumption/fork-bomb-pattern.rule.yaml
@@ -1,10 +1,12 @@
id: fork-bomb-pattern
-version: 1
+version: 2
title: Fork-bomb pattern executed in a command
description: >
- A command.executed event invokes a known fork-bomb shape — the canonical
- bash fork bomb `:(){ :|:& };:`, the `while true; do ... & done` recursive
- spawn loop, or the `bash -c ':()...'` wrapper. A fork bomb is a denial-of-
+ A command.executed event invokes a known fork-bomb shape — a function whose whole
+ body pipes one bare command into another in the background and that is then
+ called, such as the canonical `:(){ :|:& };:` under any name or spacing, the
+ `while true; do ... & done` recursive spawn loop, or a perl/python/ruby fork
+ loop. A fork bomb is a denial-of-
service primitive that recursively spawns processes to exhaust PID and
process-table resources; running one from an agent session is a strong
resource-DoS or destructive-escalation signal (OWASP LLM10). The rule is
@@ -21,10 +23,9 @@ taxonomy:
match: >
e.event.action == "command.executed" && (
- e.command.command.matches("(?i):\\(\\)\\s*\\{?\\s*:\\|:&\\s*\\}?\\s*;\\s*:") ||
+ e.command.command.matches("(?i)[\\w:.-]+\\s*\\(\\s*\\)\\s*\\{?\\s*[\\w:.-]+\\s*\\|\\s*[\\w:.-]+\\s*&\\s*;?\\s*\\}?[ \\t]*[;\\n]\\s*[\\w:.-]+") ||
e.command.command.matches("(?i)\\bwhile\\s+true\\s*;?\\s*do\\b[^;&|]*&\\s*\\S") ||
e.command.command.matches("(?i)\\bfor\\s*\\(\\s*;\\s*;\\s*\\)\\s*[;{]") ||
- e.command.command.matches("(?i)\\bbomb\\(\\)\\b") ||
e.command.command.matches("(?i)\\b(perl|python|ruby)\\s+-[ec]\\s+['\"][^'\"]*(\\.fork\\(\\)|for\\s+_\\s+in\\s+iter\\(\\s*int\\s*,\\s*1\\s*\\)|\\bwhile\\s+(1|True)\\b)")
)
@@ -67,6 +68,42 @@ tests:
event: { action: command.executed }
command: { command: "python -c 'import os; [os.fork() for _ in iter(int,1)]'" }
session: { id: s1 }
+ - name: spaced_bash_fork_bomb
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: ":(){ :|: & };:" }
+ session: { id: s1 }
+ - name: named_bomb_function
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "bomb(){ bomb|bomb& };bomb" }
+ session: { id: s1 }
+ - name: renamed_fork_bomb
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "f(){ f|f& };f" }
+ session: { id: s1 }
+ - name: spaced_renamed_fork_bomb
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "fork() { fork | fork & }; fork" }
+ session: { id: s1 }
+ - name: search_for_bomb_function
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "grep -rn 'bomb()' src/" }
+ session: { id: s1 }
+ - name: backgrounded_pipeline_function
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "watch(){ tail -f app.log | grep ERROR & }; watch" }
+ session: { id: s1 }
- name: bounded_while_loop_benign
verdict: no_match
events: