Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Validate document API identifiers

Danielce679aa5cd2a
diff --git a/kernel/api/block.go b/kernel/api/block.go
index 983bab5117..bdafc1b9a6 100644
--- a/kernel/api/block.go
+++ b/kernel/api/block.go
@@ -748,7 +748,13 @@ func getBlockInfo(c *gin.Context) {
return
}
- id := arg["id"].(string)
+ var id string
+ if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("id", &id, true, true)) {
+ return
+ }
+ if util.InvalidIDPattern(id, ret) {
+ return
+ }
if !checkBlockPublishAccess(c, id, ret) {
return
}
diff --git a/kernel/api/filetree.go b/kernel/api/filetree.go
index 499d71f91c..7011f27627 100644
--- a/kernel/api/filetree.go
+++ b/kernel/api/filetree.go
@@ -434,7 +434,10 @@ func getPathByID(c *gin.Context) {
return
}
- id := arg["id"].(string)
+ var id string
+ if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("id", &id, true, true)) {
+ return
+ }
if util.InvalidIDPattern(id, ret) {
return
}
@@ -628,12 +631,15 @@ func removeDocByID(c *gin.Context) {
return
}
- id := arg["id"].(string)
+ var id string
+ if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("id", &id, true, true)) {
+ return
+ }
if util.InvalidIDPattern(id, ret) {
return
}
- tree, err := model.LoadTreeByBlockID(id)
+ p, notebook, err := model.GetPathByID(id)
if err != nil {
ret.Code = -1
ret.Msg = err.Error()
@@ -641,7 +647,7 @@ func removeDocByID(c *gin.Context) {
return
}
- if err = model.RemoveDoc(tree.Box, tree.Path); err != nil {
+ if err = model.RemoveDoc(notebook, p); err != nil {
ret.Code = -1
ret.Msg = err.Error()
}
@@ -1197,6 +1203,9 @@ func getDoc(c *gin.Context) {
if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("id", &id, true, true)) {
return
}
+ if util.InvalidIDPattern(id, ret) {
+ return
+ }
idx := arg["index"]
index := 0
if nil != idx {