Skip to content

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

:lock: Filter invisible content from SQL embed blocks, attribute-view keys, and backlinks for publish readers https://github.com/siyuan-note/siyuan/security/advisories/GHSA-2pgf-jv7c-q7rx

Daniel8d90374fd9e8
diff --git a/kernel/model/publish_access.go b/kernel/model/publish_access.go
index 2ef54be51d..3f028b4849 100644
--- a/kernel/model/publish_access.go
+++ b/kernel/model/publish_access.go
@@ -1064,14 +1064,17 @@ func checkAttributeViewItemIDAccessableByPublishAccess(
}
func FilterBlockAttributeViewKeysByPublishAccess(c *gin.Context, publishAccess PublishAccess, blockAttributeViewKeys []*BlockAttributeViewKeys) (ret []*BlockAttributeViewKeys) {
- publishIgnore := GetDisablePublishAccess(publishAccess)
+ publishInvisible := GetInvisiblePublishAccess(publishAccess)
+ publishDisable := GetDisablePublishAccess(publishAccess)
ret = []*BlockAttributeViewKeys{}
for _, blockAttributeViewKey := range blockAttributeViewKeys {
accessable := false
bts := treenode.GetBlockTrees(blockAttributeViewKey.BlockIDs)
for _, bt := range bts {
passwordID, password := GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)
- if (password == "" || CheckPublishAuthCookie(c, passwordID, password)) && CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {
+ if (password == "" || CheckPublishAuthCookie(c, passwordID, password)) &&
+ CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishInvisible) &&
+ CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishDisable) {
accessable = true
break
}
@@ -1090,7 +1093,8 @@ func FilterAttributeViewBacklinksByPublishAccess(c *gin.Context, publishAccess P
return
}
- publishIgnore := GetDisablePublishAccess(publishAccess)
+ publishInvisible := GetInvisiblePublishAccess(publishAccess)
+ publishDisable := GetDisablePublishAccess(publishAccess)
accessibleTargetAvIDs := map[string]bool{}
checkedTargetAvIDs := map[string]bool{}
cachedBlockTrees := map[string]map[string]*treenode.BlockTree{}
@@ -1102,7 +1106,8 @@ func FilterAttributeViewBacklinksByPublishAccess(c *gin.Context, publishAccess P
for _, bt := range treenode.GetBlockTrees(treenode.GetMirrorAttrViewBlockIDs(relation.TargetAvID)) {
passwordID, password := GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)
if ("" == password || CheckPublishAuthCookie(c, passwordID, password)) &&
- CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {
+ CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishInvisible) &&
+ CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishDisable) {
accessibleTargetAvIDs[relation.TargetAvID] = true
break
}
@@ -1148,7 +1153,8 @@ func FilterAttributeViewBacklinksByPublishAccess(c *gin.Context, publishAccess P
}
passwordID, password := GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)
if ("" != password && !CheckPublishAuthCookie(c, passwordID, password)) ||
- !CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {
+ !CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishInvisible) ||
+ !CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishDisable) {
continue
}
}
@@ -1263,7 +1269,8 @@ func FilterContentByPublishAccessWithStatus(c *gin.Context, publishAccess Publis
func FilterEmbedBlocksByPublishAccess(c *gin.Context, publishAccess PublishAccess, embedBlocks []*EmbedBlock) (ret []*EmbedBlock) {
ret = []*EmbedBlock{}
- publishIgnore := GetDisablePublishAccess(publishAccess)
+ publishInvisible := GetInvisiblePublishAccess(publishAccess)
+ publishDisable := GetDisablePublishAccess(publishAccess)
for _, embedBlock := range embedBlocks {
if nil == embedBlock || nil == embedBlock.Block {
continue
@@ -1271,7 +1278,8 @@ func FilterEmbedBlocksByPublishAccess(c *gin.Context, publishAccess PublishAcces
block := embedBlock.Block
passwordID, password := GetPathPasswordByPublishAccess(block.Box, block.Path, publishAccess)
- accessible := CheckPathAccessableByPublishIgnore(block.Box, block.Path, publishIgnore) &&
+ accessible := CheckPathAccessableByPublishIgnore(block.Box, block.Path, publishInvisible) &&
+ CheckPathAccessableByPublishIgnore(block.Box, block.Path, publishDisable) &&
(password == "" || CheckPublishAuthCookie(c, passwordID, password))
if !accessible {
// 不返回不可访问的查询结果,避免泄漏结果数量、顺序和访问控制边界。
diff --git a/kernel/model/publish_access_test.go b/kernel/model/publish_access_test.go
index 484f3c6075..402fe7a0fd 100644
--- a/kernel/model/publish_access_test.go
+++ b/kernel/model/publish_access_test.go
@@ -325,9 +325,9 @@ func TestFilterAttributeViewBacklinksByPublishAccess(t *testing.T) {
expectedTotal: 0,
},
{
- name: "hidden target remains directly accessible",
+ name: "hidden target filtered from backlink relations",
publishAccess: PublishAccess{{ID: targetDocID, Visible: false}},
- expectedTotal: 1,
+ expectedTotal: 0,
},
}
for _, test := range tests {
@@ -340,6 +340,80 @@ func TestFilterAttributeViewBacklinksByPublishAccess(t *testing.T) {
}
}
+func TestFilterBlockAttributeViewKeysByPublishAccess(t *testing.T) {
+ const (
+ boxID = "20260730150000-box0002"
+ publicID = "20260730150001-public2"
+ hiddenID = "20260730150002-hidden2"
+ disabledID = "20260730150003-disable"
+ )
+
+ oldDataDir := util.DataDir
+ oldBlockTreeDBPath := util.BlockTreeDBPath
+ util.DataDir = t.TempDir()
+ util.BlockTreeDBPath = filepath.Join(util.DataDir, "blocktree.db")
+ treenode.InitBlockTree(true)
+ invalidateEncryptedPublishAccessCache()
+ t.Cleanup(func() {
+ treenode.CloseDatabase()
+ util.DataDir = oldDataDir
+ util.BlockTreeDBPath = oldBlockTreeDBPath
+ invalidateEncryptedPublishAccessCache()
+ if "" != oldBlockTreeDBPath {
+ treenode.InitBlockTree(false)
+ }
+ })
+
+ for _, id := range []string{publicID, hiddenID, disabledID} {
+ tree := treenode.NewTree(boxID, "/"+id+".sy", "/"+id, id)
+ treenode.UpsertBlockTree(tree)
+ }
+
+ newKeys := func() []*BlockAttributeViewKeys {
+ return []*BlockAttributeViewKeys{
+ {AvID: "20260730150004-av0002", BlockIDs: []string{publicID}, KeyValues: []*av.KeyValues{{Key: &av.Key{ID: "20260730150005-key0001", Name: "Key 1"}}}},
+ {AvID: "20260730150006-av0003", BlockIDs: []string{hiddenID}, KeyValues: []*av.KeyValues{{Key: &av.Key{ID: "20260730150007-key0002", Name: "Key 2"}}}},
+ {AvID: "20260730150008-av0004", BlockIDs: []string{disabledID}, KeyValues: []*av.KeyValues{{Key: &av.Key{ID: "20260730150009-key0003", Name: "Key 3"}}}},
+ }
+ }
+ c, _ := gin.CreateTestContext(httptest.NewRecorder())
+ c.Request = httptest.NewRequest(http.MethodGet, "/", nil)
+
+ tests := []struct {
+ name string
+ publishAccess PublishAccess
+ expectedAvIDs []string
+ }{
+ {
+ name: "public only",
+ expectedAvIDs: []string{"20260730150004-av0002", "20260730150006-av0003", "20260730150008-av0004"},
+ },
+ {
+ name: "hidden filtered",
+ publishAccess: PublishAccess{{ID: hiddenID, Visible: false}},
+ expectedAvIDs: []string{"20260730150004-av0002", "20260730150008-av0004"},
+ },
+ {
+ name: "disabled filtered",
+ publishAccess: PublishAccess{{ID: disabledID, Visible: true, Disable: true}},
+ expectedAvIDs: []string{"20260730150004-av0002", "20260730150006-av0003"},
+ },
+ }
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ filtered := FilterBlockAttributeViewKeysByPublishAccess(c, test.publishAccess, newKeys())
+ if len(filtered) != len(test.expectedAvIDs) {
+ t.Fatalf("unexpected block attribute view keys: %+v", filtered)
+ }
+ for i, blockAttributeViewKey := range filtered {
+ if blockAttributeViewKey.AvID != test.expectedAvIDs[i] {
+ t.Fatalf("unexpected block attribute view keys: %+v", filtered)
+ }
+ }
+ })
+ }
+}
+
func TestEncryptedNotebookDeniedByPublishAccess(t *testing.T) {
const (
boxID = "20260726000000-encrypt"
@@ -1105,15 +1179,18 @@ func TestFilterEmbedBlocksByPublishAccessRemovesInternalFields(t *testing.T) {
func TestFilterEmbedBlocksByPublishAccessDropsInaccessibleResults(t *testing.T) {
const (
boxID = "20260720000000-boxid01"
+ unlistedDocID = "20260720000001-unliste"
hiddenDocID = "20260720000002-hiddend"
protectedDocID = "20260720000003-protect"
protectedPassword = "password"
)
publishAccess := PublishAccess{
+ {ID: unlistedDocID, Visible: false},
{ID: hiddenDocID, Disable: true},
{ID: protectedDocID, Visible: true, Password: protectedPassword},
}
embedBlocks := []*EmbedBlock{
+ {Block: &Block{ID: "20260720000004-unliste", Box: boxID, Path: "/" + unlistedDocID + ".sy", Content: "unlisted"}},
{Block: &Block{ID: "20260720000004-hidden1", Box: boxID, Path: "/" + hiddenDocID + ".sy", Content: "hidden"}},
{Block: &Block{ID: "20260720000005-protect", Box: boxID, Path: "/" + protectedDocID + ".sy", Content: "protected"}},
}