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: Improve the security of publish service (#17210)
Yuxin Zhaoa6c54a4787b0
diff --git a/kernel/api/block.go b/kernel/api/block.goindex 5b30e06782..8f9d3f4030 100644--- a/kernel/api/block.go+++ b/kernel/api/block.go@@ -741,6 +741,22 @@ func getBlockDOM(c *gin.Context) {id := arg["id"].(string)dom := model.GetBlockDOM(id)++ if model.IsReadOnlyRoleContext(c) {+ publishAccess := model.GetPublishAccess()+ publishIgnore := model.GetDisablePublishAccess(publishAccess)+ bt := treenode.GetBlockTree(id)+ if bt != nil {+ passwordID, password := model.GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)+ if password != "" && !model.CheckPublishAuthCookie(c, passwordID, password) {+ dom = ""+ }+ if !model.CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {+ dom = ""+ }+ }+ }+ret.Data = map[string]string{"id": id,"dom": dom,@@ -763,6 +779,22 @@ func getBlockDOMs(c *gin.Context) {}doms := model.GetBlockDOMs(ids)++ if model.IsReadOnlyRoleContext(c) {+ publishAccess := model.GetPublishAccess()+ publishIgnore := model.GetDisablePublishAccess(publishAccess)+ bts := treenode.GetBlockTrees(ids)+ for id, bt := range bts {+ _, ok := doms[id]+ if ok {+ passwordID, password := model.GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)+ if (password != "" && !model.CheckPublishAuthCookie(c, passwordID, password)) || !model.CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {+ doms[id] = ""+ }+ }+ }+ }+ret.Data = doms}@@ -777,6 +809,22 @@ func getBlockDOMWithEmbed(c *gin.Context) {id := arg["id"].(string)dom := model.GetBlockDOMWithEmbed(id)++ if model.IsReadOnlyRoleContext(c) {+ publishAccess := model.GetPublishAccess()+ publishIgnore := model.GetDisablePublishAccess(publishAccess)+ bt := treenode.GetBlockTree(id)+ if bt != nil {+ passwordID, password := model.GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)+ if password != "" && !model.CheckPublishAuthCookie(c, passwordID, password) {+ dom = ""+ }+ if !model.CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {+ dom = ""+ }+ }+ }+ret.Data = map[string]string{"id": id,"dom": dom,@@ -799,6 +847,22 @@ func getBlockDOMsWithEmbed(c *gin.Context) {}doms := model.GetBlockDOMsWithEmbed(ids)++ if model.IsReadOnlyRoleContext(c) {+ publishAccess := model.GetPublishAccess()+ publishIgnore := model.GetDisablePublishAccess(publishAccess)+ bts := treenode.GetBlockTrees(ids)+ for id, bt := range bts {+ _, ok := doms[id]+ if ok {+ passwordID, password := model.GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)+ if (password != "" && !model.CheckPublishAuthCookie(c, passwordID, password)) || !model.CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {+ doms[id] = ""+ }+ }+ }+ }+ret.Data = doms}@@ -830,6 +894,22 @@ func getBlockKramdown(c *gin.Context) {}kramdown := model.GetBlockKramdown(id, mode)++ if model.IsReadOnlyRoleContext(c) {+ publishAccess := model.GetPublishAccess()+ publishIgnore := model.GetDisablePublishAccess(publishAccess)+ bt := treenode.GetBlockTree(id)+ if bt != nil {+ passwordID, password := model.GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)+ if password != "" && !model.CheckPublishAuthCookie(c, passwordID, password) {+ kramdown = ""+ }+ if !model.CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {+ kramdown = ""+ }+ }+ }+ret.Data = map[string]string{"id": id,"kramdown": kramdown,@@ -869,6 +949,22 @@ func getBlockKramdowns(c *gin.Context) {}kramdowns := model.GetBlockKramdowns(ids, mode)++ if model.IsReadOnlyRoleContext(c) {+ publishAccess := model.GetPublishAccess()+ publishIgnore := model.GetDisablePublishAccess(publishAccess)+ bts := treenode.GetBlockTrees(ids)+ for id, bt := range bts {+ _, ok := kramdowns[id]+ if ok {+ passwordID, password := model.GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)+ if (password != "" && !model.CheckPublishAuthCookie(c, passwordID, password)) || !model.CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {+ kramdowns[id] = ""+ }+ }+ }+ }+ret.Data = kramdowns}diff --git a/kernel/api/file.go b/kernel/api/file.goindex 444bf010e1..a54233411e 100644--- a/kernel/api/file.go+++ b/kernel/api/file.go@@ -274,6 +274,25 @@ func refuseToAccess(c *gin.Context, fileAbsPath string, ret *gulu.Result) bool {c.JSON(http.StatusAccepted, ret)return true}++ // 禁止访问 data/.siyuan/publishAccess.json+ publishAccessPath := normalizeAndResolve(filepath.Join(util.DataDir, ".siyuan", "publishAccess.json"))+ if fileNorm == publishAccessPath {+ ret.Code = http.StatusForbidden+ ret.Msg = http.StatusText(http.StatusForbidden)+ c.JSON(http.StatusAccepted, ret)+ return true+ }++ // 禁止访问 无发布访问权限的文件+ publishAccess := model.GetPublishAccess()+ if !model.CheckAbsPathAccessableByPublishAccess(c, fileAbsPath, publishAccess) {+ ret.Code = http.StatusForbidden+ ret.Msg = http.StatusText(http.StatusForbidden)+ c.JSON(http.StatusAccepted, ret)+ return true+ }+return false}