fix: harden runtime against panics/races, close path-traversal and fail-open gaps

- Runtime.Run rejects concurrent invocations instead of racing on shared state; panics in tools, hooks, and permission checkers are recovered and surfaced as errors/denials instead of crashing the loop
- AgentSpec.Loop now actually overrides RuntimeDeps.AgentLoop per-agent, as documented
- session.Store validates agent ID / session key as single path components, preventing traversal outside the session directory
- ValidatePathInWorkDir resolves symlinks on the target itself, not just its parent, closing a workspace-escape gap
- bash tool now fails closed on an unrecognized ExecPolicy.Level instead of allowing everything
- browser tool rejects unknown actions instead of silently no-op'ing

Bump README to v0.3.4 and document the AgentSpec.Loop override semantics.
This commit is contained in:
sausheong committed 2026-08-02 10:14:20 +08:00
1 parent 445614757b
commit eb4fa67976
15 files changed
+421 -37

No files matched your search

+12 -3
View File
@@ -291,14 +291,24 @@ func ValidatePathInWorkDir(path, workDir string) error {
realWork = absWork // workspace might not exist yet
}
// For the target path, resolve the parent directory (file may not exist yet)
// Resolve an existing target itself so a final-component symlink cannot
// escape the workspace. For a path that does not exist yet, resolve its
// parent directory instead so callers can safely create a new file.
realPath, targetErr := filepath.EvalSymlinks(absPath)
if targetErr == nil {
if !strings.HasPrefix(realPath, realWork+string(filepath.Separator)) && realPath != realWork {
return fmt.Errorf("path %q is outside workspace %q", path, workDir)
}
return nil
}
parentDir := filepath.Dir(absPath)
realParent, err := filepath.EvalSymlinks(parentDir)
if err != nil {
// Parent doesn't exist — use the unresolved absolute path
realParent = parentDir
}
realPath := filepath.Join(realParent, filepath.Base(absPath))
realPath = filepath.Join(realParent, filepath.Base(absPath))
if !strings.HasPrefix(realPath, realWork+string(filepath.Separator)) && realPath != realWork {
return fmt.Errorf("path %q is outside workspace %q", path, workDir)
@@ -313,4 +323,3 @@ func ValidatePathInWorkDir(path, workDir string) error {
func RegisterCron(reg *Registry, agentID string, scheduler JobScheduler) {
reg.Register(&CronTool{AgentID: agentID, Scheduler: scheduler})
}