fix: shell path validation false positives and agent config merge

This commit is contained in:
xaxadobit 2026-03-05 21:59:36 -03:00
parent 23da4503c1
commit b9d2cfc1cc
3 changed files with 19 additions and 8 deletions

View file

@ -53,12 +53,14 @@ func NewAgentInstance(
fallbacks := resolveAgentFallbacks(agentCfg, defaults)
restrict := defaults.RestrictToWorkspace
if agentCfg != nil && agentCfg.RestrictToWorkspace != nil {
restrict = *agentCfg.RestrictToWorkspace
}
readRestrict := restrict && !defaults.AllowReadOutsideWorkspace
// Compile path whitelist patterns from config.
allowReadPaths := compilePatterns(cfg.Tools.AllowReadPaths)
allowWritePaths := compilePatterns(cfg.Tools.AllowWritePaths)
toolsRegistry := tools.NewToolRegistry()
if cfg.Tools.IsToolEnabled("read_file") {

View file

@ -130,13 +130,14 @@ func (m AgentModelConfig) MarshalJSON() ([]byte, error) {
}
type AgentConfig struct {
ID string `json:"id"`
Default bool `json:"default,omitempty"`
Name string `json:"name,omitempty"`
Workspace string `json:"workspace,omitempty"`
Model *AgentModelConfig `json:"model,omitempty"`
Skills []string `json:"skills,omitempty"`
Subagents *SubagentsConfig `json:"subagents,omitempty"`
ID string `json:"id"`
Default bool `json:"default,omitempty"`
Name string `json:"name,omitempty"`
Workspace string `json:"workspace,omitempty"`
RestrictToWorkspace *bool `json:"restrict_to_workspace,omitempty"`
Model *AgentModelConfig `json:"model,omitempty"`
Skills []string `json:"skills,omitempty"`
Subagents *SubagentsConfig `json:"subagents,omitempty"`
}
type SubagentsConfig struct {

View file

@ -339,10 +339,18 @@ func (t *ExecTool) guardCommand(command, cwd string) string {
continue
}
// Skip kernel pseudo-devices that are always safe.
if safePaths[p] {
continue
}
// Only validate paths that actually exist on the filesystem.
// This prevents false positives from regex capturing non-path strings
// like escaped newlines (\n -> /n) or repo arguments (gh --repo owner/repo).
if _, err := os.Stat(p); os.IsNotExist(err) {
continue
}
rel, err := filepath.Rel(cwdPath, p)
if err != nil {
continue