fix(sandbox): cap the Go daemon's /grep result limit - #6180
Merged
Conversation
A caller-supplied `limit` on /grep had no upper bound, unlike /glob's matching globMaxResultLimit cap. A large limit lets rg's match lines accumulate in memory unbounded, the same crash-the-daemon DoS class #6176 closed for request bodies.
decocms Bot
pushed a commit
that referenced
this pull request
Aug 18, 2026
PR: #6180 fix(sandbox): cap the Go daemon's /grep result limit Bump type: patch - @decocms/sandbox (packages/sandbox/package.json): 1.55.3 -> 1.55.4 - deploy/helm/sandbox-env (chart 0.16.5) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.55.4 Deploy-Scope: both
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.
Follows #6176 (which capped fs route request bodies): auditing
packages/sandbox/daemon-go/internal/routes/fs.gofor remaining size-limit loopholes found that/grep's caller-suppliedlimithad no upper bound, unlike/glob'sresultLimitwhich is clamped toglobMaxResultLimit.Why it matters: a caller passing a very large
limitmakes the handler buffer that manyrgmatch lines into memory before the daemon ever caps it, the same class of unbounded-memory-growth issue #6176 fixed for request bodies. Both close variants of the daemon getting killed mid-run by a missed health probe.Fix: add
grepMaxResultLimit(10000, matching Glob's cap) and clamp the effective limit to it, same pattern already used byGlob.Regression test:
TestGrepCapsCallerSuppliedLimitinfs_test.goseeds a file with more matching lines than the cap, requests alimitfar above it, and asserts the response'smatchCountnever exceedsgrepMaxResultLimit. It skips locally ifrgisn't installed but runs for real in CI (sandbox-daemon.ymlinstalls ripgrep).Reviewer command:
cd packages/sandbox/daemon-go && go test ./internal/routes/... -run TestGrepCapsCallerSuppliedLimit -v(needs ripgrep installed to actually exercise the cap; otherwise it self-skips).Locally verified:
go build ./...,go vet ./internal/routes/...,go test ./internal/routes/...,gofmt -l(clean) inpackages/sandbox/daemon-go. Full CI (including the ripgrep-backed test run) validates the rest.Summary by cubic
Caps the Go sandbox daemon’s
/grepresults at 10,000 and clamps caller-suppliedlimitto prevent unbounded memory usage. Previously/grepaccepted anylimitand could buffer arbitrarily manyrgmatch lines; now it uses min(requested, 10,000), matching/glob.grepMaxResultLimit(10000) andgrepDefaultResultLimit(250); default behavior is unchanged, large limits are now clamped inpackages/sandbox/daemon-go/internal/routes/fs.go.TestGrepCapsCallerSuppliedLimitinfs_test.go; run with:cd packages/sandbox/daemon-go && go test ./internal/routes/... -run TestGrepCapsCallerSuppliedLimit -v(requires ripgrep installed).Written for commit ebd7eea. Summary will update on new commits.