Skip to content

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

:lock: Enforce publish access for tag labels https://github.com/siyuan-note/siyuan/security/advisories/GHSA-mp7r-57w4-5qm3

Daniel4515fa257cfa
diff --git a/kernel/api/tag.go b/kernel/api/tag.go
index 3cfbb16115..e24c6652ea 100644
--- a/kernel/api/tag.go
+++ b/kernel/api/tag.go
@@ -55,8 +55,7 @@ func getTag(c *gin.Context) {
if model.IsReadOnlyRoleContext(c) {
publishAccess := model.GetPublishAccess()
- publishIgnore := model.GetInvisiblePublishAccess(publishAccess)
- tags = model.FilterTagsByPublishIgnore(publishIgnore, tags)
+ tags = model.FilterTagsByPublishAccess(c, publishAccess, tags)
}
ret.Data = tags
}
diff --git a/kernel/model/publish_access.go b/kernel/model/publish_access.go
index 85ce13b423..bfbb64ab46 100644
--- a/kernel/model/publish_access.go
+++ b/kernel/model/publish_access.go
@@ -1390,14 +1390,25 @@ func FilterGraphByPublishAccess(c *gin.Context, publishAccess PublishAccess, nod
return
}
-func FilterTagsByPublishIgnore(publishIgnore PublishAccess, tags *Tags) (ret *Tags) {
- spans := sql.QueryTagSpans("")
+func FilterTagsByPublishAccess(c *gin.Context, publishAccess PublishAccess, tags *Tags) (ret *Tags) {
+ return filterTagsByPublishAccess(c, publishAccess, tags, sql.QueryTagSpans(""))
+}
+
+func filterTagsByPublishAccess(c *gin.Context, publishAccess PublishAccess, tags *Tags, spans []*sql.Span) (ret *Tags) {
+ publishInvisible := GetInvisiblePublishAccess(publishAccess)
+ publishDisable := GetDisablePublishAccess(publishAccess)
labelCounts := make(map[string]int)
for _, span := range spans {
- if CheckPathAccessableByPublishIgnore(span.Box, span.Path, publishIgnore) {
- label := util.UnescapeHTML(span.Content)
- labelCounts[label] += 1
+ if !CheckPathAccessableByPublishIgnore(span.Box, span.Path, publishInvisible) ||
+ !CheckPathAccessableByPublishIgnore(span.Box, span.Path, publishDisable) {
+ continue
+ }
+ passwordID, password := GetPathPasswordByPublishAccess(span.Box, span.Path, publishAccess)
+ if password != "" && !CheckPublishAuthCookie(c, passwordID, password) {
+ continue
}
+ label := util.UnescapeHTML(span.Content)
+ labelCounts[label] += 1
}
ret = &Tags{}
diff --git a/kernel/model/publish_access_test.go b/kernel/model/publish_access_test.go
index 2f96d8980c..2cda88eacd 100644
--- a/kernel/model/publish_access_test.go
+++ b/kernel/model/publish_access_test.go
@@ -23,6 +23,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/siyuan-note/siyuan/kernel/av"
+ "github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
)
@@ -652,6 +653,55 @@ func TestFilterGraphByPublishAccess(t *testing.T) {
}
}
+func TestFilterTagsByPublishAccess(t *testing.T) {
+ const (
+ boxID = "20260726000000-boxid01"
+ publicDocID = "20260726000001-public1"
+ protectedDocID = "20260726000002-protect"
+ hiddenDocID = "20260726000003-hidden1"
+ disabledDocID = "20260726000004-disable"
+ protectedPassword = "password"
+ )
+ publishAccess := PublishAccess{
+ {ID: protectedDocID, Visible: true, Password: protectedPassword},
+ {ID: hiddenDocID, Visible: false},
+ {ID: disabledDocID, Visible: true, Disable: true},
+ }
+ spans := []*sql.Span{
+ {Box: boxID, Path: "/" + publicDocID + ".sy", Content: "shared"},
+ {Box: boxID, Path: "/" + protectedDocID + ".sy", Content: "shared"},
+ {Box: boxID, Path: "/" + protectedDocID + ".sy", Content: "protected"},
+ {Box: boxID, Path: "/" + hiddenDocID + ".sy", Content: "hidden"},
+ {Box: boxID, Path: "/" + disabledDocID + ".sy", Content: "disabled"},
+ }
+ newTags := func() *Tags {
+ return &Tags{
+ {Name: "shared", Label: "shared", Type: "tag", Count: 2},
+ {Name: "protected", Label: "protected", Type: "tag", Count: 1},
+ {Name: "hidden", Label: "hidden", Type: "tag", Count: 1},
+ {Name: "disabled", Label: "disabled", Type: "tag", Count: 1},
+ }
+ }
+
+ c, _ := gin.CreateTestContext(httptest.NewRecorder())
+ c.Request = httptest.NewRequest(http.MethodGet, "/", nil)
+ filtered := filterTagsByPublishAccess(c, publishAccess, newTags(), spans)
+ if len(*filtered) != 1 || (*filtered)[0].Label != "shared" || (*filtered)[0].Count != 1 {
+ t.Fatalf("unexpected unauthenticated tags: %+v", *filtered)
+ }
+
+ c.Request.AddCookie(&http.Cookie{
+ Name: "publish-auth-" + protectedDocID,
+ Value: util.SHA256Hash([]byte(protectedDocID + protectedPassword)),
+ })
+ filtered = filterTagsByPublishAccess(c, publishAccess, newTags(), spans)
+ if len(*filtered) != 2 ||
+ (*filtered)[0].Label != "shared" || (*filtered)[0].Count != 2 ||
+ (*filtered)[1].Label != "protected" || (*filtered)[1].Count != 1 {
+ t.Fatalf("unexpected authenticated tags: %+v", *filtered)
+ }
+}
+
func TestFilterEmbedBlocksByPublishAccessRemovesInternalFields(t *testing.T) {
c, _ := gin.CreateTestContext(httptest.NewRecorder())
c.Request = httptest.NewRequest(http.MethodGet, "/", nil)