fix(sandbox): cap the Go daemon's file-edit path at 10MB - #6039
Open
pedrofrxncx wants to merge 1 commit into
Open
fix(sandbox): cap the Go daemon's file-edit path at 10MB#6039pedrofrxncx wants to merge 1 commit into
pedrofrxncx wants to merge 1 commit into
Conversation
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 the open PR #5608, which caps the plain-text
readroute at 10MB but leaves theeditroute (internal/routes/fs.go'sEdithandler) doing an unboundedos.ReadFileon the same untrusted repo files.A maintainer wants this because the edit route is the same trust boundary as read (any tool call can target an arbitrary file under the repo root), and it's exercised even more often (every write-side tool call), so a large generated file (a log, a lockfile, a big commit) reading unbounded into memory can OOM the daemon and take the sandbox pod down — the daemon's health probe then marks it dead mid-session.
Failure scenario: an agent calls edit on a >10MB text file in the repo; before this fix,
os.ReadFileloads the whole file (plus the computed replacement string) into memory with no bound. Regression test:TestEditRejectsOversizedFileinfs_edit_test.gowrites an 11MB fixture and asserts a 400 with a "too large" message;TestEditAllowsFileUnderCapasserts a normal small edit still succeeds.To verify:
cd packages/sandbox/daemon-go && go test ./internal/routes/... -run TestEdit -v.Locally ran:
gofmt -l,go vet ./internal/routes/...,go test ./internal/routes/...— all clean. Full CI validates the rest.Summary by cubic
Caps the
/_sandbox/editroute at 10MB to match the existing plain-textreadcap and prevent OOMs from unbounded file reads. Previously the handler read the whole file regardless of size; now files over 10MB return 400 "File too large" before reading.• Introduces
maxEditFileBytes = 10 * 1024 * 1024and a size check inEdit(packages/sandbox/daemon-go/internal/routes/fs.go).• Adds
TestEditRejectsOversizedFileandTestEditAllowsFileUnderCap(packages/sandbox/daemon-go/internal/routes/fs_edit_test.go).• Verify with:
cd packages/sandbox/daemon-go && go test ./internal/routes/... -run TestEdit -v.• Migration: callers of
/_sandbox/editmust avoid targeting files >10MB; such requests will receive 400.Written for commit 3f3676f. Summary will update on new commits.