fix(sandbox): cap the Go daemon's config-update body size - #6252
Open
pedrofrxncx wants to merge 1 commit into
Open
fix(sandbox): cap the Go daemon's config-update body size#6252pedrofrxncx wants to merge 1 commit into
pedrofrxncx wants to merge 1 commit into
Conversation
ConfigUpdate (/_sandbox/config PUT) and OrgFsConfig both read the request body with an unbounded io.ReadAll(r.Body). A misbehaving or malicious caller could stream an unbounded body into memory and crash the daemon, tearing down the sandbox pod on the next missed health probe — the same failure mode fs.go's decodeBody already guards against for file-transfer routes. Adds a shared readLimitedBody helper capped at 1MB (config payloads are always small hand-written JSON objects, never file transfers) and wires both routes through it.
pedrofrxncx
enabled auto-merge (squash)
August 19, 2026 18:06
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 the Go sandbox daemon (
packages/sandbox/daemon-go/internal/routes) for reliability gaps — the same class already fixed for the file-transfer routes (fs.go'sdecodeBody, see #6215/#6039).Payoff:
ConfigUpdate(PUT /_sandbox/config) andOrgFsConfigboth read the request body with a raw, unboundedio.ReadAll(r.Body). A misbehaving or malicious caller can stream an unbounded body into memory and crash the daemon — this is a single static binary per sandbox pod, and Studio tears the pod down on the next missed health probe, so an OOM here kills the whole session.Failure scenario: POST a multi-GB body to
/_sandbox/configor the org-fs config route →io.ReadAllbuffers it all into memory with no limit → daemon OOMs/crashes → pod dies.fs.goalready guards its routes against exactly this with a cappeddecodeBody; these two routes were missed.Fix: added a shared
readLimitedBody(r, maxBytes)helper inutil.go(same pattern asfs.go'sdecodeBody, just returning raw bytes since these two callers each unmarshal differently) and wired both routes through it, capped at 1MB — config/org-fs payloads are always small hand-written JSON, never file transfers, so 1MB is generous headroom not a real ceiling.Regression test:
TestReadLimitedBodyRejectsOversizedRequestinutil_test.go, mirroring the existingTestDecodeBodyRejectsOversizedRequestinfs_test.go— drives an infinite reader through the helper and asserts it's rejected instead of buffered.To confirm:
cd packages/sandbox/daemon-go && go build ./... && go vet ./... && go test ./internal/routes/...Locally verified:
go build,go vet,gofmt -l(clean), and the fullinternal/routestest package (including the existing config-redaction tests) — all green. CI validates the rest.Summary by cubic
Caps the request body for config endpoints at 1 MB to prevent daemon OOMs. Previously,
ConfigUpdateandOrgFsConfigread unbounded bodies into memory; now oversized bodies are rejected with 400.readLimitedBodyininternal/routes/util.goand applies it toConfigUpdateandOrgFsConfig.maxConfigBytesto 1 MB; normal small JSON payloads are unaffected.fs.goprotection pattern.TestReadLimitedBodyRejectsOversizedRequestto prevent regressions.Written for commit de5fff6. Summary will update on new commits.