Python
fix(security): refuse find's fprint family under a bare allowlist entry
Shakti Prasad Mohapatrae6bc432949ad
diff --git a/coworker/permissions.py b/coworker/permissions.pyindex e617ae57..14020f5e 100644--- a/coworker/permissions.py+++ b/coworker/permissions.py@@ -39,8 +39,11 @@ _INTERPRETERS = {"sh", "bash", "zsh", "dash", "ksh", "fish", "powershell", "pwsh", "cmd","python", "python3", "node", "deno", "bun", "ruby", "perl", "php",}-# Flags that turn a search/list tool into an execution or deletion tool.-_DANGEROUS_FLAGS = {"-exec", "-execdir", "-delete", "-ok", "-okdir", "-fprintf"}+# Flags that turn a search/list tool into an execution, deletion, or file-writing tool.+# The fprint family writes find's output to an arbitrary path; omitting it let a bare+# `find` allowlist entry auto-run `find . -fprint /tmp/exfil.txt`. readonly.py's+# `_FIND_BAD` is the complete copy of this set, so keep the two in step.+_DANGEROUS_FLAGS = {"-exec", "-execdir", "-delete", "-ok", "-okdir", "-fprintf", "-fprint", "-fprint0", "-fls"}def _split_commands(command: str) -> list[str]:diff --git a/tests/test_permissions_risk.py b/tests/test_permissions_risk.pyindex c5619baf..0575f471 100644--- a/tests/test_permissions_risk.py+++ b/tests/test_permissions_risk.py@@ -108,6 +108,20 @@ def test_exec_uses_command_allowlist(tmp_path):assert not asked.allowed and asked.needs_user+def test_allowlisted_find_refuses_output_writing_flags(tmp_path):+ # `find`'s fprint family writes to an arbitrary path. A bare `find` allowlist entry+ # must not auto-run it, exactly as it already refuses -exec/-delete/-fprintf.+ eng = PermissionEngine(workspace_root=tmp_path, allowed_commands=["find"])+ assert eng.evaluate("run_shell", {"command": "find . -name '*.py'"}, None).allowed+ for command in (+ "find . -fprint /tmp/exfil.txt",+ "find . -fprint0 /tmp/exfil.txt",+ "find . -fls /tmp/exfil.txt",+ ):+ d = eng.evaluate("run_shell", {"command": command}, None)+ assert not d.allowed and d.needs_user, command++@pytest.mark.parametrize("command",[