~emersion/soju-dev

Reject downstream NICK with illegal characters v1 APPLIED

Hubert Hirtz: 1
 Reject downstream NICK with illegal characters

 1 files changed, 15 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/soju-dev/patches/12027/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Reject downstream NICK with illegal characters Export this patch

This should avoid confusion when mixing up nickname and user name.
Also it avoid breaking downstreams (since '@' and '!' are used for host
masks).
---
 downstream.go | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/downstream.go b/downstream.go
index 9c1f7f7..73a2c55 100644
--- a/downstream.go
+++ b/downstream.go
@@ -57,6 +57,8 @@ var errAuthFailed = ircError{&irc.Message{
	Params:  []string{"*", "Invalid username or password"},
}}

const illegalNickChars = " :/@!*?"

// permanentDownstreamCaps is the list of always-supported downstream
// capabilities.
var permanentDownstreamCaps = map[string]string{
@@ -330,6 +332,12 @@ func (dc *downstreamConn) handleMessageUnregistered(msg *irc.Message) error {
		if err := parseMessageParams(msg, &nick); err != nil {
			return err
		}
		if strings.ContainsAny(nick, illegalNickChars) {
			return ircError{&irc.Message{
				Command: irc.ERR_ERRONEUSNICKNAME,
				Params:  []string{dc.nick, nick, "contains illegal characters"},
			}}
		}
		nickCf := Casefold(nick)
		if nickCf == serviceNickCf {
			return ircError{&irc.Message{
@@ -974,6 +982,13 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
			}
		}

		if strings.ContainsAny(nick, illegalNickChars) {
			return ircError{&irc.Message{
				Command: irc.ERR_ERRONEUSNICKNAME,
				Params:  []string{dc.nick, nick, "contains illegal characters"},
			}}
		}

		var err error
		dc.forEachNetwork(func(n *network) {
			if err != nil || (upstream != nil && upstream.network != n) {
-- 
2.28.0