Skip to content

fix(sandbox): return 400 instead of 500 for empty-string entries in git/discard filepaths - #5189

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/discard-empty-filepath-w3
Jul 24, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
fix/discard-empty-filepath-w3

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 24, 2026 •

Copy link
Copy Markdown
Collaborator

Follows the recurring "400 instead of 500 on malformed git/* request" hardening lane in this exact file (#5150, #5142, #5144, #5175).

Bug: POST /git/discard with {"filepaths": [""]} passed the existing typeof fp === "string" check (an empty string is a string) and reached discard(). resolveRepoRelativePath(deps, "") resolves to the repo root itself (path.relative(repoDir, repoDir) === ""), and since git show HEAD: (empty path) succeeds and returns the root tree listing instead of erroring, the code treats it as an existing tracked file and calls git checkout -- "". Git rejects an empty pathspec with fatal: empty string is not a valid pathspec (exit 128), which isn't caught anywhere in discard(), 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 string in packages/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.ts

Checks run locally: bun run fmt, bunx tsc --noEmit in packages/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/discard receives empty or whitespace-only entries in filepaths. This hardens input validation and prevents uncaught git errors.

  • Bug Fixes
    • Validate filepaths to reject empty/whitespace-only strings and respond with 400 { error: "filepaths is required" }.
    • Added a regression test in packages/sandbox/daemon/routes/git.test.ts to cover this case.

Written for commit 003e114. Summary will update on new commits.

Review in cubic

@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) July 24, 2026 15:25
@pedrofrxncx
pedrofrxncx merged commit fb96a0a into main Jul 24, 2026
15 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/discard-empty-filepath-w3 branch July 24, 2026 15:31
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
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