fix(api): protect emoji delete api from path traversal exploit

This commit is contained in:
Gabe Kangas 2024-01-20 19:48:52 -08:00
parent 225dc98736
commit 1b14800c7d
No known key found for this signature in database
GPG Key ID: 4345B2060657F330

View File

@ -76,9 +76,13 @@ func DeleteCustomEmoji(w http.ResponseWriter, r *http.Request) {
return
}
// var emojiFileName = filepath.Base(emoji.Name)
targetPath := filepath.Join(config.CustomEmojiPath, emoji.Name)
if !filepath.IsLocal(targetPath) {
controllers.WriteSimpleResponse(w, false, "Emoji path is not valid")
return
}
if err := os.Remove(targetPath); err != nil {
if os.IsNotExist(err) {
controllers.WriteSimpleResponse(w, false, fmt.Sprintf("Emoji %q doesn't exist", emoji.Name))