mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🔒 XSS through emoji name https://github.com/siyuan-note/siyuan/issues/15034 https://github.com/siyuan-note/siyuan/pull/15041
This commit is contained in:
parent
724cddf7cb
commit
e5a634d90c
2 changed files with 16 additions and 18 deletions
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/88250/lute"
|
||||
"github.com/88250/lute/html"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/conf"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
|
|
@ -171,13 +172,12 @@ func getEmojiConf(c *gin.Context) {
|
|||
}
|
||||
|
||||
if !util.IsValidUploadFileName(html.UnescapeString(name)) {
|
||||
emojiFullName := customConfDir + "/" + name
|
||||
fullPathFilteredName := customConfDir + "/" + util.FilterUploadFileName(name)
|
||||
emojiFullName := filepath.Join(customConfDir, name)
|
||||
fullPathFilteredName := filepath.Join(customConfDir, util.FilterUploadFileName(name))
|
||||
// XSS through emoji name https://github.com/siyuan-note/siyuan/issues/15034
|
||||
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)
|
||||
logging.LogWarnf("renaming invalid custom emoji file [%s] to [%s]", name, fullPathFilteredName)
|
||||
if removeErr := filelock.Rename(emojiFullName, fullPathFilteredName); nil != removeErr {
|
||||
logging.LogErrorf("renaming invalid custom emoji file to [%s] failed: %s", fullPathFilteredName, removeErr)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -200,13 +200,12 @@ func getEmojiConf(c *gin.Context) {
|
|||
}
|
||||
|
||||
if !util.IsValidUploadFileName(html.UnescapeString(name)) {
|
||||
emojiFullName := customConfDir + "/" + name
|
||||
fullPathFilteredName := customConfDir + "/" + util.FilterUploadFileName(name)
|
||||
emojiFullName := filepath.Join(customConfDir, name)
|
||||
fullPathFilteredName := filepath.Join(customConfDir, util.FilterUploadFileName(name))
|
||||
// XSS through emoji name https://github.com/siyuan-note/siyuan/issues/15034
|
||||
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)
|
||||
logging.LogWarnf("renaming invalid custom emoji file [%s] to [%s]", name, fullPathFilteredName)
|
||||
if removeErr := filelock.Rename(emojiFullName, fullPathFilteredName); nil != removeErr {
|
||||
logging.LogErrorf("renaming invalid custom emoji file to [%s] failed: %s", fullPathFilteredName, removeErr)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -559,13 +559,12 @@ 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)
|
||||
emojiFullName := filepath.Join(unzipRootPath, "emojis", d.Name())
|
||||
fullPathFilteredName := filepath.Join(unzipRootPath, "emojis", util.FilterUploadFileName(d.Name()))
|
||||
// XSS through emoji name https://github.com/siyuan-note/siyuan/issues/15034
|
||||
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)
|
||||
logging.LogWarnf("renaming invalid custom emoji file [%s] to [%s]", d.Name(), fullPathFilteredName)
|
||||
if removeErr := filelock.Rename(emojiFullName, fullPathFilteredName); nil != removeErr {
|
||||
logging.LogErrorf("renaming invalid custom emoji file to [%s] failed: %s", fullPathFilteredName, removeErr)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue