{"record":{"id":"aa0a38e9650fcac8","repo":"Tencent/WeKnora","slug":"mcp-service-url-failed-ssrf-validation-w","errorCode":null,"errorMessage":"MCP service URL failed SSRF validation: %w","messagePattern":"MCP service URL failed SSRF validation: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/mcp/security.go","lineNumber":23,"sourceCode":"\t\"strings\"\n\n\t\"github.com/Tencent/WeKnora/internal/types\"\n\tsecutils \"github.com/Tencent/WeKnora/internal/utils\"\n)\n\n// ValidateServiceOutboundURLs validates every URL that the MCP transport or\n// OAuth discovery flow may contact. It is intentionally called both at\n// persistence boundaries and immediately before client construction so stale\n// or imported rows cannot bypass the current SSRF policy.\nfunc ValidateServiceOutboundURLs(service *types.MCPService) error {\n\tif service == nil {\n\t\treturn fmt.Errorf(\"MCP service is required\")\n\t}\n\tif service.URL != nil {\n\t\tserviceURL := strings.TrimSpace(*service.URL)\n\t\tif serviceURL != \"\" {\n\t\t\tif err := secutils.ValidateURLForSSRF(serviceURL); err != nil {\n\t\t\t\treturn fmt.Errorf(\"MCP service URL failed SSRF validation: %w\", err)\n\t\t\t}\n\t\t}\n\t}\n\tif service.AuthConfig != nil {\n\t\tmetadataURL := strings.TrimSpace(service.AuthConfig.AuthServerMetadataURL)\n\t\tif metadataURL != \"\" {\n\t\t\tif err := secutils.ValidateURLForSSRF(metadataURL); err != nil {\n\t\t\t\treturn fmt.Errorf(\"MCP OAuth metadata URL failed SSRF validation: %w\", err)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":5,"sourceCodeEnd":37,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/mcp/security.go#L5-L37","documentation":"ValidateServiceOutboundURLs in internal/mcp/security.go:23 wraps secutils.ValidateURLForSSRF when an MCP service's URL fails SSRF checks. The server refuses to persist or connect to an MCP service whose endpoint could be used for server-side request forgery (private IPs, localhost, non-HTTP schemes, unresolved DNS). The wrapped inner error describes the exact reason.","triggerScenarios":"Calling CreateMCPService, UpdateMCPService, NewMCPClient, or newHandler with a service whose *service.URL (after trimming) is non-empty and fails ValidateURLForSSRF — e.g. URL points to 127.0.0.1, 10.x/192.168.x metadata IPs, uses file:// or other non-http(s) schemes, or has no hostname.","commonSituations":"Registering a local dev MCP server (http://localhost:8080) in a deployed environment; pointing the service at an internal Kubernetes service or cloud metadata endpoint; pasting an SSE endpoint with an unsupported scheme; missing SSRF_WHITELIST entries for legitimate internal hosts.","solutions":["Change the MCP service URL to a publicly resolvable http/https endpoint.","If the host is legitimately internal, add its hostname to the SSRF_WHITELIST environment/config so IsSSRFWhitelisted skips the private-IP checks.","Read the wrapped %w error for the specific reason (invalid scheme, no hostname, SSRF validation failed) and fix accordingly.","Ensure the URL includes a hostname and uses http or https."],"exampleFix":"// before\nsvc := &types.MCPService{URL: strPtr(\"http://localhost:8080/sse\")}\nerr := mcp.ValidateServiceOutboundURLs(svc) // fails SSRF validation\n// after\nsvc := &types.MCPService{URL: strPtr(\"https://mcp.example.com/sse\")}\n// or add 'localhost' to SSRF_WHITELIST for trusted internal deployments\nerr := mcp.ValidateServiceOutboundURLs(svc) // nil","handlingStrategy":"validation","validationCode":"if err := secutils.ValidateURLForSSRF(strings.TrimSpace(*service.URL)); err != nil {\n    // refuse before calling CreateMCPService\n    return fmt.Errorf(\"unacceptable MCP URL: %w\", err)\n}","typeGuard":"func isPublicHTTPURL(raw string) bool {\n    u, err := url.Parse(raw)\n    return err == nil && (u.Scheme == \"http\" || u.Scheme == \"https\") && u.Hostname() != \"\"\n}","tryCatchPattern":null,"preventionTips":["Run ValidateURLForSSRF on any user-supplied endpoint in your own UI/API before persistence.","Maintain SSRF_WHITELIST for trusted internal hosts instead of weakening code.","Only use http/https URLs with explicit hostnames for MCP services."],"tags":["ssrf","security","validation","mcp"],"backgroundTag":"ssrf-url-validation-failed","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}