Repository navigation
Conversation
_is_single_command_read_only skipped every leading VAR=value assignment unconditionally before classifying the command, so an unsafe assignment could hide a SAFE_COMMANDS member behind it: LD_PRELOAD=/tmp/evil.so grep … (or PATH=/tmp/evil grep …, swapping the binary outright) was classified read-only and auto-allowed in every permission mode, while _extract_command_prefix in the same file refuses to extract a prefix when a non-allowlisted assignment is present. Only step over assignments that cannot change the program that runs: whitelisted names except PATH and the LD_*/DYLD_* loader variables. Everything else falls through to the normal checks.
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.
AgentScope Version
2.0.12dev (main @
782bd43)Description
BashCommandParser._is_single_command_read_onlyskipped every leadingVAR=valueassignment unconditionally before classifying the command, so an unsafe assignment could hide aSAFE_COMMANDSmember behind it:LD_PRELOAD=/tmp/evil.so grep -n todo src/a.py(orPATH=/tmp/evil grep todo src/a.py, swapping the executed binary outright) was classified read-only and auto-allowed in every permission mode including DEFAULT —check_permissionsstep 1 returns ALLOW for read-only commands, and the engine's read-only fast path short-circuits the same way. Neither payload contains$(…),<(or any other dynamic structure, so the injection-risk check passes it through untouched._extract_command_prefixin the same file already refuses to extract a prefix when a non-allowlisted assignment is present, so rule generation stayed safe while the read-only fast path allowed the command outright (#3802).Changes — the skip loop now only steps over assignments that cannot change the program that runs:
SAFE_ENV_VARSallowlist (matching_extract_command_prefix's semantics), exceptPATHand theLD_*/DYLD_*loader variables are never skipped, because they change which binary executes or how it loads —PATHitself is on the allowlist, so an allowlist-only fix would not have coveredPATH=/tmp/evil grep ….Anything else (e.g.
LD_PRELOAD=…,FOO=1) falls through to the normal checks.How to test
New case in the existing
BashParserReadOnlyTest(tests/permission_bash_parser_test.py):test_env_assignments_are_not_skipped_blindly— fails onmain(the three payloadsLD_PRELOAD=… grep,PATH=/tmp/evil grep,DYLD_INSERT_LIBRARIES=… grepare all classified read-only), passes with this fix;NODE_ENV=prod grep …,DEBUG=1 cat …remain read-only), and the existing prefix-extraction expectations (PATH=/usr/bin npm run build→npm run) are untouched.Fixes #3802
Checklist