Wei-Shaw/sub2api · error
proxy port is invalid
Error message
proxy port is invalid
What it means
Returned by validateDataProxy (backend/internal/handler/admin/account_data.go:662) when a proxy entry's port is outside 1-65535 (port <= 0 or > 65535). It fires after protocol and host checks, before the protocol whitelist and status validation.
Source
Thrown at backend/internal/handler/admin/account_data.go:662
}
if payload.Proxies == nil {
return errors.New("proxies is required")
}
if payload.Accounts == nil {
return errors.New("accounts is required")
}
return nil
}
func validateDataProxy(item DataProxy) error {
if strings.TrimSpace(item.Protocol) == "" {
return errors.New("proxy protocol is required")
}
if strings.TrimSpace(item.Host) == "" {
return errors.New("proxy host is required")
}
if item.Port <= 0 || item.Port > 65535 {
return errors.New("proxy port is invalid")
}
switch item.Protocol {
case "http", "https", "socks5", "socks5h":
default:
return fmt.Errorf("proxy protocol is invalid: %s", item.Protocol)
}
if item.Status != "" {
normalizedStatus := normalizeProxyStatus(item.Status)
if normalizedStatus != service.StatusActive && normalizedStatus != "inactive" {
return fmt.Errorf("proxy status is invalid: %s", item.Status)
}
}
return nil
}
func validateDataAccount(item DataAccount) error {
if strings.TrimSpace(item.Name) == "" {
return errors.New("account name is required")View on GitHub (pinned to 073e92d171)
Solutions
- Set port to an integer between 1 and 65535 on the entry.
- If port was omitted intentionally for a default, write the default explicitly (e.g. 80 for http, 443 for https).
- Split combined 'host:port' strings before building the payload.
Example fix
// before
{ "protocol": "https", "host": "proxy.example.com" } // port 0
// after
{ "protocol": "https", "host": "proxy.example.com", "port": 443 } Defensive patterns
Strategy: validation
Validate before calling
function isValidProxyPort(port: unknown): boolean {
return typeof port === 'number' && Number.isInteger(port) && port >= 1 && port <= 65535
} Type guard
function isValidPort(p: unknown): p is number {
return typeof p === 'number' && Number.isInteger(p) && p >= 1 && p <= 65535
} Prevention
- Write the scheme's default port explicitly (80/443/1080) instead of omitting it.
- Use integer-only number inputs with min=1 max=65535 in forms.
- Never paste 'host:port' into the port field; split first.
When it happens
Trigger: port omitted (defaults to 0 in Go), set to a negative number, or above 65535 (e.g. a 32-bit overflow or a pasted value like '127.0.0.1:1080' jammed into the port field).
Common situations: Omitting port because the scheme implies one (http=80); spreadsheets reformatting ports as numbers with thousands separators; copy-paste of full URLs into the port field.
Related errors
- proxy protocol is required
- proxy host is required
- 空 JSON 内容
- agent identity 缺少必要字段
- agent identity private key 格式无效
AI-assisted analysis of Wei-Shaw/sub2api@073e92d171 (2026-08-15).
Data as JSON: /api/errors/a3a7bf2db370bbab.
Report an issue: GitHub.