{"record":{"id":"5080f7c1f36f3486","repo":"nsqio/nsq","slug":"invalid-arg-channel","errorCode":"INVALID_ARG_CHANNEL","errorMessage":"INVALID_ARG_CHANNEL","messagePattern":"INVALID_ARG_CHANNEL","errorType":"http","errorClass":"http_api.Err","httpStatus":400,"severity":"error","filePath":"internal/http_api/topic_channel_args.go","lineNumber":29,"sourceCode":"}\n\nfunc GetTopicChannelArgs(rp getter) (string, string, error) {\n\ttopicName, err := rp.Get(\"topic\")\n\tif err != nil {\n\t\treturn \"\", \"\", errors.New(\"MISSING_ARG_TOPIC\")\n\t}\n\n\tif !protocol.IsValidTopicName(topicName) {\n\t\treturn \"\", \"\", errors.New(\"INVALID_ARG_TOPIC\")\n\t}\n\n\tchannelName, err := rp.Get(\"channel\")\n\tif err != nil {\n\t\treturn \"\", \"\", errors.New(\"MISSING_ARG_CHANNEL\")\n\t}\n\n\tif !protocol.IsValidChannelName(channelName) {\n\t\treturn \"\", \"\", errors.New(\"INVALID_ARG_CHANNEL\")\n\t}\n\n\treturn topicName, channelName, nil\n}\n","sourceCodeStart":11,"sourceCodeEnd":34,"githubUrl":"https://github.com/nsqio/nsq/blob/85cf10c09c6c3c86160d6f0eb156f62d0efc1648/internal/http_api/topic_channel_args.go#L11-L34","documentation":"The channel value from the query string is validated with protocol.IsValidChannelName using the same rule as topics: ^[.a-zA-Z0-9_-]+(#ephemeral)?$ and 1..64 characters. Values that fail - including empty strings - return INVALID_ARG_CHANNEL and a 400 response from the HTTP handler.","triggerScenarios":"Passing channel= with an empty value (?topic=t&channel=), a channel containing spaces or slashes (channel=archive/2024), unicode, or a name longer than 64 characters. As with topics, the #ephemeral suffix is explicitly permitted.","commonSituations":"Auto-generating channel names per environment or customer without restricting the character set; passing a URL path fragment as channel; whitespace introduced by shell quoting or templating.","solutions":["Use only [.a-zA-Z0-9_-] characters, 1-64 long, e.g. channel=archive.","Sanitize generated channel names at consumer-subscribe time in your client library.","Trim whitespace and reject empty strings before issuing the request."],"exampleFix":"# before\ncurl -X POST 'http://127.0.0.1:4151/channel/create?topic=orders&channel=archive team'\n# after\ncurl -X POST 'http://127.0.0.1:4151/channel/create?topic=orders&channel=archive_team'","handlingStrategy":"validation","validationCode":"var validTopicChannelNameRegex = regexp.MustCompile(`^[.a-zA-Z0-9_-]+(#ephemeral)?$`)\n\nfunc isValidChannelName(name string) bool {\n\treturn len(name) >= 1 && len(name) <= 64 && validTopicChannelNameRegex.MatchString(name)\n}\n\nif !isValidChannelName(channel) {\n\treturn fmt.Errorf(\"invalid channel name %q\", channel)\n}","typeGuard":"func isValidChannelName(name string) bool {\n\treturn len(name) >= 1 && len(name) <= 64 && validTopicChannelNameRegex.MatchString(name)\n}","tryCatchPattern":"if resp.StatusCode == 400 && strings.Contains(string(body), \"INVALID_ARG_CHANNEL\") {\n\tchannel = sanitizeNSQName(channel)\n\t// note: subscribing to a new channel name starts a fresh stream - prefer fixing at the source\n}","preventionTips":["Validate channel names where they are configured (subscribe call), not where HTTP requests are issued.","Generate channels from allow-listed identifiers (env, customer id) mapped through a sanitizing function."],"tags":["nsq","http-api","validation","nsqd"],"backgroundTag":null,"analyzedSha":"85cf10c09c6c3c86160d6f0eb156f62d0efc1648","analyzedAt":"2026-08-16T00:53:05.009Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}