An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:lock: emoji xss fix (#15041)
syr1ne724cddf7cb07
diff --git a/kernel/api/system.go b/kernel/api/system.goindex 80c4b97487..9550666750 100644--- a/kernel/api/system.go+++ b/kernel/api/system.go@@ -171,9 +171,14 @@ func getEmojiConf(c *gin.Context) {}if !util.IsValidUploadFileName(html.UnescapeString(name)) {+ emojiFullName := customConfDir + "/" + name+ fullPathFilteredName := customConfDir + "/" + util.FilterUploadFileName(name)// XSS through emoji name https://github.com/siyuan-note/siyuan/issues/15034logging.LogWarnf("invalid custom emoji name [%s]", name)- continue+ logging.LogErrorf("renaming invalid file to [%s] in emojis", fullPathFilteredName)+ if removeErr := os.Rename(emojiFullName, fullPathFilteredName); nil != removeErr {+ logging.LogErrorf("renaming invalid file to [%s] failed: %s", fullPathFilteredName, removeErr)+ }}if customEmoji.IsDir() {@@ -195,9 +200,14 @@ func getEmojiConf(c *gin.Context) {}if !util.IsValidUploadFileName(html.UnescapeString(name)) {+ emojiFullName := customConfDir + "/" + name+ fullPathFilteredName := customConfDir + "/" + util.FilterUploadFileName(name)// XSS through emoji name https://github.com/siyuan-note/siyuan/issues/15034logging.LogWarnf("invalid custom emoji name [%s]", name)- continue+ logging.LogErrorf("renaming invalid file to [%s] in emojis", fullPathFilteredName)+ if removeErr := os.Rename(emojiFullName, fullPathFilteredName); nil != removeErr {+ logging.LogErrorf("renaming invalid file to [%s] failed: %s", fullPathFilteredName, removeErr)+ }}addCustomEmoji(customEmoji.Name()+"/"+name, &items)diff --git a/kernel/model/import.go b/kernel/model/import.goindex c53cea4bd8..51af0b4dab 100644--- a/kernel/model/import.go+++ b/kernel/model/import.go@@ -559,11 +559,13 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {// 将包含的自定义表情统一移动到 data/emojis/ 下filelock.Walk(filepath.Join(unzipRootPath, "emojis"), func(path string, d fs.DirEntry, err error) error {if !util.IsValidUploadFileName(d.Name()) {+ emojiFullName := unzipRootPath + "emojis/" + name+ fullPathFilteredName := unzipRootPath + "emojis/" + util.FilterUploadFileName(name)// XSS through emoji name https://github.com/siyuan-note/siyuan/issues/15034- logging.LogErrorf("remove invalid file [%s] in emojis", path)- if removeErr := os.Remove(path); nil != removeErr {- logging.LogErrorf("remove invalid file [%s] failed: %s", path, removeErr)- return nil+ logging.LogWarnf("invalid custom emoji name [%s]", name)+ logging.LogErrorf("renaming invalid file to [%s] in emojis", fullPathFilteredName)+ if removeErr := os.Rename(emojiFullName, fullPathFilteredName); nil != removeErr {+ logging.LogErrorf("renaming invalid file to [%s] failed: %s", fullPathFilteredName, removeErr)}}return nildiff --git a/kernel/util/file.go b/kernel/util/file.goindex 5b792ed647..92fe707650 100644--- a/kernel/util/file.go+++ b/kernel/util/file.go@@ -207,6 +207,7 @@ func FilterUploadFileName(name string) string {ret = strings.ReplaceAll(ret, "#", "")ret = strings.ReplaceAll(ret, "%", "")ret = strings.ReplaceAll(ret, "$", "")+ ret = strings.ReplaceAll(ret, ";", "")ret = TruncateLenFileName(ret)return ret}