Commit graph

35 commits

Author SHA1 Message Date
Keith Patrick
b9dd313454 Document PICOCLAW_* env vars in exec tool description 2026-03-09 01:34:43 +00:00
Keith Patrick
64fc4a82d0 Add PICOCLAW_AGENT_WORKSPACE env var
- Pass workingDir to WithPicoclawEnvVars
- Add PICOCLAW_AGENT_WORKSPACE for child processes to know their workspace
2026-03-09 01:28:24 +00:00
Keith Patrick
347aade2fb Add PICOCLAW_* env vars to child processes
- Ensure PICOCLAW_HOME, PICOCLAW_CONFIG, PICOCLAW_EXE, PICOCLAW_SERVICE_NAME
  are passed to exec'd child processes
- Remove hardcoded PICOCLAW_* from DefaultEnvAllowlist (now handled dynamically)
2026-03-09 01:03:24 +00:00
Keith Patrick
bf7279e2a1 feat(security): add config env_allowlist support 2026-03-08 23:04:40 +00:00
Keith Patrick
7cc6ed435b feat(security): add env parameter to exec tool schema
- Add env parameter to tool definition for LLM
- Document blocked vars in description
2026-03-08 20:11:47 +00:00
Keith Patrick
b43acf4aba feat(security): add config env_set support
- Add EnvSet field to ExecConfig for config file
- Merge env_set into cachedEnv at ExecTool init
- LLM env overrides still checked against blocklist
2026-03-08 19:55:11 +00:00
Keith Patrick
1b0393fed3 feat(security): add LLM env param support with blocklist filtering
- Parse 'env' param from LLM tool call
- Apply blocklist filtering to prevent LLM from overriding sensitive vars
- Pass to BuildSanitizedEnv with extraEnv parameter
2026-03-08 19:44:14 +00:00
Keith Patrick
b4e18abcb8 feat(security): add environment sanitization for shell execution
- Add BuildSanitizedEnv() with default allowlist (PATH, HOME, USER, etc)
- Add PICOCLAW_* vars to allowlist for config propagation
- Add LLMBlocklist for vars LLM cannot override
- Cache sanitized env at ExecTool init, pass to exec.Cmd
- Add tests and docs

Part of PR1: Environment Sanitization for External Execution
2026-03-08 19:41:12 +00:00
mosir
d0888ca429 refactor(tools): remove redundant kill -9 pattern 2026-03-06 18:34:46 +08:00
mosir
e62021909b Merge branch 'sipeed:main' into fix/reload-config-selfkill-guard 2026-03-06 18:27:46 +08:00
wangyanfu2
d161cff778 fix(tools): make exec tool timeout configurable via config
Add TimeoutSeconds field to ExecConfig so the shell command execution
timeout can be configured instead of being hardcoded to 60s.

- Add TimeoutSeconds int field to ExecConfig in pkg/config/config.go
  with json/env tags (PICOCLAW_TOOLS_EXEC_TIMEOUT_SECONDS)
- Set default value of 60s in DefaultConfig() in pkg/config/defaults.go
- Read TimeoutSeconds from config in NewExecToolWithConfig() in
  pkg/tools/shell.go; falls back to 60s when value is 0 or unset
2026-03-06 09:51:58 +08:00
mosir
2b7e3191b1 fix(exec): block kill command pattern in safety guard 2026-03-05 12:45:53 +08:00
Huang Rui
fbc8de422e fix(tools): allow /dev/null redirection and add read/write sandbox split (#967)
* fix(tools): allow /dev/null redirection and add read/write sandbox split

- Remove deny pattern that incorrectly blocked redirects to /dev/null
- Expand block device write pattern to cover nvme, mmcblk, vd, xvd,
  hd, loop, dm-, md, sr and nbd in addition to sd
- Add safe path whitelist for kernel pseudo-devices so workspace path
  check does not reject /dev/null, /dev/zero, /dev/random, /dev/urandom,
  /dev/stdin, /dev/stdout and /dev/stderr
- Add allow_read_outside_workspace config option (default true) so file
  read and list tools are unrestricted while write tools stay sandboxed

Closes https://github.com/sipeed/picoclaw/issues/964
Closes https://github.com/sipeed/picoclaw/issues/965

Signed-off-by: Huang Rui <vowstar@gmail.com>

* feat(tools): add configurable allow patterns and path whitelists

- Add custom_allow_patterns to exec config so users can exempt specific
  commands from deny pattern checks
- Add allow_read_paths and allow_write_paths regex lists to tools config
  for whitelisting specific paths outside the workspace
- Introduce whitelistFs that wraps sandboxFs and falls through to hostFs
  for paths matching whitelist patterns
- Use variadic constructor signatures to keep backward compatibility

Suggested-by: lxowalle
Signed-off-by: Huang Rui <vowstar@gmail.com>

---------

Signed-off-by: Huang Rui <vowstar@gmail.com>
2026-03-02 12:22:02 +08:00
Tong Niu
9d5ef3e314 fix(pkg):do regex precompile insteadd on the fly (#911)
* fix(pkg/providers):do regex precompile insteadd on the fly

* fix(providers): replace HTTP-specific regex with standalone status code matcher

The precompiled HTTP regex used uppercase "HTTP" which never matched
because ClassifyError lowercases the input. Replace it with a
case-insensitive word-boundary pattern that matches any standalone
3-digit status code (300-599), which also subsumes the HTTP/x.x case.

Add test case for standalone status code extraction.

* fix(providers): restore http regex and add standalone status code matcher

Restore the http-prefixed regex (without unnecessary (?i) flag since
input is already lowercased by ClassifyError) as a mid-priority pattern
to reduce false positives. Add a standalone word-boundary matcher as a
fallback for bare status codes like "429". Fix test to use lowercased
input matching the actual calling convention.

* perf(tools): move path regex compilation from per-call to package init

The path regex in guardCommand was compiled on every call. Hoist it
to a package-level var (absolutePathPattern) alongside defaultDenyPatterns
in a single var block, so it is compiled once at init time.

* style(tools): move inline comment to fix golines formatting error
2026-03-01 23:06:31 +11:00
Mauro
a1d6a1227d fix(exec) fail close on invalid deny pattern (#781)
* fix(exec) fail close on invalid deny pattern

* fix: error check

* resolve conflicts
2026-02-28 16:24:26 +08:00
Kai Xia
bcc13d1f9b enable wastedassign
Finds wasted assignment statements.

Signed-off-by: Kai Xia <kaix+github@fastmail.com>
2026-02-25 21:31:07 +11:00
Goksu Ceylan
614d28d8c5 fix(security): ensure custom deny patterns extend defaults instead of replacing them (#479)
* fix (security): custom deny patterns denying default patterns

* fix formatting whitespace
2026-02-24 09:02:44 +11:00
Goksu Ceylan
d86043d1eb fix (security): ExecTool working_dir sandbox escape (#478)
* fix (security) Shell working_dir bypass

* Feedback from @mengzhuo & Discord
- reuse internal security package to validate path
- add tests for workspace escape
2026-02-21 08:15:46 +08:00
Artem Yadelskyi
af01973d03 Merge branch 'main' into fix-formatting
# Conflicts:
#	cmd/picoclaw/main.go
#	pkg/agent/context.go
#	pkg/agent/loop.go
#	pkg/channels/dingtalk.go
#	pkg/channels/feishu_64.go
#	pkg/channels/line.go
#	pkg/channels/manager.go
#	pkg/config/config.go
#	pkg/migrate/migrate_test.go
#	pkg/providers/anthropic/provider_test.go
#	pkg/providers/claude_provider_test.go
#	pkg/providers/http_provider.go
#	pkg/providers/openai_compat/provider.go
#	pkg/providers/protocoltypes/types.go
#	pkg/providers/types.go
2026-02-20 20:02:53 +02:00
Meng Zhuo
0909b7520d Merge pull request #378 from lunareed720/fix/exec-timeout-process-tree
fix(exec): kill child process tree on timeout to prevent orphaned tasks
2026-02-20 23:32:05 +08:00
Artem Yadelskyi
9ac60c60f1 feat(fmt): Run formatters 2026-02-18 21:48:23 +02:00
Artem Yadelskyi
a6019b11ef feat(linters): Fix linter 2026-02-18 16:24:55 +02:00
lxowalle
ee3375a493 feat: Support modifying the command filtering list of the exec tool (#410) 2026-02-18 19:31:15 +08:00
lxowalle
e2e81ee167 fix: Add comprehensive command injection and system abuse prevention patterns (#401)
* Add comprehensive command injection and system abuse prevention patterns

* fix: Container running as root
2026-02-18 15:33:34 +08:00
Luna Reed
a145786aad fix(exec): terminate process tree on timeout 2026-02-18 02:01:29 +08:00
yinwm
9a6dec8cb6 refactor(shell): interpret zero timeout as unlimited execution
Replace unconditional WithTimeout usage with conditional context creation
based on timeout configuration. Zero values now bypass timeout enforcement,
using WithCancel for graceful cancellation while preserving existing timeout
behavior for positive values. Simplifies CronTool initialization by removing
unnecessary conditional timeout assignment.
2026-02-17 21:10:20 +08:00
Meng Zhuo
c1fa579d9b misc: fmt code 2026-02-13 17:51:47 +08:00
yinwm
538aaacea1 Merge upstream/main into ralph/tool-result-refactor
Resolved conflicts:
- pkg/heartbeat/service.go: merged both 'started' field and 'onHeartbeatWithTools'
- pkg/tools/edit.go: use validatePath() with ToolResult return
- pkg/tools/filesystem.go: fixed return values to use ToolResult
- cmd/picoclaw/main.go: kept active setupCronTool, fixed toolsPkg import
- pkg/tools/cron.go: fixed Execute return value handling

Fixed tests for new function signatures (NewEditFileTool, NewAppendFileTool, NewExecTool)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 01:00:26 +08:00
Satyam Tiwari
759f4357f7 Merge branch 'main' of https://github.com/SatyamDevv/picoclaw 2026-02-12 20:25:31 +05:30
Satyam Tiwari
89978073b5 Enhance CronTool to support executing shell commands and update job handling 2026-02-12 20:21:49 +05:30
mxrain
22d0eac992 fix: use cmd /c on Windows for shell command execution
The exec tool was hardcoded to use 'sh -c' which doesn't exist on Windows,
causing all tool calls to fail silently in gateway mode.
2026-02-12 22:38:47 +08:00
yinwm
419af2f745 feat: US-002 - Modify Tool interface to return *ToolResult
- Update all Tool implementations to return *ToolResult instead of (string, error)
- ShellTool: returns UserResult for command output, ErrorResult for failures
- SpawnTool: returns NewToolResult on success, ErrorResult on failure
- WebTool: returns ToolResult with ForUser=content, ForLLM=summary
- EditTool: returns SilentResult for silent edits, ErrorResult on failure
- FilesystemTool: returns SilentResult/NewToolResult for operations, ErrorResult on failure
- Temporarily disable cronTool in main.go (will be re-enabled in US-016)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 19:28:56 +08:00
RinZ27
61eea1412d Enforce workspace boundaries with configurable restriction option
Implemented a unified path validation helper to ensure filesystem operations stay within the designated workspace. This now supports a 'restrict_to_workspace' option in config.json (enabled by default) to allow flexibility for specific environments while maintaining a secure default posture. I've updated read_file, write_file, list_dir, append_file, edit_file, and exec tools to respect this setting and included tests for both restricted and unrestricted modes.
2026-02-12 12:46:32 +07:00
yinwm
724053b865 Add memory system, dynamic tool loading, and fix logging issues
- Add MemoryStore for persistent long-term and daily notes
- Add dynamic tool summary generation in system prompt
- Fix YAML frontmatter parsing for nanobot skill format
- Add GetSummaries() method to ToolRegistry
- Fix DebugCF logging to use structured metadata
- Improve web_search and shell tool descriptions
2026-02-11 00:14:33 +08:00
lxowalle
e17693b17c * First commit 2026-02-09 19:20:19 +08:00