From 4b871b50c67b0b81aee4b22d4ae954766247b13a Mon Sep 17 00:00:00 2001 From: odyseusz <4pt5r3kf2@mozmail.com> Date: Sun, 6 Oct 2024 16:24:46 +0200 Subject: [PATCH] Add file-size limit --- pages/users.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pages/users.go b/pages/users.go index d6be56e..48adc97 100644 --- a/pages/users.go +++ b/pages/users.go @@ -75,7 +75,7 @@ func userData(username, usersonline, ops string) UserInfo { } crdstr := strings.TrimSuffix(string(crd), "\n") filename := "/home/" + username + "/meta-info.toml" - _, error := os.Stat(filename) + filestat, error := os.Stat(filename) if error != nil { if os.IsNotExist(error) { UserError("user doesn't have a meta-info.toml", username, error) @@ -95,6 +95,23 @@ func userData(username, usersonline, ops string) UserInfo { return user } } + // Check file size of meta-info.toml. If it's over 100 kB, bail + if filestat.Size() > 100_000 { + log.Error("user's meta-info.toml is above the 100 kB file size limit", "user", username) + user := UserInfo{ + Name: username, + Online: false, + Op: false, + } + user.Created, _ = strconv.Atoi(crdstr) + if isonline { + user.Online = true + } + if isop { + user.Op = true + } + return user + } viper.SetConfigFile(filename) if err := viper.ReadInConfig(); err != nil { log.Error("message", "couldn't read a users meta-info.toml file.", "error", log.Any("err", err), "user", username)