fix(api): validate timeout is positive in PostSandboxesSandboxIDConnect - #3580
Open
chill-czar wants to merge 1 commit into
Open
fix(api): validate timeout is positive in PostSandboxesSandboxIDConnect#3580chill-czar wants to merge 1 commit into
chill-czar wants to merge 1 commit into
Conversation
chill-czar
requested review from
ValentaTomas,
dobrac and
jakubno
as code owners
August 17, 2026 19:52
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.
Closes #3579
Summary
if body.Timeout <= 0validation inPostSandboxesSandboxIDConnect(POST /sandboxes/{id}/connect), returning400 Bad Request("Timeout must be greater than 0") when timeout is non-positive.PostSandboxesSandboxIDConnectin alignment withPostSandboxes,PostSandboxesSandboxIDResume, andPostSandboxesSandboxIDFork.packages/api/internal/handlers/sandbox_timeout_validation_test.goverifying zero and negative timeout values are rejected early.Why
In
packages/api/internal/handlers/sandbox_connect.go,body.Timeoutwas only validated against the maximum length limit (MaxLengthHours). Supplying0or negative values resulted in a negative/zero sandbox lifetime passed tostartSandbox, which immediately terminated the connected sandbox due to the expiration timestamp being in the past.Diff Overview
body, err := ginutils.ParseBody[api.PostSandboxesSandboxIDConnectJSONRequestBody](ctx, c) if err != nil { a.sendAPIStoreError(c, http.StatusBadRequest, fmt.Sprintf("Error when parsing request: %s", err)) telemetry.ReportCriticalError(ctx, "error when parsing request", err) return } + if body.Timeout <= 0 { + a.sendAPIStoreError(c, http.StatusBadRequest, "Timeout must be greater than 0") + + return + } + timeout := time.Duration(body.Timeout) * time.Second if timeout > time.Duration(teamInfo.Limits.MaxLengthHours)*time.Hour { a.sendAPIStoreError(c, http.StatusBadRequest, fmt.Sprintf("Timeout cannot be greater than %d hours", teamInfo.Limits.MaxLengthHours))Test Plan
go test -v ./packages/api/internal/handlers -run TestSandboxConnect_RejectsNonPositiveTimeoutgo test -v ./packages/api/internal/handlers/...make fmtandmake linttimeout: 0andtimeout: -1return400 Bad Request("Timeout must be greater than 0")/cc @jakubno @dobrac @ValentaTomas @arkamar @tvi