{"record":{"id":"f497f8ee63922148","repo":"fatedier/frp","slug":"s-port-number-d-must-be-in-the-range-0-65535","errorCode":null,"errorMessage":"%s: port number %d must be in the range 0..65535","messagePattern":"(.+?): port number (.+?) must be in the range 0\\.\\.65535","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/v1/validation/common.go","lineNumber":42,"sourceCode":"func validateWebServerConfig(c *v1.WebServerConfig) error {\n\tif c.TLS != nil {\n\t\tif c.TLS.CertFile == \"\" {\n\t\t\treturn fmt.Errorf(\"tls.certFile must be specified when tls is enabled\")\n\t\t}\n\t\tif c.TLS.KeyFile == \"\" {\n\t\t\treturn fmt.Errorf(\"tls.keyFile must be specified when tls is enabled\")\n\t\t}\n\t}\n\n\treturn ValidatePort(c.Port, \"webServer.port\")\n}\n\n// ValidatePort checks that the network port is in range\nfunc ValidatePort(port int, fieldPath string) error {\n\tif 0 <= port && port <= 65535 {\n\t\treturn nil\n\t}\n\treturn fmt.Errorf(\"%s: port number %d must be in the range 0..65535\", fieldPath, port)\n}\n\nfunc validateLogConfig(c *v1.LogConfig) error {\n\tif !slices.Contains(SupportedLogLevels, c.Level) {\n\t\treturn fmt.Errorf(\"invalid log level, optional values are %v\", SupportedLogLevels)\n\t}\n\treturn nil\n}\n","sourceCodeStart":24,"sourceCodeEnd":51,"githubUrl":"https://github.com/fatedier/frp/blob/6c8a8d0a97d03b44e9528d30b30c70cb9d61b405/pkg/config/v1/validation/common.go#L24-L51","documentation":"ValidatePort rejects any port outside 0..65535. It is the shared range check used across frp config validation (webServer.port here, and reused for bind/local/remote ports elsewhere), with the field path interpolated so the message names which config key is wrong.","triggerScenarios":"webServer.port = 70000 or a negative value; also triggered via other call sites that pass their own fieldPath (e.g. proxy localPort). Integer overflow from env-var parsing (strconv without bounds) often lands here.","commonSituations":"Ports passed via environment variables or CLI flags parsed as int without range checks; YAML unquoted values interpreted oddly; copying a port from a URL like :808080.","solutions":["Set the named port field to a value in 0..65535 (prefer 1024+ for non-root)","If the value comes from env/flags, bounds-check before feeding it into config","Check for accidental string concatenation (e.g. \"7400\" + \"0\") in templated configs"],"exampleFix":"# before\n[webServer]\nport = 740000\n\n# after\n[webServer]\nport = 7400","handlingStrategy":"validation","validationCode":"func portInRange(p int) bool { return p >= 0 && p <= 65535 }\n// or reuse: validation.ValidatePort(p, \"field\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bounds-check env/flag-derived ports with strconv + range check before writing config","Use validation.ValidatePort directly in custom tooling"],"tags":["frp","config","port","validation","go"],"backgroundTag":null,"analyzedSha":"6c8a8d0a97d03b44e9528d30b30c70cb9d61b405","analyzedAt":"2026-08-15T06:53:27.215Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}