Repository navigation
Conversation
`_is_safe_command` searched the raw command line for blocklist substrings,
so anything that changed the spelling of a blocked command got through.
The surrounding-space patterns made this easy to defeat: an extra space,
a tab, a leading path, or chaining onto another command was enough.
Measured against the current blocklist, these were all accepted:
rm -rf /
sudo<TAB>rm -rf /
kill -9 -1
echo hi;rm -rf /
echo hi&&rm -rf /
/bin/rm -rf /
sh -c "rm -rf /"
rm --recursive --force /x
The command is now split on `&&`, `||`, `;`, `|` and newlines, each piece
is tokenised with `shlex`, and the program name is compared without its
directory. Flags are matched as a set, so every ordering of `-r` and `-f`
counts as recursive force, and a `sh -c` payload is checked as its own
command line.
The blocklist itself is unchanged: `sudo` stays blocked outright, and
`rm -rf build/` stays blocked exactly as before. No command that was
rejected before is accepted now.
Linked issuesChecked at commit 58627bc #11039 [Bug] shell blocklist rejects rm -rf under /tmp because it is a raw substring match · 1 of 2 met
|
There was a problem hiding this comment.
Hey - I've found 17 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="86" />
<code_context>
+# Separators that end one shell command and start the next.
+_SHELL_SEPARATORS = re.compile(r"&&|\|\||[;|\n\r]")
+
+
</code_context>
<issue_to_address>
**Blocked commands run after `&`**
When a command uses a single `&` to start a blocked command, `_SHELL_SEPARATORS` leaves both commands in one segment, so `shlex.split` checks only the first command and the shell runs the blocked command.
Parse single-ampersand command separators and check each resulting command before execution.
</issue_to_address>
### Comment 2
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="125-126" />
<code_context>
+ return False
+
+ # Compare the bare program name so `/bin/rm` and `rm` are the same tool.
+ name = argv[0].replace("\\", "/").rsplit("/", 1)[-1].lower()
+ flags = argv[1:]
+
+ # `sudo` is blocked outright, so a tab or extra space around it must not
</code_context>
<issue_to_address>
**Wrapped blocked commands run**
When a blocked executable is preceded by `env`, a leading environment assignment, or a wrapper that invokes `sudo`, `_is_safe_command` checks only the first parsed token, so it misses the wrapped executable and allows the shell to run the blocked command.
Resolve leading assignments and command wrappers before applying the executable and argument checks.
Also at `astrbot/core/astr_agent_runtime/computer/booters/local.py:131`.
</issue_to_address>
### Comment 3
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="107-109" />
<code_context>
+ if any(pat in cmd for pat in _BLOCKED_COMMAND_PATTERNS):
+ return False
+
+ for segment in _SHELL_SEPARATORS.split(command):
+ try:
+ argv = shlex.split(segment, posix=True)
+ except ValueError:
+ # Unbalanced quotes: fall back to whitespace splitting so that a
</code_context>
<issue_to_address>
**Substitutions run unchecked commands**
When a command substitution or backtick expression contains a blocked command, `shlex.split` treats the substitution as an argument to the outer command, so `_is_safe_command` checks only that outer command and the shell executes the blocked command; the same unchecked path occurs when the command also uses a single `&`.
Inspect and validate commands inside substitutions and backticks, as well as commands separated by single `&`.
Also at `astrbot/core/astr_agent_runtime/computer/booters/local.py:86`, `astrbot/core/astr_agent_runtime/computer/booters/local.py:125-126`.
</issue_to_address>
### Comment 4
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="156-158" />
<code_context>
+ "powershell",
+ "pwsh",
+ }:
+ if "-c" in flags:
+ index = flags.index("-c")
+ if index + 1 >= len(flags) or not _is_safe_command(flags[index + 1]):
+ return False
+ continue
</code_context>
<issue_to_address>
**Combined shell flags bypass payload checks**
When a shell receives its inline payload through a combined short option or a platform-specific command option, `_is_safe_command` recognizes only an exact `-c` token, so it skips payload validation and the nested shell runs the blocked command.
Recognize supported inline-payload options, including combined short options and PowerShell command options, and validate their payloads.
Also at `astrbot/core/astr_agent_runtime/computer/booters/local.py:107-110`.
</issue_to_address>
### Comment 5
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="140-142" />
<code_context>
+ )
+ long_flags = {f for f in flags if f.startswith("--")}
+ recursive = "r" in short or "R" in short or "--recursive" in long_flags
+ forced = "f" in short or "--force" in long_flags
+ if recursive and forced:
+ return False
+
+ if name in {"kill", "killall", "pkill"} and "-9" in flags:
</code_context>
<issue_to_address>
**Recursive removal runs unchecked**
When an `rm` command uses recursive flags without a force flag, the recursive-removal check requires both recursive and force flags, so `rm -r /home/user` passes and deletes files.
Reject recursive `rm` commands even when they do not include a force flag.
</issue_to_address>
### Comment 6
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="144-145" />
<code_context>
+ if recursive and forced:
+ return False
+
+ if name in {"kill", "killall", "pkill"} and "-9" in flags:
+ return False
+
+ if name == "dd" and any(f.lower().startswith("if=") for f in flags):
</code_context>
<issue_to_address>
**`killall` commands terminate processes**
When `killall` is followed by a tab or invoked by an absolute path without `-9`, the raw pattern misses the whitespace or path prefix, and the parsed check rejects `killall` only when `-9` is present, so the command passes and terminates processes.
Reject `killall` based on its parsed executable name regardless of its path, argument separator, or flags.
Also at `astrbot/core/astr_agent_runtime/computer/booters/local.py:125`.
</issue_to_address>
### Comment 7
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="125" />
<code_context>
+ return False
+
+ # Compare the bare program name so `/bin/rm` and `rm` are the same tool.
+ name = argv[0].replace("\\", "/").rsplit("/", 1)[-1].lower()
+ flags = argv[1:]
+
</code_context>
<issue_to_address>
**Path-based blocked utilities run**
When a blocklisted utility such as `shutdown`, `reboot`, or `mkfs` is invoked by an absolute path, the parsed checks do not block these utilities, and the raw patterns miss their path-prefixed names, so the commands run.
Apply the blocklist to the parsed executable basename and add token-based checks for these utilities.
Also at `astrbot/core/astr_agent_runtime/computer/booters/local.py:133`.
</issue_to_address>
### Comment 8
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="136-139" />
<code_context>
+ if name == "rm":
+ # Any recursive forced removal, however the flags are grouped.
+ short = "".join(
+ f[1:] for f in flags if f.startswith("-") and not f.startswith("--")
+ )
+ long_flags = {f for f in flags if f.startswith("--")}
+ recursive = "r" in short or "R" in short or "--recursive" in long_flags
+ forced = "f" in short or "--force" in long_flags
+ if recursive and forced:
</code_context>
<issue_to_address>
**Flag-like filenames are rejected**
When an `rm` command uses `--` before filenames such as `-r` and `-f`, the flag scan continues past `--` and treats filenames as options, so `_is_safe_command` rejects a valid file removal.
Stop scanning `rm` options after the `--` token.
</issue_to_address>
### Comment 9
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="86" />
<code_context>
+# Separators that end one shell command and start the next.
+_SHELL_SEPARATORS = re.compile(r"&&|\|\||[;|\n\r]")
+
+
</code_context>
<issue_to_address>
**Quoted separators reject harmless commands**
When quoted command text contains a separator followed by text resembling a blocked command, `_SHELL_SEPARATORS.split` treats separators inside quoted arguments as command boundaries, so the resulting fragments trigger the blocklist and harmless commands are rejected.
Split commands using shell-aware parsing that ignores separators inside quoted arguments.
Also at `astrbot/core/astr_agent_runtime/computer/booters/local.py:118`, `astrbot/core/astr_agent_runtime/computer/booters/local.py:120`.
</issue_to_address>
### Comment 10
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="104" />
<code_context>
+ """
cmd = f" {command.strip().lower()} "
- return not any(pat in cmd for pat in _BLOCKED_COMMAND_PATTERNS)
+ if any(pat in cmd for pat in _BLOCKED_COMMAND_PATTERNS):
+ return False
+
</code_context>
<issue_to_address>
**Quoted blocklist text is rejected**
When harmless quoted text contains a blocked phrase with the pattern’s surrounding spaces, the whole-line substring check matches text inside a quoted argument before tokenization, so the caller rejects a harmless command.
Apply blocklist checks to parsed commands and arguments rather than raw quoted text.
</issue_to_address>
### Comment 11
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="138-140" />
<code_context>
+ short = "".join(
+ f[1:] for f in flags if f.startswith("-") and not f.startswith("--")
+ )
+ long_flags = {f for f in flags if f.startswith("--")}
+ recursive = "r" in short or "R" in short or "--recursive" in long_flags
+ forced = "f" in short or "--force" in long_flags
+ if recursive and forced:
+ return False
</code_context>
<issue_to_address>
**Abbreviated removal flags bypass check**
When the command uses GNU `rm` with unambiguous abbreviations of `--recursive` and `--force`, gNU `rm` accepts unambiguous long-option abbreviations such as `--rec` and `--for`, but the checker requires exact strings in `long_flags`; `rm --rec --for /` therefore passes and removes files recursively.
Recognize supported long-option abbreviations when checking `rm` flags, or otherwise reject abbreviated forms of the dangerous options.
</issue_to_address>
### Comment 12
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="140" />
<code_context>
+ )
+ long_flags = {f for f in flags if f.startswith("--")}
+ recursive = "r" in short or "R" in short or "--recursive" in long_flags
+ forced = "f" in short or "--force" in long_flags
+ if recursive and forced:
+ return False
</code_context>
<issue_to_address>
**PowerShell removal flags evade blocking**
When a Windows PowerShell command uses the `rm` alias with its case-insensitive `-Recurse` and `-Force` parameters, the flag check is case-sensitive, so `rm -Recurse -Force C:\some-dir` sets `recursive` but not `forced`; PowerShell treats those parameter names case-insensitively and runs the recursive forced removal.
Handle PowerShell aliases and parameter semantics separately from POSIX short-option parsing.
</issue_to_address>
### Comment 13
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="86" />
<code_context>
+# Separators that end one shell command and start the next.
+_SHELL_SEPARATORS = re.compile(r"&&|\|\||[;|\n\r]")
+
+
</code_context>
<issue_to_address>
**Line continuation bypasses blocking**
When a POSIX command uses a backslash-newline continuation between blocked flags, the split separates the physical newline before the shell processes the backslash continuation; tokenization of the first fragment fails and falls back to whitespace splitting, so neither fragment is recognized as recursive forced removal. `_is_safe_command` accepts the command, and the shell joins it into `rm -rf /`.
Normalize shell line continuations before checking, or use parsing that preserves the shell’s continuation semantics.
</issue_to_address>
### Comment 14
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="133-142" />
<code_context>
+ if name == "sudo":
+ return False
+
+ if name == "rm":
+ # Any recursive forced removal, however the flags are grouped.
+ short = "".join(
+ f[1:] for f in flags if f.startswith("-") and not f.startswith("--")
+ )
+ long_flags = {f for f in flags if f.startswith("--")}
+ recursive = "r" in short or "R" in short or "--recursive" in long_flags
+ forced = "f" in short or "--force" in long_flags
+ if recursive and forced:
+ return False
+
+ if name in {"kill", "killall", "pkill"} and "-9" in flags:
</code_context>
<issue_to_address>
**Temporary cleanup remains blocked**
The issue expects cleanup to be allowed when every removal target is a literal path under `/tmp`. This branch rejects recursive forced `rm` commands without checking their targets, so the reported cleanup command is still blocked.
</issue_to_address>
### Comment 15
<location path="astrbot/core/astr_agent_runtime/computer/booters/local.py" line_range="125" />
<code_context>
+ return False
+
+ # Compare the bare program name so `/bin/rm` and `rm` are the same tool.
+ name = argv[0].replace("\\", "/").rsplit("/", 1)[-1].lower()
+ flags = argv[1:]
+
</code_context>
<issue_to_address>
**Nested shell payloads bypass checks**
When a command embeds a blocked operation in a substitution or invokes a shell with a combined command option, `_is_safe_command` checks only the outer command or misses the shell payload, so the shell executes the blocked operation.
Inspect nested command substitutions and recognize combined shell command options before allowing execution.
Also at `astrbot/core/astr_agent_runtime/computer/booters/local.py:109`, `astrbot/core/astr_agent_runtime/computer/booters/local.py:156`.
</issue_to_address>
### Comment 16
<location path="tests/unit/test_computer.py" line_range="152-154" />
<code_context>
+ "rm -r -f /home",
+ "rm --recursive --force /home",
+ # A shell started with -c runs the payload inside.
+ 'sh -c "rm -rf /"',
+ "bash -c 'rm -rf /'",
+ 'sh -c "echo hi; rm -rf /"',
+ ]
+ for cmd in blocked_commands:
</code_context>
<issue_to_address>
**Shell payload checks go untested**
When the `-c` handling stops checking its payload, `test_is_safe_command_blocked_despite_obfuscation` at lines 152–154 still passes if the recursive `-c` payload check is removed: the outer raw-text check finds `rm -rf` in each input and rejects it before payload inspection.
Use at least one `-c` payload with an obfuscated blocked command, such as `rm -rf /`, so only recursive payload inspection can reject it.
</issue_to_address>
### Comment 17
<location path="tests/unit/test_computer.py" line_range="143" />
<code_context>
+ # Chaining onto a harmless command must not hide the payload.
+ "echo hi;rm -rf /",
+ "echo hi&&rm -rf /",
+ "echo hi || rm -rf /",
+ "true\nrm -rf /",
+ # Reaching the same binary by another path.
</code_context>
<issue_to_address>
**Legacy scan masks parser cases**
When the parser stops splitting `||` commands or recognizing recursive and forced short flags supplied separately, `test_is_safe_command_blocked_despite_obfuscation` at lines 143 and 149 still passes if `||` splitting and separate short-flag detection are broken: the initial raw-text check rejects both inputs via ` rm -rf ` and ` rm -r ` before those checks run.
Use cases that evade the raw substring patterns, such as `echo hi||rm -rf /` and `rm -f -r /home`, to exercise those parser checks.
Also at `tests/unit/test_computer.py:149`.
</issue_to_address>Sourcery assessment
Approval pending. 17 findings to address first.
Blocking findings: astrbot/core/astr_agent_runtime/computer/booters/local.py:86, astrbot/core/astr_agent_runtime/computer/booters/local.py:126, astrbot/core/astr_agent_runtime/computer/booters/local.py:109, astrbot/core/astr_agent_runtime/computer/booters/local.py:158, astrbot/core/astr_agent_runtime/computer/booters/local.py:142, and 12 more
|
|
||
|
|
||
| # Separators that end one shell command and start the next. | ||
| _SHELL_SEPARATORS = re.compile(r"&&|\|\||[;|\n\r]") |
There was a problem hiding this comment.
🟠 High · Blocked commands run after &
When a command uses a single & to start a blocked command, _SHELL_SEPARATORS leaves both commands in one segment, so shlex.split checks only the first command and the shell runs the blocked command.
Parse single-ampersand command separators and check each resulting command before execution.
Prompt for AI agents
In `astrbot/core/astr_agent_runtime/computer/booters/local.py` at line 86:
**Blocked commands run after `&`**
When a command uses a single `&` to start a blocked command, `_SHELL_SEPARATORS` leaves both commands in one segment, so `shlex.split` checks only the first command and the shell runs the blocked command.
Parse single-ampersand command separators and check each resulting command before execution.| name = argv[0].replace("\\", "/").rsplit("/", 1)[-1].lower() | ||
| flags = argv[1:] |
There was a problem hiding this comment.
🔴 Critical · Wrapped blocked commands run
When a blocked executable is preceded by env, a leading environment assignment, or a wrapper that invokes sudo, _is_safe_command checks only the first parsed token, so it misses the wrapped executable and allows the shell to run the blocked command.
Resolve leading assignments and command wrappers before applying the executable and argument checks.
Also at astrbot/core/astr_agent_runtime/computer/booters/local.py:131.
Prompt for AI agents
In `astrbot/core/astr_agent_runtime/computer/booters/local.py` at lines 125-126:
**Wrapped blocked commands run**
When a blocked executable is preceded by `env`, a leading environment assignment, or a wrapper that invokes `sudo`, `_is_safe_command` checks only the first parsed token, so it misses the wrapped executable and allows the shell to run the blocked command.
Resolve leading assignments and command wrappers before applying the executable and argument checks.
Also at `astrbot/core/astr_agent_runtime/computer/booters/local.py:131`.| for segment in _SHELL_SEPARATORS.split(command): | ||
| try: | ||
| argv = shlex.split(segment, posix=True) |
There was a problem hiding this comment.
🔴 Critical · Substitutions run unchecked commands
When a command substitution or backtick expression contains a blocked command, shlex.split treats the substitution as an argument to the outer command, so _is_safe_command checks only that outer command and the shell executes the blocked command; the same unchecked path occurs when the command also uses a single &.
Inspect and validate commands inside substitutions and backticks, as well as commands separated by single &.
Also at astrbot/core/astr_agent_runtime/computer/booters/local.py:86, astrbot/core/astr_agent_runtime/computer/booters/local.py:125-126.
Prompt for AI agents
In `astrbot/core/astr_agent_runtime/computer/booters/local.py` at lines 107-109:
**Substitutions run unchecked commands**
When a command substitution or backtick expression contains a blocked command, `shlex.split` treats the substitution as an argument to the outer command, so `_is_safe_command` checks only that outer command and the shell executes the blocked command; the same unchecked path occurs when the command also uses a single `&`.
Inspect and validate commands inside substitutions and backticks, as well as commands separated by single `&`.
Also at `astrbot/core/astr_agent_runtime/computer/booters/local.py:86`, `astrbot/core/astr_agent_runtime/computer/booters/local.py:125-126`.| if "-c" in flags: | ||
| index = flags.index("-c") | ||
| if index + 1 >= len(flags) or not _is_safe_command(flags[index + 1]): |
There was a problem hiding this comment.
🔴 Critical · Combined shell flags bypass payload checks
When a shell receives its inline payload through a combined short option or a platform-specific command option, _is_safe_command recognizes only an exact -c token, so it skips payload validation and the nested shell runs the blocked command.
Recognize supported inline-payload options, including combined short options and PowerShell command options, and validate their payloads.
Also at astrbot/core/astr_agent_runtime/computer/booters/local.py:107-110.
Prompt for AI agents
In `astrbot/core/astr_agent_runtime/computer/booters/local.py` at lines 156-158:
**Combined shell flags bypass payload checks**
When a shell receives its inline payload through a combined short option or a platform-specific command option, `_is_safe_command` recognizes only an exact `-c` token, so it skips payload validation and the nested shell runs the blocked command.
Recognize supported inline-payload options, including combined short options and PowerShell command options, and validate their payloads.
Also at `astrbot/core/astr_agent_runtime/computer/booters/local.py:107-110`.| forced = "f" in short or "--force" in long_flags | ||
| if recursive and forced: | ||
| return False |
There was a problem hiding this comment.
🟠 High · Recursive removal runs unchecked
When an rm command uses recursive flags without a force flag, the recursive-removal check requires both recursive and force flags, so rm -r /home/user passes and deletes files.
Reject recursive rm commands even when they do not include a force flag.
Prompt for AI agents
In `astrbot/core/astr_agent_runtime/computer/booters/local.py` at lines 140-142:
**Recursive removal runs unchecked**
When an `rm` command uses recursive flags without a force flag, the recursive-removal check requires both recursive and force flags, so `rm -r /home/user` passes and deletes files.
Reject recursive `rm` commands even when they do not include a force flag.|
|
||
|
|
||
| # Separators that end one shell command and start the next. | ||
| _SHELL_SEPARATORS = re.compile(r"&&|\|\||[;|\n\r]") |
There was a problem hiding this comment.
🔴 Critical · Line continuation bypasses blocking
When a POSIX command uses a backslash-newline continuation between blocked flags, the split separates the physical newline before the shell processes the backslash continuation; tokenization of the first fragment fails and falls back to whitespace splitting, so neither fragment is recognized as recursive forced removal. _is_safe_command accepts the command, and the shell joins it into rm -rf /.
Normalize shell line continuations before checking, or use parsing that preserves the shell’s continuation semantics.
Prompt for AI agents
In `astrbot/core/astr_agent_runtime/computer/booters/local.py` at line 86:
**Line continuation bypasses blocking**
When a POSIX command uses a backslash-newline continuation between blocked flags, the split separates the physical newline before the shell processes the backslash continuation; tokenization of the first fragment fails and falls back to whitespace splitting, so neither fragment is recognized as recursive forced removal. `_is_safe_command` accepts the command, and the shell joins it into `rm -rf /`.
Normalize shell line continuations before checking, or use parsing that preserves the shell’s continuation semantics.| if name == "rm": | ||
| # Any recursive forced removal, however the flags are grouped. | ||
| short = "".join( | ||
| f[1:] for f in flags if f.startswith("-") and not f.startswith("--") | ||
| ) | ||
| long_flags = {f for f in flags if f.startswith("--")} | ||
| recursive = "r" in short or "R" in short or "--recursive" in long_flags | ||
| forced = "f" in short or "--force" in long_flags | ||
| if recursive and forced: | ||
| return False |
There was a problem hiding this comment.
🔴 Critical · Temporary cleanup remains blocked
The issue expects cleanup to be allowed when every removal target is a literal path under /tmp. This branch rejects recursive forced rm commands without checking their targets, so the reported cleanup command is still blocked.
Prompt for AI agents
In `astrbot/core/astr_agent_runtime/computer/booters/local.py` at lines 133-142:
**Temporary cleanup remains blocked**
The issue expects cleanup to be allowed when every removal target is a literal path under `/tmp`. This branch rejects recursive forced `rm` commands without checking their targets, so the reported cleanup command is still blocked.From #11039:
Allow the cleanup command when every removal target is a literal path under `/tmp`.| return False | ||
|
|
||
| # Compare the bare program name so `/bin/rm` and `rm` are the same tool. | ||
| name = argv[0].replace("\\", "/").rsplit("/", 1)[-1].lower() |
There was a problem hiding this comment.
🔴 Critical · Nested shell payloads bypass checks
When a command embeds a blocked operation in a substitution or invokes a shell with a combined command option, _is_safe_command checks only the outer command or misses the shell payload, so the shell executes the blocked operation.
Inspect nested command substitutions and recognize combined shell command options before allowing execution.
Also at astrbot/core/astr_agent_runtime/computer/booters/local.py:109, astrbot/core/astr_agent_runtime/computer/booters/local.py:156.
Prompt for AI agents
In `astrbot/core/astr_agent_runtime/computer/booters/local.py` at line 125:
**Nested shell payloads bypass checks**
When a command embeds a blocked operation in a substitution or invokes a shell with a combined command option, `_is_safe_command` checks only the outer command or misses the shell payload, so the shell executes the blocked operation.
Inspect nested command substitutions and recognize combined shell command options before allowing execution.
Also at `astrbot/core/astr_agent_runtime/computer/booters/local.py:109`, `astrbot/core/astr_agent_runtime/computer/booters/local.py:156`.| 'sh -c "rm -rf /"', | ||
| "bash -c 'rm -rf /'", | ||
| 'sh -c "echo hi; rm -rf /"', |
There was a problem hiding this comment.
🟡 Medium · Shell payload checks go untested
When the -c handling stops checking its payload, test_is_safe_command_blocked_despite_obfuscation at lines 152–154 still passes if the recursive -c payload check is removed: the outer raw-text check finds rm -rf in each input and rejects it before payload inspection.
Use at least one -c payload with an obfuscated blocked command, such as rm -rf /, so only recursive payload inspection can reject it.
Prompt for AI agents
In `tests/unit/test_computer.py` at lines 152-154:
**Shell payload checks go untested**
When the `-c` handling stops checking its payload, `test_is_safe_command_blocked_despite_obfuscation` at lines 152–154 still passes if the recursive `-c` payload check is removed: the outer raw-text check finds `rm -rf` in each input and rejects it before payload inspection.
Use at least one `-c` payload with an obfuscated blocked command, such as `rm -rf /`, so only recursive payload inspection can reject it.| # Chaining onto a harmless command must not hide the payload. | ||
| "echo hi;rm -rf /", | ||
| "echo hi&&rm -rf /", | ||
| "echo hi || rm -rf /", |
There was a problem hiding this comment.
🟡 Medium · Legacy scan masks parser cases
When the parser stops splitting || commands or recognizing recursive and forced short flags supplied separately, test_is_safe_command_blocked_despite_obfuscation at lines 143 and 149 still passes if || splitting and separate short-flag detection are broken: the initial raw-text check rejects both inputs via rm -rf and rm -r before those checks run.
Use cases that evade the raw substring patterns, such as echo hi||rm -rf / and rm -f -r /home, to exercise those parser checks.
Also at tests/unit/test_computer.py:149.
Prompt for AI agents
In `tests/unit/test_computer.py` at line 143:
**Legacy scan masks parser cases**
When the parser stops splitting `||` commands or recognizing recursive and forced short flags supplied separately, `test_is_safe_command_blocked_despite_obfuscation` at lines 143 and 149 still passes if `||` splitting and separate short-flag detection are broken: the initial raw-text check rejects both inputs via ` rm -rf ` and ` rm -r ` before those checks run.
Use cases that evade the raw substring patterns, such as `echo hi||rm -rf /` and `rm -f -r /home`, to exercise those parser checks.
Also at `tests/unit/test_computer.py:149`.|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Fixes #11039.
_is_safe_commandsearched the raw command line for blocklist substrings. Because every pattern carries its surrounding spaces, changing the spelling of a blocked command was enough to get it accepted.What was accepted
Measured against the blocklist currently on
master:rm -rf /rm -rfsudo<TAB>rm -rf /sudokill -9 -1kill -9echo hi;rm -rf /echo hi&&rm -rf /&&/bin/rm -rf /rmsh -c "rm -rf /"rm --recursive --force /xrm -rf /itself was rejected, which is why the gap stayed invisible.Change
The command is split on
&&,||,;,|and newlines. Each piece is tokenised withshlex, and the program name is compared without its directory so/bin/rmandrmare the same tool. Flags are matched as a set, so every ordering of-rand-fcounts, as does--recursive --force. A shell invoked with-chas its payload checked as its own command line. Unbalanced quotes fall back to whitespace splitting rather than throwing.The blocklist itself is untouched. This tightens the check; it does not relax the policy.
Not adopting the
/tmpallowance#11045 added a
/tmpexception and its author withdrew it, because checking a path and then handing the string to the shell leaves a TOCTOU window. I did not reopen that direction.rm -rf /tmp/xis rejected now, exactly as it was before.Verification
New cases in
tests/unit/test_computer.py:test_is_safe_command_blocked_despite_obfuscationcovers all eight bypasses above plus flag and quoting variants, andtest_is_safe_command_allowed_alongside_blocked_textguards against over-blocking.pytest tests/unit/test_computer.py→ 58 passed.local.pymakestest_is_safe_command_blocked_despite_obfuscationfail, so the test is tied to the fix rather than passing vacuously.ls -la,git status,npm run build && npm test,git add . ; git commit -m 'msg',rm file.txt,dd --version,kill 1234, …) produce the same verdict before and after — zero new rejections.ruff formatandruff checkpass.Summary by Sourcery
Harden computer command safety checks by evaluating parsed shell commands instead of relying on raw-text substring matching.
Bug Fixes:
Enhancements:
Tests: