3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 13:29:27 +01:00

Restrict ident length similar to other servers

This commit is contained in:
Daniel Oaks 2019-02-03 19:24:59 +10:00
parent 8cd5db1194
commit cfbb4361dc
4 changed files with 17 additions and 7 deletions

View File

@ -176,12 +176,12 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) {
client.Notice(client.t("*** Looking up your username"))
resp, err := ident.Query(clientHost, serverPort, clientPort, IdentTimeoutSeconds)
if err == nil {
username := resp.Identifier
cfusername, err := CasefoldName(username)
if err == nil {
ident := resp.Identifier[:config.Limits.IdentLen-1]
if isIdent(ident) {
identLower := strings.ToLower(ident) // idents can only be ASCII chars only
client.Notice(client.t("*** Found your username"))
client.username = username
client.usernameCasefolded = cfusername
client.username = ident
client.usernameCasefolded = identLower
// we don't need to updateNickMask here since nickMask is not used for anything yet
} else {
client.Notice(client.t("*** Got a malformed username, ignoring"))

View File

@ -206,12 +206,13 @@ type Limits struct {
AwayLen int `yaml:"awaylen"`
ChanListModes int `yaml:"chan-list-modes"`
ChannelLen int `yaml:"channellen"`
IdentLen int `yaml:"identlen"`
KickLen int `yaml:"kicklen"`
LineLen LineLenLimits `yaml:"linelen"`
MonitorEntries int `yaml:"monitor-entries"`
NickLen int `yaml:"nicklen"`
TopicLen int `yaml:"topiclen"`
WhowasEntries int `yaml:"whowas-entries"`
LineLen LineLenLimits `yaml:"linelen"`
}
// STSConfig controls the STS configuration/
@ -491,6 +492,10 @@ func LoadConfig(filename string) (config *Config, err error) {
if len(config.Server.Listen) == 0 {
return nil, ErrNoListenersDefined
}
//dan: automagically fix identlen until a few releases in the future (from now, 0.12.0), being a newly-introduced limit
if config.Limits.IdentLen < 1 {
config.Limits.IdentLen = 10
}
if config.Limits.NickLen < 1 || config.Limits.ChannelLen < 2 || config.Limits.AwayLen < 1 || config.Limits.KickLen < 1 || config.Limits.TopicLen < 1 {
return nil, ErrLimitsAreInsane
}

View File

@ -2193,7 +2193,9 @@ func userHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
return false
}
err := client.SetNames(msg.Params[0], msg.Params[3])
ident := msg.Params[0][:server.Limits().IdentLen-1] // -1 as SetNames adds the ~ at the start for us
err := client.SetNames(ident, msg.Params[3])
if err == errInvalidUsername {
rb.Add(nil, server.name, ERR_INVALIDUSERNAME, client.t("Malformed username"))
}

View File

@ -415,6 +415,9 @@ limits:
# nicklen is the max nick length allowed
nicklen: 32
# identlen is the max ident length allowed
identlen: 10
# channellen is the max channel length allowed
channellen: 64