Skip to content

fix: the sandbox guard reads quotes and heredocs before cutting a command - #101

Merged
alexeybe1kin merged 1 commit into
mainfrom
fix/guard-quotes
Nov 13, 2026
Merged

alexeybe1kin merged 1 commit into
mainfrom
fix/guard-quotes

Conversation

@alexeybe1kin

Copy link
Copy Markdown
Collaborator

Hunt toolgate-5 F9. guard() cut the command with a regex on ; | & ( ) { }, newlines, backticks and $(, ignoring quotes. Harmless commands were refused with "Refused: shutting down": grep -E "error|halt|panic" log, echo "done; reboot now", or a heredoc that writes a file containing shutdown().

_Scanner (toolgate/sandbox/validation.py) now cuts the line the way the shell reads it:

  • Single quotes are data.
  • Double quotes are data, except $(...) and backticks inside them, which are still separate commands.
  • \ escapes the next character.
  • A heredoc body is data. For an unquoted delimiter its $(...) and backticks are still checked; a quoted delimiter (<<'EOF') makes the whole body data. <<- strips tabs, and <<< is not a heredoc.
  • Text after the closing delimiter is commands again.

The per-command checks are unchanged, and FORK_BOMB and DEVICE_WRITE still run on the raw text. Known limits are unchanged from main: bash -c "reboot" passes (it did before), and the container stays the boundary.

Tests (toolgate/tests/test_sandbox_validation.py, TestGuardQuotes): 9 commands that must pass (7 of them are refused on main), and 10 that must still be refused, among them echo "$(reboot)", backticks, unquoted heredoc substitution, a command after a heredoc, and "reboot". Local: the validation, runner and guard suites pass (119 passed, 1 skipped). ruff, types and sizes ok.

…mand

It cut the command on ; | & ( ) { } and newlines with no quote awareness, so
grep -E "error|halt" log, echo "done; reboot now" or a heredoc writing a
line shutdown() were refused as shutting down (hunt toolgate-5 F9). A small
scanner now keeps quoted text and heredoc bodies as data, while $(...) and
backticks are still checked inside double quotes and unquoted heredocs.
@alexeybe1kin
alexeybe1kin merged commit 8fcbb85 into main Nov 13, 2026
4 checks passed
@alexeybe1kin
alexeybe1kin deleted the fix/guard-quotes branch November 13, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant