fix: shell path validation false positives and agent config merge
This commit is contained in:
parent
23da4503c1
commit
b9d2cfc1cc
3 changed files with 19 additions and 8 deletions
|
|
@ -53,12 +53,14 @@ func NewAgentInstance(
|
||||||
fallbacks := resolveAgentFallbacks(agentCfg, defaults)
|
fallbacks := resolveAgentFallbacks(agentCfg, defaults)
|
||||||
|
|
||||||
restrict := defaults.RestrictToWorkspace
|
restrict := defaults.RestrictToWorkspace
|
||||||
|
if agentCfg != nil && agentCfg.RestrictToWorkspace != nil {
|
||||||
|
restrict = *agentCfg.RestrictToWorkspace
|
||||||
|
}
|
||||||
readRestrict := restrict && !defaults.AllowReadOutsideWorkspace
|
readRestrict := restrict && !defaults.AllowReadOutsideWorkspace
|
||||||
|
|
||||||
// Compile path whitelist patterns from config.
|
// Compile path whitelist patterns from config.
|
||||||
allowReadPaths := compilePatterns(cfg.Tools.AllowReadPaths)
|
allowReadPaths := compilePatterns(cfg.Tools.AllowReadPaths)
|
||||||
allowWritePaths := compilePatterns(cfg.Tools.AllowWritePaths)
|
allowWritePaths := compilePatterns(cfg.Tools.AllowWritePaths)
|
||||||
|
|
||||||
toolsRegistry := tools.NewToolRegistry()
|
toolsRegistry := tools.NewToolRegistry()
|
||||||
|
|
||||||
if cfg.Tools.IsToolEnabled("read_file") {
|
if cfg.Tools.IsToolEnabled("read_file") {
|
||||||
|
|
|
||||||
|
|
@ -130,13 +130,14 @@ func (m AgentModelConfig) MarshalJSON() ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AgentConfig struct {
|
type AgentConfig struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Default bool `json:"default,omitempty"`
|
Default bool `json:"default,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Workspace string `json:"workspace,omitempty"`
|
Workspace string `json:"workspace,omitempty"`
|
||||||
Model *AgentModelConfig `json:"model,omitempty"`
|
RestrictToWorkspace *bool `json:"restrict_to_workspace,omitempty"`
|
||||||
Skills []string `json:"skills,omitempty"`
|
Model *AgentModelConfig `json:"model,omitempty"`
|
||||||
Subagents *SubagentsConfig `json:"subagents,omitempty"`
|
Skills []string `json:"skills,omitempty"`
|
||||||
|
Subagents *SubagentsConfig `json:"subagents,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SubagentsConfig struct {
|
type SubagentsConfig struct {
|
||||||
|
|
|
||||||
|
|
@ -339,10 +339,18 @@ func (t *ExecTool) guardCommand(command, cwd string) string {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip kernel pseudo-devices that are always safe.
|
||||||
if safePaths[p] {
|
if safePaths[p] {
|
||||||
continue
|
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)
|
rel, err := filepath.Rel(cwdPath, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue