Skip to content

Commit e5a634d

Browse files
committed
🔒 XSS through emoji name #15034 #15041
1 parent 724cddf commit e5a634d

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

kernel/api/system.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/88250/lute"
2929
"github.com/88250/lute/html"
3030
"github.com/gin-gonic/gin"
31+
"github.com/siyuan-note/filelock"
3132
"github.com/siyuan-note/logging"
3233
"github.com/siyuan-note/siyuan/kernel/conf"
3334
"github.com/siyuan-note/siyuan/kernel/model"
@@ -171,13 +172,12 @@ func getEmojiConf(c *gin.Context) {
171172
}
172173

173174
if !util.IsValidUploadFileName(html.UnescapeString(name)) {
174-
emojiFullName := customConfDir + "/" + name
175-
fullPathFilteredName := customConfDir + "/" + util.FilterUploadFileName(name)
175+
emojiFullName := filepath.Join(customConfDir, name)
176+
fullPathFilteredName := filepath.Join(customConfDir, util.FilterUploadFileName(name))
176177
// XSS through emoji name https://github.com/siyuan-note/siyuan/issues/15034
177-
logging.LogWarnf("invalid custom emoji name [%s]", name)
178-
logging.LogErrorf("renaming invalid file to [%s] in emojis", fullPathFilteredName)
179-
if removeErr := os.Rename(emojiFullName, fullPathFilteredName); nil != removeErr {
180-
logging.LogErrorf("renaming invalid file to [%s] failed: %s", fullPathFilteredName, removeErr)
178+
logging.LogWarnf("renaming invalid custom emoji file [%s] to [%s]", name, fullPathFilteredName)
179+
if removeErr := filelock.Rename(emojiFullName, fullPathFilteredName); nil != removeErr {
180+
logging.LogErrorf("renaming invalid custom emoji file to [%s] failed: %s", fullPathFilteredName, removeErr)
181181
}
182182
}
183183

@@ -200,13 +200,12 @@ func getEmojiConf(c *gin.Context) {
200200
}
201201

202202
if !util.IsValidUploadFileName(html.UnescapeString(name)) {
203-
emojiFullName := customConfDir + "/" + name
204-
fullPathFilteredName := customConfDir + "/" + util.FilterUploadFileName(name)
203+
emojiFullName := filepath.Join(customConfDir, name)
204+
fullPathFilteredName := filepath.Join(customConfDir, util.FilterUploadFileName(name))
205205
// XSS through emoji name https://github.com/siyuan-note/siyuan/issues/15034
206-
logging.LogWarnf("invalid custom emoji name [%s]", name)
207-
logging.LogErrorf("renaming invalid file to [%s] in emojis", fullPathFilteredName)
208-
if removeErr := os.Rename(emojiFullName, fullPathFilteredName); nil != removeErr {
209-
logging.LogErrorf("renaming invalid file to [%s] failed: %s", fullPathFilteredName, removeErr)
206+
logging.LogWarnf("renaming invalid custom emoji file [%s] to [%s]", name, fullPathFilteredName)
207+
if removeErr := filelock.Rename(emojiFullName, fullPathFilteredName); nil != removeErr {
208+
logging.LogErrorf("renaming invalid custom emoji file to [%s] failed: %s", fullPathFilteredName, removeErr)
210209
}
211210
}
212211

kernel/model/import.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,13 +559,12 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
559559
// 将包含的自定义表情统一移动到 data/emojis/ 下
560560
filelock.Walk(filepath.Join(unzipRootPath, "emojis"), func(path string, d fs.DirEntry, err error) error {
561561
if !util.IsValidUploadFileName(d.Name()) {
562-
emojiFullName := unzipRootPath + "emojis/" + name
563-
fullPathFilteredName := unzipRootPath + "emojis/" + util.FilterUploadFileName(name)
562+
emojiFullName := filepath.Join(unzipRootPath, "emojis", d.Name())
563+
fullPathFilteredName := filepath.Join(unzipRootPath, "emojis", util.FilterUploadFileName(d.Name()))
564564
// XSS through emoji name https://github.com/siyuan-note/siyuan/issues/15034
565-
logging.LogWarnf("invalid custom emoji name [%s]", name)
566-
logging.LogErrorf("renaming invalid file to [%s] in emojis", fullPathFilteredName)
567-
if removeErr := os.Rename(emojiFullName, fullPathFilteredName); nil != removeErr {
568-
logging.LogErrorf("renaming invalid file to [%s] failed: %s", fullPathFilteredName, removeErr)
565+
logging.LogWarnf("renaming invalid custom emoji file [%s] to [%s]", d.Name(), fullPathFilteredName)
566+
if removeErr := filelock.Rename(emojiFullName, fullPathFilteredName); nil != removeErr {
567+
logging.LogErrorf("renaming invalid custom emoji file to [%s] failed: %s", fullPathFilteredName, removeErr)
569568
}
570569
}
571570
return nil

0 commit comments

Comments
 (0)