Repository navigation
fix(shell,skills): close the allowlist holes that let a read run code - #3593
Conversation
The Windows shell allowlist called commands read-only that were not. `dir . &where cmd` ran a second command because the operator check only saw an ampersand followed by whitespace; `powershell -e` slipped a filter that matched only the full `-EncodedCommand` spelling; and .NET calls, alias invocations and `>` redirection inside `-Command` all passed as cmdlet reads. Allowlisted binaries were write primitives too: `git log --output=` and `wmic /output:` put near-arbitrary content at a near-arbitrary path. Separately, a skill holding `shell:execute:gh` could run `gh auth status --show-token`, which sits in the tier that skips confirmation, and print the user's GitHub token into tool output a `network:read` skill could then send anywhere. Reads now take a fixed flag allowlist, so a flag nobody reviewed is refused rather than passed through to the tool's own parser. The argv rewrite that removes cmd.exe from this path entirely is a larger change and lands separately; its contract is pinned here as strict xfail so implementing it forces the marker off.
Request changesThis PR closes several genuine holes — The PowerShell fix stops one token short. Put almost any other PowerShell switch in front of the command text and the whole new script-body check goes back to sleep: The skill doc now promises more than the code does. It tells the model that reads take a fixed flag allowlist, but that only holds for Two reads that used to work now fail with the wrong reason. Listing untracked files ( Four tests became strict expected-failures with a reason saying argv execution isn't implemented — but that path looks present in the shell tool already. Worth saying, per test, why it actually fails today; an expected-failure marker on a security contract hides a regression rather than pinning a spec. Real-world evidenceNo and the same way against the The 🔍 Technical details🔴 Critical — a leading PowerShell switch defeats the new body check (
|
They are module-level constants handed to a helper as default arguments, so a mutable dict there is a shared object any caller could rewrite for every later policy lookup. MappingProxyType makes that impossible rather than merely unlikely.
|
🔴 The leading-switch bypass from the first review is still open. The first review described the shape needed: walk 🔍 Technical details
for i, part in enumerate(cmd_parts):
if part.lower() in ("-command", "-c"):
ps_cmd = " ".join(cmd_parts[i + 1:]).lower()
break
if not ps_cmd:
ps_cmd = " ".join(cmd_parts[1:]).lower() # flag becomes head of bodyReproducing what the first review showed:
The gap: The fix the first review outlined: build an explicit allowlist of the PowerShell.exe switches that are safe to pass before the body (e.g. |
The agent's Windows tips told it to run a Get-Process command with an inline calculated property, which the hardened shell allowlist refuses, so asking for top memory users failed instead of answering. It now asks for the raw WS column and leaves the division to the model.
# Conflicts: # src/gaia/agents/tools/shell_tools.py
|
Verdict: Approve Security hardening across four layers — the shell operator filter, PowerShell body inspection, git/wmic file-write detection, and the A few observations that don't block merge: 🟢 🟢 The two new standalone test functions at the top of 🔍 Technical details
# shell_tools.py
def _outside_double_quotes(text: str) -> str:
if text.count('"') % 2:
return text
return " ".join(text.split('"')[::2])
Import ordering in # New tests at top of file — ShellToolsMixin used here
def test_powershell_switches_cannot_hide_executable_body(command):
assert ShellToolsMixin()._validate_shell_command(command)[0] is not None
# ... more tests ...
# Import appears later in the file (pre-existing position)
from gaia.agents.tools.shell_tools import (
ShellToolsMixin,
...
)Works at runtime;
Agent prompt alignment ( |
Co-Authored-By: Claude Opus 5 <[email protected]>
|
Verdict: Approve This is well-targeted security hardening. Each bypass (unspaced One thing to be aware of going forward: 🟢 PowerShell body 🟢 Test import ordering. The two new Both are nits; neither blocks the fix. 🔍 Technical details
Import ordering (
|
Co-Authored-By: Claude Opus 5 <[email protected]>
|
Verdict: Approve 🟢 Security hardening to the shell guardrails that closes several real bypass paths and is backed by thorough tests. No bugs found across the correctness, security, and architecture checks. What the PR fixes:
Notable design decisions (worth noting for reviewers):
Chat agent prompt change: The Windows process-monitoring command was simplified from the 🔍 Technical detailsThe
The new per-segment pipeline cmdlet check (
|
Main's allowlist fixes (amd#3593) keep refusing under this branch's ask-first model: each guard it added is tagged as an outright refusal, so none of them turns into a yes/no prompt. The /agents switch (amd#3987) and the conversation-clear test (amd#3650) now use the full-access names, and a saved-default notice is shown once rather than again on every switch.
A skill or a prompt-injected tool argument could run arbitrary commands on Windows through paths the shell tool reported as read-only, and could print the user's GitHub token without a confirmation prompt. Both now refuse. Legitimate reads are unaffected — they take a reviewed flag allowlist instead of whatever the underlying tool would have accepted.
The argv rewrite that removes
cmd.exefrom this path entirely is a larger change and lands separately. Its contract is pinned here as four strict-xfail tests, so implementing it forces the marker off rather than leaving the spec unenforced.Test plan
python -m pytest tests/unit/test_shell_guardrails.py tests/unit/test_skill_binary_grants.py— 365 passed, 4 xfailedgh auth status,gh issue list,dir,powershell -Command "Get-Process") still passpython util/lint.py --black --isortclean