Skip to content
Python

fix: exclude exec-risk tools from session_allow_tools shortcut

Shakti Prasad Mohapatra643054bc055f
diff --git a/coworker/permissions.py b/coworker/permissions.py
index 39eb24b3..e6efe7ea 100644
--- a/coworker/permissions.py
+++ b/coworker/permissions.py
@@ -612,6 +612,7 @@ class PermissionEngine:
honor_session_grants
and tool_name in self.session_allow_tools
and not is_connector
+ and not is_shell
):
return Decision(True, "tool allowed for session")
# Run grant (OPE-136 "Allow for this request"): same checkpoint, shorter life —
diff --git a/coworker/server/manager.py b/coworker/server/manager.py
index 5155b6eb..20e81ef7 100644
--- a/coworker/server/manager.py
+++ b/coworker/server/manager.py
@@ -6445,6 +6445,8 @@ class SessionManager:
engine.permissions.task_rules = task.standing_rules()
for tool in task.name_allowed_tools():
engine.permissions.allow_tool_for_session(tool)
+ for cmd in task.always_allowed_commands:
+ engine.permissions.allow_command_for_session(cmd)
def _build_task_engine(self, task, *, session_id: str) -> TurnEngine:
ag = get_agent(task.agent)
diff --git a/tests/test_tools_permissions.py b/tests/test_tools_permissions.py
index 56e4a14d..7896c84e 100644
--- a/tests/test_tools_permissions.py
+++ b/tests/test_tools_permissions.py
@@ -118,6 +118,22 @@ def test_session_allow_command_sticks(tmp_path):
assert eng.evaluate("run_shell", {"command": "make build"}, None).allowed
+def test_session_allow_tool_does_not_bypass_shell_command_scoping(tmp_path):
+ """A name-only session grant for run_shell must not bypass the command
+ allowlist — the tool-level shortcut is excluded for exec-risk tools so
+ that command-level scoping (_command_allowed / session_allow_commands)
+ still runs. Regression test for issue #296."""
+ eng = PermissionEngine(workspace_root=tmp_path, allowed_commands=["ls"])
+ # Grant run_shell at the tool level for this session.
+ eng.allow_tool_for_session("run_shell")
+ # An allowed command still works.
+ assert eng.evaluate("run_shell", {"command": "ls"}, None).allowed
+ # A disallowed command must still ask, even though the tool itself
+ # was granted for the session.
+ d = eng.evaluate("run_shell", {"command": "rm -rf /"}, None)
+ assert not d.allowed and d.needs_user
+
+
def test_custom_mode_auto_allows_configured_tools(tmp_path):
reg = _registry(tmp_path)
eng = PermissionEngine(