{"record":{"id":"9745869a64b4d4c3","repo":"projectdiscovery/nuclei","slug":"invalid-protocol-type-valuetomap","errorCode":null,"errorMessage":"Invalid protocol type: {valueToMap}","messagePattern":"Invalid protocol type: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/templates/types/types.go","lineNumber":91,"sourceCode":"func SupportedProtocolsStrings() []string {\n\tvar result []string\n\tfor _, protocol := range GetSupportedProtocolTypes() {\n\t\tif protocol.String() == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tresult = append(result, protocol.String())\n\t}\n\treturn result\n}\n\nfunc toProtocolType(valueToMap string) (ProtocolType, error) {\n\tnormalizedValue := normalizeValue(valueToMap)\n\tfor key, currentValue := range protocolMappings {\n\t\tif normalizedValue == currentValue {\n\t\t\treturn key, nil\n\t\t}\n\t}\n\treturn -1, errors.New(\"Invalid protocol type: \" + valueToMap)\n}\n\nfunc normalizeValue(value string) string {\n\treturn strings.TrimSpace(strings.ToLower(value))\n}\n\nfunc (t ProtocolType) String() string {\n\treturn protocolMappings[t]\n}\n\n// TypeHolder is used to hold internal type of the protocol\ntype TypeHolder struct {\n\tProtocolType ProtocolType `mapping:\"true\"`\n}\n\nfunc (holder TypeHolder) JSONSchema() *jsonschema.Schema {\n\tgotType := &jsonschema.Schema{\n\t\tType:        \"string\",","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/projectdiscovery/nuclei/blob/265b3a3dec374741614e342f813c10f8b38d2bb7/pkg/templates/types/types.go#L73-L109","documentation":"toProtocolType (pkg/templates/types/types.go:84-92) maps a protocol string to ProtocolType after TrimSpace+ToLower and rejects anything not present in protocolMappings. Accepted strings are exactly: dns, file, http, headless, tcp, workflow, ssl, websocket, whois, code, javascript (case-insensitive). Note the network protocol's string form is 'tcp' (not 'network'), and 'offline-http' exists as a Go constant but is absent from the mapping, so both spellings fail. The error propagates from TypeHolder.UnmarshalYAML (used by catalog index/tag filters) and ProtocolTypes.UnmarshalYAML, rejecting the template or filter value.","triggerScenarios":"A template or index filter with a `type:` value like 'https', 'network', 'offline-http', or any typo; feeding -type/-tags filter values through ProtocolTypes.Set or UnmarshalYAML; SDK calls that decode a TypeHolder from YAML/JSON with an unknown protocol string.","commonSituations":"Hand-edited templates assuming 'network' is the string for network protocol; templates targeting offline-http scanning; schema drift after nuclei upgrades adding new protocols not known to an older binary.","solutions":["Set the type to one of the exact accepted strings: dns, file, http, headless, tcp, workflow, ssl, websocket, whois, code, javascript","Use 'tcp' for the network protocol, never 'network'","Validate templates/filters before scanning with `nuclei -validate`","Enumerate allowed values programmatically via types.SupportedProtocolsStrings() and reject unknown input early"],"exampleFix":"# before (template or filter)\ntype: network\n\n# after\ntype: tcp","handlingStrategy":"validation","validationCode":"import \"strings\"\nimport \"github.com/projectdiscovery/nuclei/v3/pkg/templates/types\"\n\nfunc validProtocolType(v string) bool {\n    n := strings.ToLower(strings.TrimSpace(v))\n    for _, s := range types.SupportedProtocolsStrings() {\n        if n == s { return true }\n    }\n    return false\n}\n\nif !validProtocolType(tplType) {\n    return fmt.Errorf(\"unsupported protocol type %q (allowed: %v)\", tplType, types.SupportedProtocolsStrings())\n}","typeGuard":"func isSupportedProtocol(v string) bool {\n    switch strings.ToLower(strings.TrimSpace(v)) {\n    case \"dns\", \"file\", \"http\", \"headless\", \"tcp\", \"workflow\", \"ssl\", \"websocket\", \"whois\", \"code\", \"javascript\":\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Treat protocol type strings as an enum generated from types.SupportedProtocolsStrings(), never free text","Remember the network protocol string is 'tcp'","Run nuclei -validate on template changes in CI"],"tags":["go","nuclei","yaml","templates","protocol-type","validation"],"backgroundTag":null,"analyzedSha":"265b3a3dec374741614e342f813c10f8b38d2bb7","analyzedAt":"2026-08-15T20:05:51.855Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}