Skip to content

Secure, Fast, and Extensible Sandbox runtime for AI agents.

fix(egress): reject explicit zero resolve port; audit SNI-gate denials

高然246c94d9404a
diff --git a/components/egress/pkg/credentialvault/resolve_handler.go b/components/egress/pkg/credentialvault/resolve_handler.go
index 79d5b48f5..4637d6154 100644
--- a/components/egress/pkg/credentialvault/resolve_handler.go
+++ b/components/egress/pkg/credentialvault/resolve_handler.go
@@ -148,14 +148,12 @@ func (h *ResolveHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
writeResolveError(w, http.StatusBadRequest, "malformed request")
return
}
- destination, frame, targetErr := buildResolveTarget(document)
- if targetErr != nil {
- writeResolveError(w, targetErr.status, targetErr.reason)
- return
- }
+ // Audit starts after decoding but before target validation: a decoded
+ // request that is then denied (SNI gate, invalid target) is a resolution
+ // decision; only undecodable requests carry no event.
started := time.Now()
- event := ResolveAuditEvent{Binding: document.Binding, TargetHost: frame.Host}
+ event := ResolveAuditEvent{Binding: document.Binding, TargetHost: strings.TrimSpace(document.Request.Host)}
outcome := telemetry.ResolutionOutcomeDenied
defer func() {
event.Resolution = outcome
@@ -163,6 +161,13 @@ func (h *ResolveHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
h.audit(event)
}()
+ destination, frame, targetErr := buildResolveTarget(document)
+ if targetErr != nil {
+ writeResolveError(w, targetErr.status, targetErr.reason)
+ return
+ }
+ event.TargetHost = frame.Host
+
access, accessErr := h.access(r)
if accessErr != nil {
writeResolveError(w, accessErr.Status, accessErr.Reason)
@@ -287,8 +292,11 @@ type resolveEndpointHTTPRequest struct {
Scheme string
Host string
Port int
- Method string
- Path string
+ // PortPresent distinguishes an explicit "port" from an absent one: an
+ // explicit port is validated in full (0 is not the scheme default).
+ PortPresent bool
+ Method string
+ Path string
}
// decodeResolveRequest strictly decodes the addon request: exact field sets,
@@ -345,6 +353,7 @@ func decodeResolveRequest(data []byte) (resolveEndpointRequest, error) {
if err := json.Unmarshal(trimmed, &document.Request.Port); err != nil {
return resolveEndpointRequest{}, errors.New("port must be an integer")
}
+ document.Request.PortPresent = true
}
return document, nil
}
@@ -377,7 +386,7 @@ func buildResolveTarget(document resolveEndpointRequest) (ResolveDestination, Re
return ResolveDestination{}, ResolveRequestFrame{}, badRequest
}
port := document.Request.Port
- if port == 0 {
+ if !document.Request.PortPresent {
if scheme == "https" {
port = 443
} else {
diff --git a/components/egress/pkg/credentialvault/resolve_handler_test.go b/components/egress/pkg/credentialvault/resolve_handler_test.go
index 179a822fe..e4254efb7 100644
--- a/components/egress/pkg/credentialvault/resolve_handler_test.go
+++ b/components/egress/pkg/credentialvault/resolve_handler_test.go
@@ -233,6 +233,12 @@ func TestResolveHandlerRequestDiscipline(t *testing.T) {
{"null port", http.MethodPost, "application/json",
`{"binding":"internal-api","sni":"api.internal.example.com","request":{"scheme":"https","host":"api.internal.example.com","port":null,"method":"GET","path":"/"}}`,
http.StatusBadRequest, "malformed request"},
+ {"explicit zero port", http.MethodPost, "application/json",
+ `{"binding":"internal-api","sni":"api.internal.example.com","request":{"scheme":"https","host":"api.internal.example.com","port":0,"method":"GET","path":"/"}}`,
+ http.StatusBadRequest, "malformed request"},
+ {"negative port", http.MethodPost, "application/json",
+ `{"binding":"internal-api","sni":"api.internal.example.com","request":{"scheme":"https","host":"api.internal.example.com","port":-443,"method":"GET","path":"/"}}`,
+ http.StatusBadRequest, "malformed request"},
{"out-of-range port", http.MethodPost, "application/json",
`{"binding":"internal-api","sni":"api.internal.example.com","request":{"scheme":"https","host":"api.internal.example.com","port":65536,"method":"GET","path":"/"}}`,
http.StatusBadRequest, "malformed request"},
@@ -281,6 +287,12 @@ func TestResolveHandlerSNIGate(t *testing.T) {
require.Equal(t, http.StatusForbidden, rec.Code)
require.Equal(t, "forbidden", strings.TrimSpace(rec.Body.String()))
require.Empty(t, h.client.recorded())
+ // The SNI-gate denial is a resolution decision: it carries the R10 audit
+ // and the closed-set outcome, unlike malformed requests.
+ require.Len(t, h.audits, 1)
+ require.Equal(t, "denied", h.audits[0].Resolution)
+ require.Equal(t, "internal-api", h.audits[0].Binding)
+ require.Equal(t, "api.internal.example.com", h.audits[0].TargetHost)
// Case and trailing-dot differences normalize to equality.
body = `{"binding":"internal-api","sni":"API.internal.example.com.",` +