3
0
mirror of https://github.com/ergochat/ergo.git synced 2026-03-18 13:18:08 +01:00
Allow restricting metadata modification to server operators
This commit is contained in:
Shivaram Lingamneni 2026-03-17 11:33:11 -07:00 committed by GitHub
parent 9e61528711
commit 937bad6717
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 7 deletions

View File

@ -1150,6 +1150,8 @@ allow-environment-overrides: true
metadata:
# can clients store metadata?
enabled: true
# if this is true, only server operators with the `metadata` capability can edit metadata:
operator-only-modification: false
# how many keys can a client subscribe to?
max-subs: 100
# how many keys can be stored per entity?

View File

@ -715,11 +715,12 @@ type Config struct {
}
Metadata struct {
Enabled bool
MaxSubs int `yaml:"max-subs"`
MaxKeys int `yaml:"max-keys"`
MaxValueBytes int `yaml:"max-value-length"`
ClientThrottle ThrottleConfig `yaml:"client-throttle"`
Enabled bool
OperatorOnlyModification bool `yaml:"operator-only-modification"`
MaxSubs int `yaml:"max-subs"`
MaxKeys int `yaml:"max-keys"`
MaxValueBytes int `yaml:"max-value-length"`
ClientThrottle ThrottleConfig `yaml:"client-throttle"`
}
WebPush struct {

View File

@ -3148,7 +3148,7 @@ func markReadHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
func metadataHandler(server *Server, client *Client, msg ircmsg.Message, rb *ResponseBuffer) (exiting bool) {
config := server.Config()
if !config.Metadata.Enabled {
rb.Add(nil, server.name, "FAIL", "METADATA", "FORBIDDEN", utils.SafeErrorParam(msg.Params[0]), "Metadata is disabled on this server")
rb.Add(nil, server.name, "FAIL", "METADATA", "FORBIDDEN", utils.SafeErrorParam(msg.Params[0]), client.t("Metadata is disabled on this server"))
return
}
@ -3163,7 +3163,13 @@ func metadataHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
case "sub", "unsub", "subs":
// these are session-local and function the same whether or not the client is registered
return metadataSubsHandler(client, subcommand, msg.Params, rb)
case "get", "set", "list", "clear", "sync":
case "set", "clear":
if config.Metadata.OperatorOnlyModification && !client.HasRoleCapabs("metadata") {
rb.Add(nil, server.name, "FAIL", "METADATA", "FORBIDDEN", utils.SafeErrorParam(msg.Params[0]), client.t("Only server operators can modify metadata"))
return
}
fallthrough
case "get", "list", "sync":
if client.registered {
return metadataRegisteredHandler(client, config, subcommand, msg.Params, rb)
} else {

View File

@ -1121,6 +1121,8 @@ allow-environment-overrides: true
metadata:
# can clients store metadata?
enabled: true
# if this is true, only server operators with the `metadata` capability can edit metadata:
operator-only-modification: false
# how many keys can a client subscribe to?
max-subs: 100
# how many keys can be stored per entity?