picoclaw/pkg/tools
Hakancan 6b72326be1
fix: safety guard incorrectly blocks commands with URLs (#1254)
* fix: safety guard incorrectly blocks commands with URLs

The absolutePathPattern regex was matching URL path components like
//github.com as file system paths, causing commands containing URLs
to be incorrectly blocked by the workspace restriction safety guard.

For example, 'agent-browser open https://github.com' would be blocked
because //github.com was treated as an absolute file path outside
the working directory.

The fix adds a check to skip any path match that starts with '//',
as these are URL path components, not file system paths.

Fixes #1203

* fix: handle file:// URIs correctly in safety guard

The previous fix skipped all paths starting with '//', which incorrectly
also skipped file:// URIs that could escape the workspace sandbox.

Changes:
- Only skip '//' paths when preceded by web URL schemes (http:, https:, ftp:, etc.)
- file:// URIs are now properly checked against workspace boundaries
- Added TestShellTool_FileURISandboxing to verify the fix

Fixes security issue raised by @alexhoshina in PR #1254

* style: fix gofumpt formatting

* fix(safety-guard): use exact match position to prevent URL exemption bypass

Using strings.Index(cmd, raw) always returned the first occurrence of the
matched substring, allowing a bypass where the same //path appeared both
inside a URL and as a standalone shell path (e.g. echo https://etc/passwd
&& cat //etc/passwd would skip the second match).

Switch to FindAllStringIndex so each match is evaluated at its actual
position in the command string.

Adds TestShellTool_URLBypassPrevented to cover the exploit scenario.
2026-03-13 17:16:05 +08:00
..
base.go fix: eliminate data races on shared tool instances (#1080) 2026-03-05 09:57:33 +08:00
cron.go fix(security): harden unauthenticated tool-exec paths (#1360) 2026-03-11 19:22:20 +08:00
cron_test.go fix(security): harden unauthenticated tool-exec paths (#1360) 2026-03-11 19:22:20 +08:00
edit.go fix(tools): allow /dev/null redirection and add read/write sandbox split (#967) 2026-03-02 12:22:02 +08:00
edit_test.go fix(security): workspace sandbox avoid time-of-check/time-of-use (TOCTOU) races (#464) 2026-02-23 20:09:53 +11:00
filesystem.go fix lint 2026-03-09 11:02:31 +01:00
filesystem_test.go refined code 2026-03-09 09:32:21 +01:00
i2c.go refactor: cleanup dead code and turn on dead code detection in CI (#515) 2026-02-24 21:52:25 +08:00
i2c_linux.go feat(linter): Fix govet linter 2026-02-20 22:35:16 +02:00
i2c_other.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
mcp_tool.go fix: improve MCP tool name collision safety and registry overwrite warning 2026-03-01 12:00:26 +08:00
mcp_tool_test.go chore: fix lint issues in mcp and agent packages 2026-03-01 08:53:13 +08:00
message.go fix: eliminate data races on shared tool instances (#1080) 2026-03-05 09:57:33 +08:00
message_test.go fix: eliminate data races on shared tool instances (#1080) 2026-03-05 09:57:33 +08:00
registry.go feat(mcp): tool search tools (#1243) 2026-03-09 18:21:49 +01:00
registry_test.go fix: eliminate data races on shared tool instances (#1080) 2026-03-05 09:57:33 +08:00
result.go feat(channels): add MediaSender optional interface for outbound media 2026-02-23 03:10:57 +08:00
result_test.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
search_tool.go feat(mcp): tool search tools (#1243) 2026-03-09 18:21:49 +01:00
search_tools_test.go feat(mcp): tool search tools (#1243) 2026-03-09 18:21:49 +01:00
send_file.go feat(feishu,tools): add outbound media delivery via send_file tool (#1156) 2026-03-06 19:42:52 +08:00
send_file_test.go feat(feishu,tools): add outbound media delivery via send_file tool (#1156) 2026-03-06 19:42:52 +08:00
shell.go fix: safety guard incorrectly blocks commands with URLs (#1254) 2026-03-13 17:16:05 +08:00
shell_process_unix.go fix(exec): terminate process tree on timeout 2026-02-18 02:01:29 +08:00
shell_process_windows.go fix(exec): terminate process tree on timeout 2026-02-18 02:01:29 +08:00
shell_test.go fix: safety guard incorrectly blocks commands with URLs (#1254) 2026-03-13 17:16:05 +08:00
shell_timeout_unix_test.go fix(exec) fail close on invalid deny pattern (#781) 2026-02-28 16:24:26 +08:00
skills_install.go refactor(pkg): move atomic file write to dedicated fileutil package 2026-02-24 23:57:13 +08:00
skills_install_test.go feat(fmt): Fix formatting 2026-02-20 20:03:11 +02:00
skills_search.go feat(fmt): Fix formatting 2026-02-20 20:03:11 +02:00
skills_search_test.go feat(fmt): Fix formatting 2026-02-20 20:03:11 +02:00
spawn.go fix: eliminate data races on shared tool instances (#1080) 2026-03-05 09:57:33 +08:00
spawn_test.go fix: background task results silently dropped 2026-03-05 13:07:17 +01:00
spi.go refactor: cleanup dead code and turn on dead code detection in CI (#515) 2026-02-24 21:52:25 +08:00
spi_linux.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
spi_other.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
subagent.go fix: background task results silently dropped 2026-03-05 13:07:17 +01:00
subagent_tool_test.go fix: background task results silently dropped 2026-03-05 13:07:17 +01:00
toolloop.go feat: execute LLM tool calls in parallel for faster response (#1070) 2026-03-04 17:17:28 +08:00
types.go feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
web.go enhance skill installer (#1252) 2026-03-13 14:04:02 +08:00
web_test.go enhance skill installer (#1252) 2026-03-13 14:04:02 +08:00