Skip to content

fix(sandbox): return 400 for path-traversal in git discard - #5105

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-discard-path-traversal-status-w4
Jul 23, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/sandbox-discard-path-traversal-status-w4

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 23, 2026 •

Copy link
Copy Markdown
Collaborator

Source: a bug found while auditing packages/sandbox/daemon/routes/git.ts for missing/incorrect status codes.

Why a maintainer wants it: makeGitDiscardHandler returned a 500 for a filepaths entry that escapes the repo (e.g. "../outside-secret.txt"), even though that's a client input-validation condition, not a server fault — every sibling handler (fs.ts's safePath checks, and this same file's makeGitRebaseHandler for an invalid branch name) already responds 400 for the equivalent case. A 500 tells callers/monitoring "the daemon is broken" when the request was simply invalid, which is misleading for alerting and client retry logic.

Failure scenario + fix: POST /git/discard with filepaths: ["../outside-secret.txt"] returned HTTP 500 with {"error": "Invalid path: ../outside-secret.txt"}. Fixed by introducing InvalidDiscardPathError (thrown from resolveRepoRelativePath) and mapping it to 400 in the handler, mirroring the existing InvalidRemoteBranchNameError -> 400 pattern used by makeGitDiffHandler/makeGitRebaseHandler in the same file. The existing test discard rejects path traversal asserted the old (wrong) 500 status — inverted it to assert 400.

Reviewer command: bun test packages/sandbox/daemon/routes/git.test.ts

Local checks run: bun run fmt, cd packages/sandbox && bunx tsc --noEmit (clean), and the targeted test file above (29 pass). Full CI validates the rest.


Summary by cubic

Return 400 for repo-escaping filepaths in the git discard route instead of 500. This correctly treats path traversal as client input and avoids false server-error alarms.

  • Bug Fixes
    • Added InvalidDiscardPathError, thrown by resolveRepoRelativePath and mapped to 400 in makeGitDiscardHandler (packages/sandbox/daemon/routes/git.ts).
    • Updated test to expect 400 for path traversal (packages/sandbox/daemon/routes/git.test.ts).

Written for commit 6efec22. Summary will update on new commits.

Review in cubic

The git discard route returned 500 for a filepath that escapes the repo
(e.g. "../outside-secret.txt"), even though this is a client input
validation error, not a server fault. Every sibling handler in fs.ts and
the rebase handler in this same file already return 400 for the
equivalent case. Introduces InvalidDiscardPathError, mapped to 400 in
makeGitDiscardHandler, and inverts the existing test that asserted the
old 500.
@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 23, 2026 16:36
@pedrofrxncx
pedrofrxncx merged commit 8fdfc00 into main Jul 23, 2026
15 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/sandbox-discard-path-traversal-status-w4 branch July 23, 2026 16:42
decocms Bot pushed a commit that referenced this pull request Jul 23, 2026
PR: #5105 fix(sandbox): return 400 for path-traversal in git discard
Bump type: patch

- @decocms/sandbox (packages/sandbox/package.json): 1.20.1 -> 1.20.2
- deploy/helm/sandbox-env (chart 0.9.15) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.20.2

Deploy-Scope: both
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