Skip to content

test(sandbox-proxy): cover branch-name validation trust boundary - #5350

Open
pedrofrxncx wants to merge 1 commit into
mainfrom
test/sandbox-branch-validation-w4
Open

test(sandbox-proxy): cover branch-name validation trust boundary#5350
pedrofrxncx wants to merge 1 commit into
mainfrom
test/sandbox-branch-validation-w4

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Trust-boundary test for assertSandboxBranchParam in apps/api/src/api/routes/sandbox-proxy.ts.

Why this is a trust boundary (C4/R4): assertSandboxBranchParam parses the branch URL path param — fully client-controlled — before it's used to compose the sandbox claim ref (composeSandboxRef) and claim handle (computeClaimHandle), which are ultimately forwarded to the sandbox daemon where branch is used as a live git ref for checkout/fetch (see packages/sandbox/daemon/git/ref-name.ts's isValidRemoteBranchName, which encodes the same git-ref-injection rules: no .., no leading/trailing /, no .lock suffix). This is exactly "a URL used for auth or a network call" / "user-supplied paths feeding a filesystem/proxy op" per the gate. I confirmed via repo-wide grep that no test anywhere (in apps/api or packages/sandbox) previously exercised this specific function — a regression here (e.g. a loosened regex, or a broken thread: prefix strip letting .. through) would only surface later as an opaque daemon-side git error, not a caught local failure.

Change: exported assertSandboxBranchParam (previously module-private) and added a describe("assertSandboxBranchParam", ...) block in the existing test file covering: valid plain/thread:-prefixed branches, empty branch, empty thread: id, .. traversal (both plain and inside a thread: id), leading/trailing slash, .lock suffix, >255 chars, and disallowed charset (space, :, leading -). No production logic changed — just an export keyword plus the new tests.

Reviewer check: bun test apps/api/src/api/routes/sandbox-proxy.test.ts (19 tests, all pass).

Locally verified: bun run fmt, cd apps/api && bunx tsc --noEmit (clean), and the targeted test file above. Full CI covers the rest.


Summary by cubic

Add trust-boundary tests for assertSandboxBranchParam in the sandbox proxy to catch unsafe branch inputs before they reach the daemon. Exported the function for testing; covers valid plain and thread: branches and rejects empty, .. traversal, leading/trailing /, .lock suffix, >255 chars, and invalid charset.

Written for commit 05386fe. Summary will update on new commits.

Review in cubic

assertSandboxBranchParam parses the untrusted URL branch param before it
composes the sandbox claim ref/handle and is forwarded to the daemon, which
uses it as a live git ref (checkout/fetch). No test anywhere in the repo
exercised it, so a regression here (e.g. a loosened regex letting ".."- or
".lock"-suffixed input through) would only surface as a downstream daemon
error rather than a caught local failure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant