Skip to content

fix(s17): compare the danger gates against a normalized command - #675

Open
shuhuNB515 wants to merge 1 commit into
shareAI-lab:mainfrom
shuhuNB515:fix/s17-deny-list-normalize
Open

shuhuNB515 wants to merge 1 commit into
shareAI-lab:mainfrom
shuhuNB515:fix/s17-deny-list-normalize

Conversation

@shuhuNB515

@shuhuNB515 shuhuNB515 commented Nov 29, 2026 •

Copy link
Copy Markdown

Fixes #674

Problem

AgentSession._permission_hook matched DENY_LIST and DESTRUCTIVE with a case-sensitive literal substring test against the raw command. Since the bash tool runs through cmd.exe on Windows (case-insensitive keywords, per ENVIRONMENT_PROMPT), and extra whitespace still runs the same program, both gates could be walked past:

command before after
SUDO apt install x allowed, no prompt denied
SHUTDOWN /s /t 0 allowed, no prompt denied
dd if=/dev/zero of=/dev/sda allowed, no prompt denied

The file already compiles DESTRUCTIVE_COMMAND_WORD with (?i) and an explicit ;&|() / newline boundary, so the two guards disagreed about what counts as the same command.

Change

normalized = " ".join(command.casefold().split())
for pattern in DENY_LIST:
    if pattern in normalized:
        return f"Permission denied by deny list: {pattern}"
if contains_destructive_command(command) or any(
    keyword in normalized for keyword in DESTRUCTIVE
):

The gate reads a case-folded, whitespace-collapsed copy; the command that actually runs is untouched. s17_goal_loop/code.py and its embedded snapshot in web/src/data/generated/versions.json are updated together, so tests/test_web_scenarios.py stays byte-identical.

Scoped to s17 on purpose: s03–s15 carry the same literal check as a teaching gate, and this PR does not touch them (their code blocks are also quoted in the s03 READMEs in three languages). Happy to align them in a follow-up if you prefer.

Verification

Reproduced by loading the real module and dispatching through trigger_hooks("PreToolUse", ...) with builtins.input patched to raise, proving the command never reaches the confirmation branch:

  • before: SHUTDOWN /s /t 0, SUDO apt install x, dd if=... all returned None (executed silently)
  • after: all three return Permission denied by deny list: ...; sudo apt install x behaves as before

Tests: tests/test_goal_loop.py — 24 passed; tests/test_web_scenarios.py + tests/test_chapter_readmes.py — 9 passed. Whole suite with tests/test_agent_teams_runtime.py excluded (that file now stops responding in this sandbox even when run alone, on unmodified main too) — 433 passed, 43 subtests passed, 3 failed; the three failures are the same environment-only ones described below, identical on unmodified main (sandbox mkdir EEXIST in test_s_full_background.py ×2, plus one GBK subprocess case).

An earlier complete run on a sibling branch, before this change, finished at 500 passed with exactly those same 3 failures.

Disclosed AI assistance: found during an AI-assisted review; patch and verification done with AI assistance.

DENY_LIST and DESTRUCTIVE were matched against the raw string with a
case-sensitive literal substring test. On Windows the bash tool runs through
cmd.exe, whose keywords are case-insensitive, so 'SHUTDOWN /s /t 0' or
'SUDO apt install x' passed both gates with no denial and no confirmation
prompt. Extra whitespace ('dd  if=') did the same. The module already
compiles DESTRUCTIVE_COMMAND_WORD with (?i) for exactly this reason, so the
two guards disagreed about what counts as the same command. Match both
against a case-folded, whitespace-collapsed copy while running the original
text unchanged. Sync the embedded s17 snapshot in versions.json.

Disclosed AI assistance: found during an AI-assisted review.

This branch has not been deployed

No deployments
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.

s17: deny list is matched case-sensitively, so 'SHUTDOWN' or 'SUDO' bypass both danger gates

1 participant