Repository navigation
fix(sandbox): return 400 instead of 500 for non-string entries in git/discard filepaths - #5150
Merged
Merged
Conversation
…/discard filepaths The /git/discard route only checked that `filepaths` was a non-empty array, not that every entry was a string. A non-string entry (e.g. a number) reaches path.resolve() inside resolveRepoRelativePath(), which throws a raw TypeError that the route's catch-all maps to a 500 instead of a 400.
pedrofrxncx
enabled auto-merge (squash)
July 23, 2026 23:44
decocms Bot
pushed a commit
that referenced
this pull request
Jul 23, 2026
PR: #5150 fix(sandbox): return 400 instead of 500 for non-string entries in git/discard filepaths Bump type: patch - @decocms/sandbox (packages/sandbox/package.json): 1.22.3 -> 1.22.4 - deploy/helm/sandbox-env (chart 0.9.22) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.22.4 Deploy-Scope: both
This was referenced Jul 24, 2026
Merged
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: bug found while auditing
packages/sandbox/daemon/routes/git.ts(my assigned focus area: sandbox daemon git route hardening). Same lane as the repo's proven series of "return 4xx instead of 500" daemon fixes (#5008, #5105, #5106, #5109, #5124).Why a maintainer wants this: the
/git/discardroute only validated thatfilepathswas a non-empty array, not that each entry was a string. A non-string entry (e.g.123) reachesresolveRepoRelativePath()->safePath()->path.resolve(baseDir, userPath), and Node'spath.resolvethrows aTypeErrorfor a non-string argument. That TypeError isn't one of the route's known error classes, so it falls through to the generic catch and surfaces as an opaque 500 instead of a client-input 400 — the exact bug shape this daemon has repeatedly hardened against elsewhere.Failure scenario:
POST /git/discardwith body{"filepaths": ["README.md", 123]}throws insidepath.resolveand returns 500. After the fix it returns 400 with{"error": "filepaths is required"}.Regression test: added
discard returns 400 (not 500) when filepaths contains a non-string entrytopackages/sandbox/daemon/routes/git.test.ts, which fails against the old code (500) and passes against the fix (400).Reviewer verification:
bun test packages/sandbox/daemon/routes/git.test.tsLocally verified:
bun run fmt,cd packages/sandbox && bunx tsc --noEmit, and the single targeted test file above (35/35 pass). Full CI validates the rest.Summary by cubic
Return 400 (not 500) from
/git/discardwhenfilepathscontains a non-string entry by validating every item is a string. Adds a regression test to cover this case.filepathsis a non-empty array of strings; otherwise return 400 with{ "error": "filepaths is required" }.["README.md", 123]with 400 inpackages/sandbox/daemon/routes/git.test.ts.Written for commit 96c998e. Summary will update on new commits.