fix(shared): enforce valid port boundaries and fix error assertion in proxy target parser - #3431
Open
chill-czar wants to merge 1 commit into
Open
Conversation
… proxy target parser
chill-czar
requested review from
ValentaTomas,
dobrac and
jakubno
as code owners
July 28, 2026 18:23
Contributor
Author
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 #3430
Summary
1 <= port <= 65535) toparseHostandparseHeadersinpackages/shared/pkg/proxy/host.goerrors.Astarget type inpackages/shared/pkg/proxy/handler.gofrom*InvalidSandboxPortError(pointer target) toInvalidSandboxPortError(value struct target)TestGetTargetFromRequestinpackages/shared/pkg/proxy/host_test.goto properly verifyInvalidSandboxPortErrorconcrete type0and out-of-range ports (65536,70000) for both URL subdomains andE2b-Sandbox-Portheaders inhost_test.goTestProxyInvalidSandboxPortErrorintegration test inpackages/shared/pkg/proxy/proxy_test.goasserting HTTP400 Bad Request("Invalid sandbox port")Why
parseHostandparseHeadersparsed ports usingstrconv.ParseUintintouint64without enforcing valid TCP port boundaries. Passing port0(e.g.0-sandboxid.e2b.apporE2b-Sandbox-Port: 0) or out-of-range ports returnedport = 0, causing downstream proxy dialers to attempt invalid dials to port 0.handler.go,var invalidPortErr *InvalidSandboxPortErrorwas passed as a target toerrors.As. Becausehost.goreturnsInvalidSandboxPortErroras a value struct (InvalidSandboxPortError{...}), double-pointer indirection (**InvalidSandboxPortError) causederrors.Asto returnfalsefor all invalid port errors. This allowed invalid port errors to fall through to uncaught error handling rather than returning400 Bad Request.host_test.go,require.ErrorAs(t, err, &tt.wantErrIs)executederrors.As(err, (*error))against anilerrorinterface, which matched any non-nil error and allowed error-type mismatches to pass silently.Test Plan
go test -v ./packages/shared/pkg/proxy/...0and> 65535handling returnsInvalidSandboxPortError400 Bad Request("Invalid sandbox port") whenInvalidSandboxPortErroroccursrequire.ErrorAscorrectly asserts error types inTestGetTargetFromRequest/cc @jakubno @dobrac @ValentaTomas @arkamar @tvi