projectdiscovery/nuclei · error

Invalid protocol type: {valueToMap}

Error message

Invalid protocol type: {valueToMap}

What it means

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.

Source

Thrown at pkg/templates/types/types.go:91

func SupportedProtocolsStrings() []string {
	var result []string
	for _, protocol := range GetSupportedProtocolTypes() {
		if protocol.String() == "" {
			continue
		}
		result = append(result, protocol.String())
	}
	return result
}

func toProtocolType(valueToMap string) (ProtocolType, error) {
	normalizedValue := normalizeValue(valueToMap)
	for key, currentValue := range protocolMappings {
		if normalizedValue == currentValue {
			return key, nil
		}
	}
	return -1, errors.New("Invalid protocol type: " + valueToMap)
}

func normalizeValue(value string) string {
	return strings.TrimSpace(strings.ToLower(value))
}

func (t ProtocolType) String() string {
	return protocolMappings[t]
}

// TypeHolder is used to hold internal type of the protocol
type TypeHolder struct {
	ProtocolType ProtocolType `mapping:"true"`
}

func (holder TypeHolder) JSONSchema() *jsonschema.Schema {
	gotType := &jsonschema.Schema{
		Type:        "string",

View on GitHub (pinned to 265b3a3dec)

Solutions

  1. Set the type to one of the exact accepted strings: dns, file, http, headless, tcp, workflow, ssl, websocket, whois, code, javascript
  2. Use 'tcp' for the network protocol, never 'network'
  3. Validate templates/filters before scanning with `nuclei -validate`
  4. Enumerate allowed values programmatically via types.SupportedProtocolsStrings() and reject unknown input early

Example fix

# before (template or filter)
type: network

# after
type: tcp
Defensive patterns

Strategy: validation

Validate before calling

import "strings"
import "github.com/projectdiscovery/nuclei/v3/pkg/templates/types"

func validProtocolType(v string) bool {
    n := strings.ToLower(strings.TrimSpace(v))
    for _, s := range types.SupportedProtocolsStrings() {
        if n == s { return true }
    }
    return false
}

if !validProtocolType(tplType) {
    return fmt.Errorf("unsupported protocol type %q (allowed: %v)", tplType, types.SupportedProtocolsStrings())
}

Type guard

func isSupportedProtocol(v string) bool {
    switch strings.ToLower(strings.TrimSpace(v)) {
    case "dns", "file", "http", "headless", "tcp", "workflow", "ssl", "websocket", "whois", "code", "javascript":
        return true
    }
    return false
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of projectdiscovery/nuclei@265b3a3dec (2026-08-15). Data as JSON: /api/errors/9745869a64b4d4c3. Report an issue: GitHub.