Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(exec): refine format command deny pattern to allow URL parameters
ykstartf97b960433dd
diff --git a/nanobot/agent/tools/shell.py b/nanobot/agent/tools/shell.pyindex d1ad36359..3412a11a7 100644--- a/nanobot/agent/tools/shell.py+++ b/nanobot/agent/tools/shell.py@@ -106,7 +106,7 @@ class ExecTool(Tool):r"\brm\s+-[rf]{1,2}\b", # rm -r, rm -rf, rm -frr"\bdel\s+/[fq]\b", # del /f, del /qr"\brmdir\s+/s\b", # rmdir /s- r"(?:^|[;&|]\s*)format\b", # format (as standalone command only)+ r"(?:^|[;&|]\s*)format(?!=)\b", # format (as standalone command only)r"\b(mkfs|diskpart)\b", # disk operationsr"\bdd\s+if=", # ddr">\s*/dev/sd", # write to diskdiff --git a/tests/tools/test_exec_security.py b/tests/tools/test_exec_security.pyindex 844d535c0..fb6731f03 100644--- a/tests/tools/test_exec_security.py+++ b/tests/tools/test_exec_security.py@@ -243,3 +243,44 @@ def test_exec_still_blocks_real_outside_path_via_redirect(tmp_path):blocked = tool._guard_command("echo pwn > /etc/issue", str(workspace))assert blocked is not Noneassert "path outside working dir" in blocked+++# --- format command blocking -----------------------------------------------+++ "command",+ [+ "format C: /q",+ "format D: /fs:ntfs",+ "&& format",+ "| format",+ "&format",+ ";format",+ "|format",+ ],+)+def test_exec_blocks_format_command(command):+ """The Windows ``format`` disk command must be denied."""+ tool = ExecTool()+ result = tool._guard_command(command, "/tmp")+ assert result is not None+ assert "deny pattern filter" in result.lower()+++ "command",+ [+ # URL parameter &format= must NOT be blocked (regression).+ 'curl -s "wttr.in/xxx?lang=zh&format=%l:+%c+%t+%h+%w&1"',+ 'curl -s "wttr.in/xxx?format=%l:+%c+%t+%h+%w&1"',+ # format as a non-command word in a normal argument.+ "echo format",+ "echo reformat",+ ],+)+def test_exec_allows_format_in_url_and_args(command):+ """``format`` inside URL parameters or as a non-command arg must be allowed."""+ tool = ExecTool()+ result = tool._guard_command(command, "/tmp")+ assert result is None