fix(sandbox): validate remote default branch before shelling out in checkout#4470
Merged
Merged
Conversation
…heckout spawnCheckoutBranch's fork-from-default-branch path reads defaultBranch from the remote's own origin/HEAD symref and interpolates it into sh -c git commands without validation. Git's ref-format rules permit shell metacharacters (;, $(...), backticks) in ref names, so a repo whose default branch is attacker-named injects arbitrary commands into the sandbox daemon. The sibling fetchBaseBranch path in clone.ts was already hardened against this exact class with its own ad-hoc allowlist; this path was missed. Reuse the existing assertValidRemoteBranchName guard (already used in rebase-onto-base.ts and routes/git.ts) instead of adding another ad-hoc check.
decocms Bot
pushed a commit
that referenced
this pull request
Jul 11, 2026
PR: #4470 fix(sandbox): validate remote default branch before shelling out in checkout Bump type: patch - @decocms/sandbox (packages/sandbox/package.json): 1.14.2 -> 1.14.3 Deploy-Scope: both
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.
Source
A bug found while reading recently-changed sandbox git code (no open issue covers this).
Payoff
Closes a command-injection vector:
spawnCheckoutBranch's fork-from-default-branch path readsdefaultBranchfrom the remote's ownorigin/HEADsymref and interpolates it, unvalidated, intosh -cgit commands (fetch/checkout -B). Git's ref-format rules permit shell metacharacters (;,$(...), backticks) in ref names, so a repository whose default branch is attacker-named lets that attacker run arbitrary commands in the sandbox daemon process the moment a task requests a branch that doesn't exist locally or on the remote.This is the same vulnerability class the team already fixed in the sibling
fetchBaseBranchpath (packages/sandbox/daemon/setup/clone.ts, with its own ad-hocisSafeRefNameallowlist and an explicit comment about the injection vector) — this file was just missed. Rather than duplicating that allowlist again, this reuses the existingassertValidRemoteBranchNameguard already used for the same purpose inrebase-onto-base.tsandroutes/git.ts.Failure scenario + regression test
packages/sandbox/daemon/git/checkout-branch.test.tsadds a case that points a cloned repo'sorigin/HEADatrefs/heads/pwn;touch${IFS}<tmp>/INJECTED(a syntactically valid git ref name) and requests a checkout of a branch absent from both remote and local. Before the fix,spawnCheckoutBranchresolves without error (i.e. it shells the malicious ref straight intosh -c); after the fix it rejects withInvalidRemoteBranchNameErrorbefore the shell ever sees it.Verify
Checks run locally
bun run fmt— no changes neededbun test packages/sandbox/daemon/git/checkout-branch.test.ts— 4 pass (confirmed the new test fails on the pre-fix code, then passes after the fix)Summary by cubic
Validate the remote default branch name in sandbox checkout to block command injection via attacker-controlled
origin/HEAD. Adds a guard before shell commands and a regression test to ensurespawnCheckoutBranchrejects malicious refs.defaultBranchinspawnCheckoutBranchusingassertValidRemoteBranchNamebefore runninggit fetch/git checkout -B.origin/HEADto a ref with shell metacharacters; now fails withInvalidRemoteBranchNameErrorand no commands run.Written for commit 60815ef. Summary will update on new commits.