Skip to content

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

fix(rules): flag every octal chmod mode that makes a file world-writable (#1021)

Rudy Mizrahi Celekli6a1dd081b5b4
diff --git a/rules/risky-command/world-writable-chmod.rule.yaml b/rules/risky-command/world-writable-chmod.rule.yaml
index 10ce4144..7fc223ca 100644
--- a/rules/risky-command/world-writable-chmod.rule.yaml
+++ b/rules/risky-command/world-writable-chmod.rule.yaml
@@ -1,8 +1,9 @@
id: world-writable-chmod
-version: 3
+version: 4
title: chmod grants world-writable or full permissions
description: >
- A command makes a file or tree world-writable — chmod 777 / 0777, or a symbolic mode
+ A command makes a file or tree world-writable — an octal mode whose "other" digit
+ grants write (777, 0777, 666, 0776, 1777), or a symbolic mode
(via + or =) that grants write to other or all (e.g. o+w, a+rwx, a=rwx, o=rwx,
ugo+rwx). Owner- or group-only grants (u+w, g=rw) are intentionally excluded because
they are not world-writable. chmod is anchored to the acting command position so it
@@ -16,7 +17,7 @@ taxonomy:
match: >
e.event.action == "command.executed" &&
- e.command.command.matches("(?i)(^|[;&|]\\s*)chmod\\s+([^;&|]*\\s)?(0?777\\b|([ugoa]*[oa][ugoa]*)[+=][rwx]*w[rwx]*\\b)")
+ e.command.command.matches("(?i)(^|[;&|]\\s*)chmod\\s+([^;&|]*\\s)?([0-7]?[0-7]{2}[2367](\\s|$)|([ugoa]*[oa][ugoa]*)[+=][rwx]*w[rwx]*\\b)")
emit:
reason: "chmod grants world-writable or fully permissive access"
@@ -34,6 +35,18 @@ tests:
- event: { action: command.executed }
command: { command: "chmod 0777 evil.sh" }
session: { id: s1 }
+ - name: chmod_666_world_writable_file
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "chmod 666 /etc/app/config" }
+ session: { id: s1 }
+ - name: chmod_0776_octal
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "chmod -R 0776 /srv/app" }
+ session: { id: s1 }
- name: chmod_ugo_rwx_symbolic
verdict: match
events:
@@ -64,12 +77,30 @@ tests:
- event: { action: command.executed }
command: { command: "cd /opt && chmod 777 ./run" }
session: { id: s1 }
+ - name: chmod_sticky_world_writable_dir
+ verdict: match
+ events:
+ - event: { action: command.executed }
+ command: { command: "chmod 1777 /srv/shared" }
+ session: { id: s1 }
- name: chmod_normal_mode
verdict: no_match
events:
- event: { action: command.executed }
command: { command: "chmod 644 README.md" }
session: { id: s1 }
+ - name: chmod_exec_on_numbered_script
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "chmod +x 007.sh" }
+ session: { id: s1 }
+ - name: chmod_normal_mode_on_numbered_file
+ verdict: no_match
+ events:
+ - event: { action: command.executed }
+ command: { command: "chmod 644 002-setup.sh" }
+ session: { id: s1 }
- name: chmod_read_only_other
verdict: no_match
events: