{"record":{"id":"5f6724883f5fc103","repo":"JuliusBrussee/caveman","slug":"ssrf-managed-mode-requires-port-443","errorCode":null,"errorMessage":"ssrf: managed mode requires port 443","messagePattern":"ssrf: managed mode requires port 443","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/ssrf/ssrf.go","lineNumber":227,"sourceCode":"\tu, parseErr := url.Parse(raw)\n\tif parseErr != nil {\n\t\t// net/url.Error includes the raw URL (and may therefore include\n\t\t// credentials or query secrets). Keep this error field-only and stable.\n\t\treturn \"\", \"\", errors.New(\"ssrf: invalid URL\")\n\t}\n\tif u.Scheme != \"https\" && !(u.Scheme == \"http\" && !cfg.ManagedMode) {\n\t\treturn \"\", \"\", fmt.Errorf(\"ssrf: scheme %q not permitted (managed mode requires https)\", u.Scheme)\n\t}\n\tif u.User != nil {\n\t\treturn \"\", \"\", fmt.Errorf(\"ssrf: credentials embedded in URL are forbidden\")\n\t}\n\thost = u.Hostname()\n\tif host == \"\" {\n\t\treturn \"\", \"\", fmt.Errorf(\"ssrf: URL must contain a host\")\n\t}\n\tport = u.Port()\n\tif cfg.ManagedMode && port != \"\" && port != \"443\" {\n\t\treturn \"\", \"\", errors.New(\"ssrf: managed mode requires port 443\")\n\t}\n\tif port == \"\" {\n\t\tif u.Scheme == \"https\" {\n\t\t\tport = \"443\"\n\t\t} else {\n\t\t\tport = \"80\"\n\t\t}\n\t}\n\treturn host, port, nil\n}\n\n// ValidateHost resolves host (bare hostname or IP literal) and checks all\n// resolved addresses.  Use when you have a host/port pair rather than a full\n// URL.\nfunc ValidateHost(ctx context.Context, host string, cfg Config) error {\n\treturn validateHostPort(ctx, host, \"\", cfg)\n}\n","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/ssrf/ssrf.go#L209-L245","documentation":"In managed mode (the strictest SSRF posture) the library only permits HTTPS on port 443. If the URL carries an explicit port that is anything other than 443, parseValidatedURL rejects it because non-standard ports are a common way to reach internal services. URLs with no explicit port are fine — the default 443 is applied.","triggerScenarios":"Calling ValidateURL or ValidateURLNoResolve in managed mode (cfg.ManagedMode = true) with URLs like \"https://host:8443/x\", \"https://host:8080/\" — an explicit non-443 port triggers this; \"https://host/\" (no port) does not.","commonSituations":"Pointing the client at a self-hosted service on a custom HTTPS port (8443, 9443) while managed mode is on; a dev/staging endpoint with an explicit port leaked into prod config; forgetting that managed mode forbids even https on alternate ports.","solutions":["Move the service behind standard port 443 (reverse proxy/load balancer) or drop the explicit :port from the URL and serve on 443.","If the alternate port is genuinely required and safe, construct the client without managed mode so http/custom ports are allowed per cfg.ManagedMode=false semantics.","Route through your operator proxy/gateway that terminates TLS on 443 and forwards to the service's real port."],"exampleFix":"// before (managed mode)\nclient, err := ssrf.ValidateURL(\"https://payments.internal:8443/v1/charge\")\n// after\nclient, err := ssrf.ValidateURL(\"https://payments.internal/v1/charge\") // serve on 443","handlingStrategy":"validation","validationCode":"func okForManagedMode(raw string) bool {\n    u, err := url.Parse(raw)\n    if err != nil || u.Scheme != \"https\" {\n        return false\n    }\n    p := u.Port()\n    return p == \"\" || p == \"443\"\n}","typeGuard":null,"tryCatchPattern":"if err := ssrf.ValidateURL(raw); err != nil && strings.Contains(err.Error(), \"managed mode requires port 443\") {\n    return fmt.Errorf(\"endpoint %s must be served on 443 in managed mode\", raw)\n}","preventionTips":["Keep managed-mode endpoints on standard 443 behind a load balancer","Omit explicit ports from managed-mode URLs","Add a config lint that checks managed-mode endpoints for non-443 ports at startup"],"tags":["ssrf","port-restriction","config","go"],"backgroundTag":"invalid-config-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}