mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 02:00:11 -08:00
improve value validation
This commit is contained in:
parent
3e761ff68a
commit
f417f71bfa
3 changed files with 17 additions and 4 deletions
|
|
@ -728,7 +728,7 @@ type Config struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
MaxSubs int `yaml:"max-subs"`
|
MaxSubs int `yaml:"max-subs"`
|
||||||
MaxKeys int `yaml:"max-keys"`
|
MaxKeys int `yaml:"max-keys"`
|
||||||
MaxValueBytes int `yaml:"max-value-length"` // todo: currently unenforced!!
|
MaxValueBytes int `yaml:"max-value-length"`
|
||||||
}
|
}
|
||||||
|
|
||||||
WebPush struct {
|
WebPush struct {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/ergochat/irc-go/ircfmt"
|
"github.com/ergochat/irc-go/ircfmt"
|
||||||
"github.com/ergochat/irc-go/ircmsg"
|
"github.com/ergochat/irc-go/ircmsg"
|
||||||
|
|
@ -3104,7 +3105,8 @@ func metadataHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
|
||||||
originalTarget := msg.Params[0]
|
originalTarget := msg.Params[0]
|
||||||
target := originalTarget
|
target := originalTarget
|
||||||
|
|
||||||
if !server.Config().Metadata.Enabled {
|
config := server.Config()
|
||||||
|
if !config.Metadata.Enabled {
|
||||||
rb.Add(nil, server.name, "FAIL", "METADATA", "FORBIDDEN", originalTarget, "Metadata is disabled on this server")
|
rb.Add(nil, server.name, "FAIL", "METADATA", "FORBIDDEN", originalTarget, "Metadata is disabled on this server")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -3164,9 +3166,15 @@ func metadataHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
|
||||||
|
|
||||||
if len(msg.Params) > 3 {
|
if len(msg.Params) > 3 {
|
||||||
value := msg.Params[3]
|
value := msg.Params[3]
|
||||||
const maxCombinedLen = 350
|
|
||||||
|
|
||||||
if len(key)+len(value) > maxCombinedLen {
|
if !globalUtf8EnforcementSetting && !utf8.ValidString(value) {
|
||||||
|
rb.Add(nil, server.name, "FAIL", "METADATA", "VALUE_INVALID", client.t("METADATA values must be UTF-8"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(key)+len(value) > maxCombinedMetadataLenBytes ||
|
||||||
|
(config.Metadata.MaxValueBytes > 0 && len(value) > config.Metadata.MaxValueBytes) {
|
||||||
|
|
||||||
rb.Add(nil, server.name, "FAIL", "METADATA", "VALUE_INVALID", client.t("Value is too long"))
|
rb.Add(nil, server.name, "FAIL", "METADATA", "VALUE_INVALID", client.t("Value is too long"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,11 @@ import (
|
||||||
"github.com/ergochat/ergo/irc/modes"
|
"github.com/ergochat/ergo/irc/modes"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// metadata key + value need to be relayable on a single IRC RPL_KEYVALUE line
|
||||||
|
maxCombinedMetadataLenBytes = 350
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errMetadataTooManySubs = errors.New("too many subscriptions")
|
errMetadataTooManySubs = errors.New("too many subscriptions")
|
||||||
errMetadataNotFound = errors.New("key not found")
|
errMetadataNotFound = errors.New("key not found")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue