Skip to content

bug: router panic on malformed sandbox endpoint due to unhandled url.Parse error in buildURL #269

@sicaario

Description

@sicaario

What happened:

The buildURL function in the router silently discards the error returned by url.Parse. When a sandbox entry point contains a malformed or empty endpoint string, url.Parse returns nil for the URL along with an error — but the error is thrown away with _. That nil URL is then returned to determineUpstreamURL, which wraps it in a successful (*url.URL, nil) return, giving the caller no indication anything went wrong. Downstream, httputil.NewSingleHostReverseProxy(nil) is called with that nil pointer, causing a panic that crashes the router process.

// pkg/router/handlers.go
func buildURL(protocol, endpoint string) *url.URL {
    ...
    url, _ := url.Parse(endpoint)  // error silently dropped
    return url                      // may return nil
}

What you expected to happen:

A malformed or empty endpoint in a sandbox's entry points should result in a descriptive HTTP error response (e.g. 500 Internal Server Error or 502 Bad Gateway) — not a router panic. The error from url.Parse should be propagated up through determineUpstreamURL so forwardToSandbox can handle it gracefully and return an error to the client.

How to reproduce it (as minimally and precisely as possible):

  1. Register a sandbox whose EntryPoints contains an entry with a malformed endpoint (e.g. "://\x00bad" or an empty string "").
  2. Send any HTTP request to the router that resolves to that sandbox (e.g. GET /agents/{namespace}/{name}/).
  3. The router calls buildURL → gets a nil *url.URL → passes it to httputil.NewSingleHostReverseProxy(nil)panic / router crash.

Anything else we need to know?:

The fix is straightforward — change buildURL to return (*url.URL, error), propagate the error up through determineUpstreamURL, and handle it in forwardToSandbox the same way other URL errors are already handled (log + return HTTP error). No API surface changes required, this is entirely internal to the router package.

Relevant call chain:
forwardToSandboxdetermineUpstreamURLbuildURLhttputil.NewSingleHostReverseProxy

Environment:

  • AgentCube version: main (commit 7502b78)
  • Kubernetes version: N/A (reproducible at unit test level without a cluster)
  • Others: affects the router component (cmd/router) only

Metadata

Metadata

Assignees

Labels

kind/bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions