Repository navigation
fix(s17): compare the danger gates against a normalized command - #675
Open
shuhuNB515 wants to merge 1 commit into
Open
shuhuNB515 wants to merge 1 commit into
shuhuNB515 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #674
Problem
AgentSession._permission_hookmatchedDENY_LISTandDESTRUCTIVEwith a case-sensitive literal substring test against the raw command. Since the bash tool runs throughcmd.exeon Windows (case-insensitive keywords, perENVIRONMENT_PROMPT), and extra whitespace still runs the same program, both gates could be walked past:SUDO apt install xSHUTDOWN /s /t 0dd if=/dev/zero of=/dev/sdaThe file already compiles
DESTRUCTIVE_COMMAND_WORDwith(?i)and an explicit;&|()/ newline boundary, so the two guards disagreed about what counts as the same command.Change
The gate reads a case-folded, whitespace-collapsed copy; the command that actually runs is untouched.
s17_goal_loop/code.pyand its embedded snapshot inweb/src/data/generated/versions.jsonare updated together, sotests/test_web_scenarios.pystays byte-identical.Scoped to
s17on purpose:s03–s15carry the same literal check as a teaching gate, and this PR does not touch them (their code blocks are also quoted in thes03READMEs 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", ...)withbuiltins.inputpatched to raise, proving the command never reaches the confirmation branch:SHUTDOWN /s /t 0,SUDO apt install x,dd if=...all returnedNone(executed silently)Permission denied by deny list: ...;sudo apt install xbehaves as beforeTests:
tests/test_goal_loop.py— 24 passed;tests/test_web_scenarios.py+tests/test_chapter_readmes.py— 9 passed. Whole suite withtests/test_agent_teams_runtime.pyexcluded (that file now stops responding in this sandbox even when run alone, on unmodifiedmaintoo) —433 passed, 43 subtests passed, 3 failed; the three failures are the same environment-only ones described below, identical on unmodifiedmain(sandboxmkdirEEXISTintest_s_full_background.py×2, plus one GBK subprocess case).An earlier complete run on a sibling branch, before this change, finished at
500 passedwith exactly those same 3 failures.Disclosed AI assistance: found during an AI-assisted review; patch and verification done with AI assistance.