Skip to content

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

Merged
pedrofrxncx merged 1 commit into
mainfrom
fix/discard-non-string-filepath-w3
Jul 23, 2026
Merged

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

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Jul 23, 2026 •

Copy link
Copy Markdown
Collaborator

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/discard route only validated that filepaths was a non-empty array, not that each entry was a string. A non-string entry (e.g. 123) reaches resolveRepoRelativePath() -> safePath() -> path.resolve(baseDir, userPath), and Node's path.resolve throws a TypeError for 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/discard with body {"filepaths": ["README.md", 123]} throws inside path.resolve and 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 entry to packages/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.ts

Locally 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/discard when filepaths contains a non-string entry by validating every item is a string. Adds a regression test to cover this case.

  • Bug Fixes
    • Validate filepaths is a non-empty array of strings; otherwise return 400 with { "error": "filepaths is required" }.
    • Added test: rejects ["README.md", 123] with 400 in packages/sandbox/daemon/routes/git.test.ts.

Written for commit 96c998e. Summary will update on new commits.

Review in cubic

…/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
pedrofrxncx enabled auto-merge (squash) July 23, 2026 23:44
@pedrofrxncx
pedrofrxncx merged commit 5c9e401 into main Jul 23, 2026
15 checks passed
@pedrofrxncx
pedrofrxncx deleted the fix/discard-non-string-filepath-w3 branch July 23, 2026 23:52
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
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