Skip to content

Commit 937bad6

Browse files
authored
fix #2287 (#2369)
Allow restricting metadata modification to server operators
1 parent 9e61528 commit 937bad6

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

default.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,8 @@ allow-environment-overrides: true
11501150
metadata:
11511151
# can clients store metadata?
11521152
enabled: true
1153+
# if this is true, only server operators with the `metadata` capability can edit metadata:
1154+
operator-only-modification: false
11531155
# how many keys can a client subscribe to?
11541156
max-subs: 100
11551157
# how many keys can be stored per entity?

irc/config.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,12 @@ type Config struct {
715715
}
716716

717717
Metadata struct {
718-
Enabled bool
719-
MaxSubs int `yaml:"max-subs"`
720-
MaxKeys int `yaml:"max-keys"`
721-
MaxValueBytes int `yaml:"max-value-length"`
722-
ClientThrottle ThrottleConfig `yaml:"client-throttle"`
718+
Enabled bool
719+
OperatorOnlyModification bool `yaml:"operator-only-modification"`
720+
MaxSubs int `yaml:"max-subs"`
721+
MaxKeys int `yaml:"max-keys"`
722+
MaxValueBytes int `yaml:"max-value-length"`
723+
ClientThrottle ThrottleConfig `yaml:"client-throttle"`
723724
}
724725

725726
WebPush struct {

irc/handlers.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,7 +3148,7 @@ func markReadHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
31483148
func metadataHandler(server *Server, client *Client, msg ircmsg.Message, rb *ResponseBuffer) (exiting bool) {
31493149
config := server.Config()
31503150
if !config.Metadata.Enabled {
3151-
rb.Add(nil, server.name, "FAIL", "METADATA", "FORBIDDEN", utils.SafeErrorParam(msg.Params[0]), "Metadata is disabled on this server")
3151+
rb.Add(nil, server.name, "FAIL", "METADATA", "FORBIDDEN", utils.SafeErrorParam(msg.Params[0]), client.t("Metadata is disabled on this server"))
31523152
return
31533153
}
31543154

@@ -3163,7 +3163,13 @@ func metadataHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
31633163
case "sub", "unsub", "subs":
31643164
// these are session-local and function the same whether or not the client is registered
31653165
return metadataSubsHandler(client, subcommand, msg.Params, rb)
3166-
case "get", "set", "list", "clear", "sync":
3166+
case "set", "clear":
3167+
if config.Metadata.OperatorOnlyModification && !client.HasRoleCapabs("metadata") {
3168+
rb.Add(nil, server.name, "FAIL", "METADATA", "FORBIDDEN", utils.SafeErrorParam(msg.Params[0]), client.t("Only server operators can modify metadata"))
3169+
return
3170+
}
3171+
fallthrough
3172+
case "get", "list", "sync":
31673173
if client.registered {
31683174
return metadataRegisteredHandler(client, config, subcommand, msg.Params, rb)
31693175
} else {

traditional.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,8 @@ allow-environment-overrides: true
11211121
metadata:
11221122
# can clients store metadata?
11231123
enabled: true
1124+
# if this is true, only server operators with the `metadata` capability can edit metadata:
1125+
operator-only-modification: false
11241126
# how many keys can a client subscribe to?
11251127
max-subs: 100
11261128
# how many keys can be stored per entity?

0 commit comments

Comments
 (0)