Skip to content

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

fix(egress): reject empty https hosts and out-of-range ports on resolver endpoints

高然98519f800d69
diff --git a/components/egress/pkg/credentialvault/source_exchange.go b/components/egress/pkg/credentialvault/source_exchange.go
index 2b9cfe901..7b98c7045 100644
--- a/components/egress/pkg/credentialvault/source_exchange.go
+++ b/components/egress/pkg/credentialvault/source_exchange.go
@@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"net/url"
+ "strconv"
"strings"
)
@@ -70,9 +71,15 @@ func validateResolverEndpoint(endpoint string) (string, error) {
if err != nil {
return "", fmt.Errorf("exchange credential endpoint %q is not a valid https URL", endpoint)
}
- if parsed.Host == "" || parsed.User != nil {
+ if parsed.Hostname() == "" || parsed.User != nil {
return "", fmt.Errorf("exchange credential endpoint %q must address https://host[:port]", endpoint)
}
+ if port := parsed.Port(); port != "" {
+ value, err := strconv.Atoi(port)
+ if err != nil || value < 1 || value > 65535 {
+ return "", fmt.Errorf("exchange credential endpoint %q has an invalid port", endpoint)
+ }
+ }
if parsed.RawQuery != "" || parsed.Fragment != "" || parsed.RawFragment != "" {
return "", fmt.Errorf("exchange credential endpoint %q must not carry a query or fragment", endpoint)
}
diff --git a/components/egress/pkg/credentialvault/source_exchange_test.go b/components/egress/pkg/credentialvault/source_exchange_test.go
index d754e08ba..4ecdb3ced 100644
--- a/components/egress/pkg/credentialvault/source_exchange_test.go
+++ b/components/egress/pkg/credentialvault/source_exchange_test.go
@@ -45,6 +45,9 @@ func TestExchangeSourceFactoryRejects(t *testing.T) {
{"empty endpoint", `{"type":"exchange","endpoint":""}`},
{"http scheme", `{"type":"exchange","endpoint":"http://resolver.internal"}`},
{"bare host", `{"type":"exchange","endpoint":"resolver.internal:8443"}`},
+ {"empty host", `{"type":"exchange","endpoint":"https://:443"}`},
+ {"port out of range", `{"type":"exchange","endpoint":"https://resolver.internal:70000"}`},
+ {"port zero", `{"type":"exchange","endpoint":"https://resolver.internal:0"}`},
{"query string", `{"type":"exchange","endpoint":"https://resolver.internal/prefix?debug=1"}`},
{"fragment", `{"type":"exchange","endpoint":"https://resolver.internal/prefix#section"}`},
{"unix relative path", `{"type":"exchange","endpoint":"unix://spi.sock"}`},