Repository navigation
fix(sandbox): return 400 for path-traversal in git discard - #5105
Merged
Merged
Conversation
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
enabled auto-merge (squash)
July 23, 2026 16:36
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
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 auditing
packages/sandbox/daemon/routes/git.tsfor missing/incorrect status codes.Why a maintainer wants it:
makeGitDiscardHandlerreturned a 500 for afilepathsentry 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'ssafePathchecks, and this same file'smakeGitRebaseHandlerfor 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/discardwithfilepaths: ["../outside-secret.txt"]returned HTTP 500 with{"error": "Invalid path: ../outside-secret.txt"}. Fixed by introducingInvalidDiscardPathError(thrown fromresolveRepoRelativePath) and mapping it to 400 in the handler, mirroring the existingInvalidRemoteBranchNameError-> 400 pattern used bymakeGitDiffHandler/makeGitRebaseHandlerin the same file. The existing testdiscard rejects path traversalasserted the old (wrong) 500 status — inverted it to assert 400.Reviewer command:
bun test packages/sandbox/daemon/routes/git.test.tsLocal 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.
InvalidDiscardPathError, thrown byresolveRepoRelativePathand mapped to 400 inmakeGitDiscardHandler(packages/sandbox/daemon/routes/git.ts).packages/sandbox/daemon/routes/git.test.ts).Written for commit 6efec22. Summary will update on new commits.