downstream: check channel name validity on JOIN

Avoid storing garbage in the DB.
This commit is contained in:
Simon Ser 2022-12-08 15:25:39 +01:00
parent 58ee475265
commit 6d64c164a7

View File

@ -231,8 +231,15 @@ func updateNetworkAttrs(record *database.Network, attrs irc.Tags, subcommand str
// - '$' breaks server masks in PRIVMSG/NOTICE
// - ',' breaks lists
// - '.' is reserved for server names
//
// See https://modern.ircdocs.horse/#clients
const illegalNickChars = " :@!*?$,."
// illegalChanChars is the list of characters forbidden in a channel name.
//
// See https://modern.ircdocs.horse/#channels
const illegalChanChars = " ,\x07"
// permanentDownstreamCaps is the list of always-supported downstream
// capabilities.
var permanentDownstreamCaps = map[string]string{
@ -1808,6 +1815,14 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
key = keys[i]
}
if name == "" || strings.ContainsAny(name, illegalChanChars) {
dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(),
Command: irc.ERR_NOSUCHCHANNEL,
Params: []string{name, "Invalid channel name"},
})
continue
}
if !uc.isChannel(name) {
dc.SendMessage(&irc.Message{
Prefix: dc.srv.prefix(),