fix: resolve critical vulnerability V-001

Automatically generated security fix
This commit is contained in:
orbisai0security
2026-01-08 09:05:01 +00:00
committed by lyingbug
parent bdc9171242
commit e023c26af8
2 changed files with 94 additions and 0 deletions
+28
View File
@@ -4,7 +4,10 @@ import (
"context"
"encoding/json"
"fmt"
"net"
"net/http"
"net/url"
"strings"
"time"
"github.com/Tencent/WeKnora/internal/logger"
@@ -58,6 +61,31 @@ type mcpGoClient struct {
initialized bool
}
// validateURLScheme validates that authentication endpoints use HTTPS
func validateURLScheme(serviceURL string, hasBasicAuth bool, hasTokenAuth bool) error {
if !hasBasicAuth && !hasTokenAuth {
// No authentication, no HTTPS requirement
return nil
}
if serviceURL == "" {
return fmt.Errorf("URL is required")
}
// Parse the URL
parsedURL, err := url.Parse(serviceURL)
if err != nil {
return fmt.Errorf("invalid URL: %w", err)
}
// Enforce HTTPS for authenticated endpoints
if parsedURL.Scheme != "https" {
return fmt.Errorf("HTTPS is required for authenticated connections, got %s scheme", parsedURL.Scheme)
}
return nil
}
// NewMCPClient creates a new MCP client based on the transport type
func NewMCPClient(config *ClientConfig) (MCPClient, error) {
// Create HTTP client with timeout