security: constrain agent command execution - #4
Merged
Merged
Conversation
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.
Problem
PatchPilot executed planner-supplied test commands and
/api/executeinput throughbash -lc. The old endpoint blocklist caught only a few literal strings, leaving shell chaining, redirection, command substitution, and other arbitrary shell execution paths open.A simple executable allowlist was not sufficient by itself: path-qualified binaries such as
/tmp/pytestcould impersonate an allowlisted tool, while generic command runners such asnode -e,npm exec,pnpm exec,go run, andcargo runcould still provide direct arbitrary-code escape hatches without using shell metacharacters.Solution
pytest,ruff,mypy, andpyrightpython/python3to-m pytestor-m unittesttest,lint,typecheck, orcheckscripts and blockexecgo testtest,check, orclippy/api/executego run, andcargo runScope / limitations
This removes the avoidable shell layer and closes obvious command-runner escape hatches. It is not a sandbox: approved test/lint tools and project-defined package scripts can still execute repository code. Strong isolation still requires a container/process sandbox and workspace/file-system controls.
Validation
The previous branch head passed Backend CI on Python 3.11 and 3.12. After the additional command-runner hardening commits, Backend CI is queued for the new head; no pass is claimed for those latest commits yet.
The connected workstation was offline during this work, so no local validation is claimed.
AI assistance disclosure: AI assistance was used to review the command-execution threat surface, identify bypass classes, prepare the focused hardening and regression tests, and inspect the resulting diff.