fix: 创建文件增加非法字符校验 (#4478)

This commit is contained in:
zhengkunwang 2024-04-11 18:32:11 +08:00 committed by GitHub
parent 0de79e537e
commit 2eae8274f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 17 additions and 0 deletions

View file

@ -116,6 +116,9 @@ func (f *FileService) GetFileTree(op request.FileOption) ([]response.FileTree, e
}
func (f *FileService) Create(op request.FileCreate) error {
if files.IsInvalidChar(op.Path) {
return buserr.New("ErrInvalidChar")
}
fo := files.NewFileOp()
if fo.Stat(op.Path) {
return buserr.New(constant.ErrFileIsExit)
@ -243,6 +246,9 @@ func (f *FileService) SaveContent(edit request.FileEdit) error {
}
func (f *FileService) ChangeName(req request.FileRename) error {
if files.IsInvalidChar(req.NewName) {
return buserr.New("ErrInvalidChar")
}
fo := files.NewFileOp()
return fo.Rename(req.OldName, req.NewName)
}

View file

@ -74,6 +74,7 @@ ErrFileDownloadDir: "Download folder not supported"
ErrCmdNotFound: "{{ .name}} command does not exist, please install this command on the host first"
ErrSourcePathNotFound: "Source directory does not exist"
ErrFavoriteExist: "This path has been collected"
ErrInvalidChar: "Illegal characters are prohibited"
#website
ErrDomainIsExist: "Domain is already exist"

View file

@ -23,6 +23,7 @@ ErrTypePortRange: '連接埠範圍需要在 1-65535 之間'
Success: "成功"
Failed: "失敗"
SystemRestart: "系統重啟導致任務中斷"
ErrInvalidChar: "禁止使用非法字元"
#app
ErrPortInUsed: "{{ .detail }} 端口已被佔用!"

View file

@ -74,6 +74,7 @@ ErrFileDownloadDir: "不支持下载文件夹"
ErrCmdNotFound: "{{ .name}} 命令不存在,请先在宿主机安装此命令"
ErrSourcePathNotFound: "源目录不存在"
ErrFavoriteExist: "已收藏此路径"
ErrInvalidChar: "禁止使用非法字符"
#website
ErrDomainIsExist: "域名已存在"

View file

@ -10,6 +10,7 @@ import (
"os/user"
"path/filepath"
"strconv"
"strings"
"sync"
)
@ -141,3 +142,10 @@ func GetParentMode(path string) (os.FileMode, error) {
absPath = parentDir
}
}
func IsInvalidChar(name string) bool {
if strings.Contains(name, "&") {
return true
}
return false
}