Skip to content

sandbox: complex hand-written shell parsing in safe_command risks bypasses #473

Closed

Description

@euxarist

Problem

splitShellSegments (and related quote/substitution/pipe handling) in the interactive command blocker is a large, hand-written parser:

// internal/sandbox/safe_command.go:480+
func splitShellSegments(command string) []string { ... }  // 100+ lines of quote, $(), `, |, ;, && logic

Used to block dangerous interactive programs (vim, less, tail -f, REPLs, etc.).

Impact

  • High chance of bypass or false negative with unusual quoting, command substitutions, or edge cases.
  • Could allow the agent to hang on an editor/pager/REPL until the per-command timeout.
  • Very hard to audit and maintain.

Suggested fix

  • Replace or augment with a well-tested shell parser (e.g. mvdan.cc/sh/v3/syntax which is already used elsewhere in the codebase for prefix matching).
  • Or significantly simplify + add many more adversarial test cases.
  • Document the limitations clearly.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions