Repository navigation
fix(sandbox): return 400 instead of 500 for empty-string entries in git/discard filepaths - #5189
Merged
Merged
Conversation
…it/discard filepaths
pedrofrxncx
enabled auto-merge (squash)
July 24, 2026 15:25
decocms Bot
pushed a commit
that referenced
this pull request
Jul 24, 2026
PR: #5189 fix(sandbox): return 400 instead of 500 for empty-string entries in git/discard filepaths Bump type: patch - @decocms/sandbox (packages/sandbox/package.json): 1.22.5 -> 1.22.6 - deploy/helm/sandbox-env (chart 0.9.24) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.22.6 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.
Follows the recurring "400 instead of 500 on malformed git/* request" hardening lane in this exact file (#5150, #5142, #5144, #5175).
Bug:
POST /git/discardwith{"filepaths": [""]}passed the existingtypeof fp === "string"check (an empty string is a string) and reacheddiscard().resolveRepoRelativePath(deps, "")resolves to the repo root itself (path.relative(repoDir, repoDir) === ""), and sincegit show HEAD:(empty path) succeeds and returns the root tree listing instead of erroring, the code treats it as an existing tracked file and callsgit checkout -- "". Git rejects an empty pathspec withfatal: empty string is not a valid pathspec(exit 128), which isn't caught anywhere indiscard(), so it bubbles up as an uncaught error and the route's catch-all returns a raw 500 with the git error text instead of a clean 4xx for what is really a malformed request body.Fix: extend the existing filepaths validation to also reject empty/whitespace-only string entries, matching the same 400 (
"filepaths is required") already returned for non-string entries.Regression test: added
discard returns 400 (not 500) when filepaths contains an empty stringinpackages/sandbox/daemon/routes/git.test.ts, which fails against the pre-fix code (500) and passes after.To verify:
bun test packages/sandbox/daemon/routes/git.test.tsChecks run locally:
bun run fmt,bunx tsc --noEmitinpackages/sandbox, and the single targeted test file above (37 pass). Full CI covers the rest.Summary by cubic
Return 400 Bad Request (not 500) when
POST /git/discardreceives empty or whitespace-only entries infilepaths. This hardens input validation and prevents uncaught git errors.filepathsto reject empty/whitespace-only strings and respond with 400{ error: "filepaths is required" }.packages/sandbox/daemon/routes/git.test.tsto cover this case.Written for commit 003e114. Summary will update on new commits.