fix(sandbox-proxy): cap body size on git diff/publish/discard/rebase routes - #5319
Merged
Merged
Conversation
…routes #5316 added a 10MB body-size cap to the file-op and config routes on this router, since proxyDaemon reads forwarded bodies fully into memory via c.req.text() before forwarding to the daemon. Four sibling routes on the same router pass forwardJsonBody: true through the identical code path but were left uncapped: git/diff, git/publish, git/discard, git/rebase. Any authenticated org member could POST an arbitrarily large body to these and have it buffered entirely into the Studio API process's memory. Reused the same bodyLimit middleware (renamed from fileOpBodyLimit to forwardedBodyLimit since it now covers all forwardJsonBody: true routes) on the four previously-uncapped routes.
decocms Bot
pushed a commit
that referenced
this pull request
Jul 28, 2026
PR: #5319 fix(sandbox-proxy): cap body size on git diff/publish/discard/rebase routes Bump type: patch - decocms (apps/api/package.json): 4.139.5 -> 4.139.6 Deploy-Scope: server
pedrofrxncx
added a commit
that referenced
this pull request
Jul 28, 2026
…utes (#5330) #5316/#5319 capped request bodies clients send into this router (forwardedBodyLimit) because proxyDaemon buffers them fully into memory via c.req.text() before forwarding. The response side had the same gap: every route reads the daemon's (or, for preview-fetch/preview-invoke, the customer's own preview server's) response fully via upstream.text() with no ceiling. A runaway git diff, a chatty exec script, or a huge preview page gets buffered entirely into the Studio API process's memory. Added readBoundedText(), which reads a Response body in chunks and throws UpstreamPayloadTooLargeError once it exceeds the same 10MB cap already used for request bodies, instead of buffering an unbounded amount. Wired it into proxyDaemon, fetchDaemonJson (used by suggest-commit/judge-review), and the preview-fetch/preview-invoke routes — replacing every remaining upstream.text() call in this file.
pedrofrxncx
added a commit
that referenced
this pull request
Jul 28, 2026
apps/api/src/tools/sandbox/{patch-sandbox-operator,resolve-env,sync-git-credentials}.ts
each PUT to the daemon's /_sandbox/config and, on a non-ok response, read the
error body with a plain res.text() with no size cap. sandbox-proxy.ts already
bounds every proxied response to the same endpoint via readBoundedText()
(#5316/#5319/#5330) — these three call sites hit /_sandbox/config directly
(during publish, rebase, and sandbox start) and were missed, so a
compromised or misbehaving daemon can still make the API process buffer an
unbounded error body into memory on that path.
Extracted readBoundedText()/UpstreamPayloadTooLargeError out of
sandbox-proxy.ts into apps/api/src/lib/bounded-text.ts (no behavior change)
so the tools/sandbox call sites can reuse it without an api-routes ->
tools-layer dependency, and switched all three sites to it with the same
10MB cap sandbox-proxy.ts already applies to this endpoint.
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 hardening follow-up to #5316, found while auditing the same file (
apps/api/src/api/routes/sandbox-proxy.ts) it touched.Why: #5316 added a 10MB
bodyLimitto the file-op (write/unlink/mkdir/rename/read/glob/grep) andconfigPUT routes becauseproxyDaemonreads anyforwardJsonBody: truerequest's body fully into memory viac.req.text()before forwarding it to the daemon. Four sibling routes on the exact same router passforwardJsonBody: truethrough that identical code path but were left uncapped:git/diff,git/publish,git/discard,git/rebase. Any authenticated org member (or a buggy client) can still POST an arbitrarily large body to these and have it buffered entirely into the Studio API process's memory — the same gap #5316 just closed elsewhere in this file.Fix: apply the same
bodyLimitmiddleware (renamed fromfileOpBodyLimittoforwardedBodyLimitsince it now covers everyforwardJsonBody: trueroute, not just file ops) to the four previously-uncapped routes, rejecting oversized requests with 413 before they're read into memory.How to verify:
grep -n 'forwardJsonBody: true' apps/api/src/api/routes/sandbox-proxy.ts— every one of the 12 matches now sits behind a route registered withforwardedBodyLimit.Checks run locally:
bun run fmtandcd apps/api && bunx tsc --noEmit(both clean). No existing test exercises the full Hono route table for this file (per #5316's own note, and this repo's unit-vs-e2e split) — wiring an already-tested middleware into more routes isn't a new logic path, so no new test was added. Full CI validates the rest.Summary by cubic
Cap JSON body size to 10MB on
git/diff,git/publish,git/discard, andgit/rebasesandbox-proxy routes to prevent unbounded memory buffering; oversized requests now return 413. The same limit is applied across allforwardJsonBody: trueroutes via a shared middleware.Bug Fixes
bodyLimittogit/diff,git/publish,git/discard,git/rebase.proxyDaemonand protects API memory.Refactors
fileOpBodyLimittoforwardedBodyLimitand reused it for allforwardJsonBody: trueroutes.Written for commit ab3590e. Summary will update on new commits.