{"record":{"id":"a5c0bdb067c48d14","repo":"juanfont/headscale","slug":"leading-0-not-permitted-in-protocol-number","errorCode":null,"errorMessage":"leading 0 not permitted in protocol number","messagePattern":"leading 0 not permitted in protocol number","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hscontrol/policy/v2/types.go","lineNumber":132,"sourceCode":"\tErrHostResolve                 = errors.New(\"error resolving host\")\n\tErrInvalidPrefix               = errors.New(\"invalid prefix\")\n\tErrInvalidAutogroup            = errors.New(\"invalid autogroup\")\n\tErrUnknownAutogroup            = errors.New(\"unknown autogroup\")\n\tErrHostportMissingColon        = errors.New(\"hostport must contain a colon\")\n\tErrTypeNotSupported            = errors.New(\"type not supported\")\n\tErrInvalidAlias                = errors.New(\"invalid alias format\")\n\tErrInvalidAutoApprover         = errors.New(\"invalid auto approver format\")\n\tErrInvalidOwner                = errors.New(\"invalid owner format\")\n\tErrGroupNotDefined             = errors.New(\"group not defined in policy\")\n\tErrInvalidGroupMember          = errors.New(\"invalid group member type\")\n\tErrGroupValueNotArray          = errors.New(\"group value must be an array of users\")\n\tErrInvalidHostIP               = errors.New(\"hostname contains invalid IP address\")\n\tErrTagNotDefined               = errors.New(\"tag not found\")\n\tErrAutoApproverNotAlias        = errors.New(\"auto approver is not an alias\")\n\tErrInvalidACLAction            = errors.New(\"invalid ACL action\")\n\tErrInvalidSSHAction            = errors.New(\"invalid SSH action\")\n\tErrInvalidProtocolNumber       = errors.New(\"invalid protocol number\")\n\tErrProtocolLeadingZero         = errors.New(\"leading 0 not permitted in protocol number\")\n\tErrProtocolOutOfRange          = errors.New(\"protocol number out of range (0-255)\")\n\tErrAutogroupNotSupported       = errors.New(\"autogroup not supported in headscale\")\n\tErrAutogroupInternetSrc        = errors.New(\"autogroup:internet can only be used in ACL destinations\")\n\tErrAutogroupSelfSrc            = errors.New(\"\\\"autogroup:self\\\" not valid on the src side of a rule\")\n\tErrAutogroupNotSupportedACLSrc = errors.New(\"autogroup not supported for ACL sources\")\n\tErrAutogroupNotSupportedACLDst = errors.New(\"autogroup not supported for ACL destinations\")\n\tErrAutogroupDangerAllDst       = errors.New(\"cannot use autogroup:danger-all as a dst\")\n\tErrAutogroupNotSupportedSSHSrc = errors.New(\"autogroup not supported for SSH sources\")\n\tErrAutogroupNotSupportedSSHDst = errors.New(\"autogroup not supported for SSH destinations\")\n\tErrHostNotDefined              = errors.New(\"host not defined in policy\")\n\tErrSSHSourceAliasNotSupported  = errors.New(\"alias not supported for SSH source\")\n\tErrSSHDestAliasNotSupported    = errors.New(\"alias not supported for SSH destination\")\n\tErrUnknownField                = errors.New(\"unknown field\")\n\tErrProtocolNoSpecificPorts     = errors.New(\"protocol does not support specific ports\")\n\tErrTestEmptyAssertions         = errors.New(\"test entry must have at least one of \\\"accept\\\" or \\\"deny\\\"\")\n\tErrTestProtocolNotAllowed      = errors.New(\"test protocol must be tcp, udp, sctp, or empty\")\n\tErrTestDestinationMultiPort    = errors.New(\"test destination port must be a single port\")\n\tErrTestDestinationCIDR         = errors.New(\"test destination must be a single host, not a CIDR range\")","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/hscontrol/policy/v2/types.go#L114-L150","documentation":"Returned by Protocol.validate (hscontrol/policy/v2/types.go:1770) when a numeric \"proto\" value starts with a zero — including the bare string \"0\" — mirroring Tailscale's strict parsing. Leading-zero forms like \"006\" or \"017\" are rejected even though they'd be numerically valid, to keep canonical representation.","triggerScenarios":"Policy with \"proto\": \"006\", \"proto\": \"017\", or \"proto\": \"0\". Note that the bare \"0\" also triggers this even though 0 is in the valid numeric range; there is no way to write protocol 0 numerically.","commonSituations":"Zero-padding protocol numbers for alignment, copying fixed-width tables, or scripts generating policies with %03d formatting.","solutions":["Strip leading zeros: \"06\" → \"6\", \"017\" → \"17\"","Prefer the protocol name (tcp, udp, ...) where one exists","For protocol 0, omit \"proto\" from the rule instead of writing \"0\""],"exampleFix":"// before\n{\"action\": \"accept\", \"proto\": \"017\", \"src\": [\"*\"], \"dst\": [\"tag:dns:53\"]}\n\n// after\n{\"action\": \"accept\", \"proto\": \"udp\", \"src\": [\"*\"], \"dst\": [\"tag:dns:53\"]}","handlingStrategy":"validation","validationCode":"func canonicalProto(s string) bool {\n\tif len(s) > 1 && s[0] == '0' {\n\t\treturn false // leading zero\n\t}\n\treturn s != \"0\"\n}","typeGuard":"func isProtocolLeadingZero(err error) bool {\n\treturn errors.Is(err, policy.ErrProtocolLeadingZero)\n}","tryCatchPattern":"if err := json.Unmarshal(b, &acl); err != nil {\n\tif errors.Is(err, policy.ErrProtocolLeadingZero) {\n\t\treturn fmt.Errorf(\"strip leading zeros from proto (and never write \\\"0\\\"; omit proto instead): %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Never zero-pad protocol numbers in generated policies","For protocol 0 / all protocols, omit the proto field entirely","Prefer names (tcp, udp) over numbers to sidestep formatting rules"],"tags":["policy","acl","protocol","validation"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}