Harden sandbox bundle upload paths#1428
Open
resolvicomai wants to merge 1 commit into
Open
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.
Description
Validate sandbox bundle member paths before building the tar archive and quote remote extraction paths before passing them through the sandbox shell command. This prevents traversal entries from reaching the uploaded archive and keeps destination/archive paths with shell metacharacters literal.
Type of Change
Testing
uv run pytestlocally.Focused checks run:
uv run pytest -q tests/test_sandbox_mixin.pyuv run ruff check verifiers/envs/experimental/sandbox_mixin.py tests/test_sandbox_mixin.pypython3 -m py_compile verifiers/envs/experimental/sandbox_mixin.py tests/test_sandbox_mixin.pygit diff --checkUV_FROZEN=1 git commit ...pre-commit hooks: ruff check, ruff format, Semgrep v1 policy, generated AGENTS/CLAUDE checkUV_FROZEN=1 git push ...pre-push hooks: ruff check, ruff format, Semgrep v1 policy, generated AGENTS/CLAUDE check, tyChecklist
Additional Notes
No docs update needed; this only hardens existing sandbox bundle upload behavior.
Note
Medium Risk
Touches sandbox file upload/extraction by adding path validation and stronger shell quoting; low surface-area change but could break callers relying on previously-accepted paths or unusual destination strings.
Overview
Hardens
SandboxMixin.upload_bundleby validating tar member paths to reject absolute paths,..traversal, and empty/.entries before building the archive.Improves remote extraction safety by quoting
dest_dirand archive paths viashlex.quoteand embedding the Python extract snippet as a single quoted script, preventing spaces/metacharacters from being interpreted by the sandbox shell.Adds tests ensuring traversal paths are rejected (with no upload/exec attempted) and that remote commands correctly quote destinations containing spaces.
Reviewed by Cursor Bugbot for commit 7607805. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Harden
SandboxMixin.upload_bundleagainst path traversal and unquoted shell paths_bundle_member_namehelper insandbox_mixin.pythat validates bundle member names, raisingValueErrorfor absolute paths,..segments, or empty/.paths, and returns a normalized POSIX path.upload_bundlenow validates allfile_mapkeys via_bundle_member_namebefore any upload or remote command is executed.mkdir, extraction, andrmnow useshlex.quoteto correctly handledest_dirand archive paths containing spaces or special characters.upload_bundlenow raisesValueErroron unsafe bundle keys instead of silently proceeding.Macroscope summarized 7607805.