Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Dec 11, 2024
2 parents a3cc2b8 + fc47230 commit b0b88d3
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions kernel/api/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ func renderTemplate(c *gin.Context) {
return
}

if !util.IsAbsPathInWorkspace(p) {
ret.Code = -1
ret.Msg = "Path [" + p + "] is not in workspace"
return
}

preview := false
if previewArg := arg["preview"]; nil != previewArg {
preview = previewArg.(bool)
Expand Down
8 changes: 7 additions & 1 deletion kernel/model/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,13 @@ func ExportResources(resourcePaths []string, mainName string) (exportFilePath st

// 将需要导出的文件/文件夹复制到临时文件夹
for _, resourcePath := range resourcePaths {
resourceFullPath := filepath.Join(util.WorkspaceDir, resourcePath) // 资源完整路径
resourceFullPath := filepath.Join(util.WorkspaceDir, resourcePath) // 资源完整路径
if !util.IsAbsPathInWorkspace(resourceFullPath) {
logging.LogErrorf("resource path [%s] is not in workspace", resourceFullPath)
err = errors.New("resource path [" + resourcePath + "] is not in workspace")
return
}

resourceBaseName := filepath.Base(resourceFullPath) // 资源名称
resourceCopyPath := filepath.Join(exportFolderPath, resourceBaseName) // 资源副本完整路径
if err = filelock.Copy(resourceFullPath, resourceCopyPath); err != nil {
Expand Down
1 change: 1 addition & 0 deletions kernel/model/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@ func FullTextSearchBlock(query string, boxes, paths []string, types map[string]b
boxFilter := buildBoxesFilter(boxes)
pathFilter := buildPathsFilter(paths)
if 2 > len(strings.Split(strings.TrimSpace(query), " ")) {
query = stringQuery(query)
blocks, matchedBlockCount, matchedRootCount = fullTextSearchByQuerySyntax(query, boxFilter, pathFilter, typeFilter, ignoreFilter, orderByClause, beforeLen, page, pageSize)
} else {
docMode = true // 文档全文搜索模式 https://github.com/siyuan-note/siyuan/issues/10584
Expand Down
5 changes: 5 additions & 0 deletions kernel/model/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ func Upload(c *gin.Context) {
if nil != form.Value["assetsDirPath"] {
relAssetsDirPath = form.Value["assetsDirPath"][0]
assetsDirPath = filepath.Join(util.DataDir, relAssetsDirPath)
if !util.IsAbsPathInWorkspace(assetsDirPath) {
ret.Code = -1
ret.Msg = "Path [" + assetsDirPath + "] is not in workspace"
return
}
}
if !gulu.File.IsExist(assetsDirPath) {
if err = os.MkdirAll(assetsDirPath, 0755); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions kernel/treenode/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ import (

func BuiltInTemplateFuncs() (ret template.FuncMap) {
ret = sprig.TxtFuncMap()

// 因为安全原因移除一些函数 https://github.com/siyuan-note/siyuan/issues/13426
delete(ret, "env")
delete(ret, "expandenv")
delete(ret, "getHostByName")

ret["Weekday"] = util.Weekday
ret["WeekdayCN"] = util.WeekdayCN
ret["WeekdayCN2"] = util.WeekdayCN2
Expand Down
4 changes: 4 additions & 0 deletions kernel/util/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,7 @@ func GetAbsPathInWorkspace(relPath string) (string, error) {
}
return "", os.ErrPermission
}

func IsAbsPathInWorkspace(absPath string) bool {
return IsSubPath(WorkspaceDir, absPath)
}

0 comments on commit b0b88d3

Please sign in to comment.