Skip to content

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

:lock: Restrict database field visibility metadata to editors https://github.com/siyuan-note/siyuan/security/advisories/GHSA-57v5-wqx3-cgj4

Daniel64c26e74bb82
diff --git a/kernel/api/av_authorization_test.go b/kernel/api/av_authorization_test.go
new file mode 100644
index 0000000000..5e20b8816d
--- /dev/null
+++ b/kernel/api/av_authorization_test.go
@@ -0,0 +1,68 @@
+// SiYuan - Refactor your thinking
+// Copyright (c) 2020-present, b3log.org
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+package api
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+
+ "github.com/gin-gonic/gin"
+ "github.com/siyuan-note/siyuan/kernel/model"
+)
+
+func TestGetAttributeViewFieldViewsRejectsReader(t *testing.T) {
+ gin.SetMode(gin.TestMode)
+
+ previousConf := model.Conf
+ model.Conf = &model.AppConf{Lang: "en"}
+ t.Cleanup(func() {
+ model.Conf = previousConf
+ })
+
+ engine := gin.New()
+ engine.Use(func(c *gin.Context) {
+ c.Set(model.RoleContextKey, model.RoleReader)
+ c.Next()
+ })
+ ServeAPI(engine)
+
+ recorder := httptest.NewRecorder()
+ request := httptest.NewRequest(
+ http.MethodPost,
+ "/api/av/getAttributeViewFieldViews",
+ strings.NewReader(`{"avID":"20260726000000-abcdefg","keyID":"20260726000001-abcdefg"}`),
+ )
+ request.Header.Set("Content-Type", "application/json")
+ engine.ServeHTTP(recorder, request)
+
+ response := &struct {
+ Code int `json:"code"`
+ Data map[string]any `json:"data"`
+ }{}
+ if err := json.Unmarshal(recorder.Body.Bytes(), response); err != nil {
+ t.Fatalf("unmarshal response failed: %v", err)
+ }
+ if response.Code != -1 {
+ t.Fatalf("reader request returned code %d: %s", response.Code, recorder.Body.String())
+ }
+ if response.Data["closeTimeout"] != float64(5000) {
+ t.Fatalf("reader request reached the handler: %s", recorder.Body.String())
+ }
+}
diff --git a/kernel/api/router.go b/kernel/api/router.go
index 115bb4ee4f..713f72d0f1 100644
--- a/kernel/api/router.go
+++ b/kernel/api/router.go
@@ -527,7 +527,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/av/renderHistoryAttributeView", model.CheckAuth, model.CheckAdminRole, renderHistoryAttributeView)
ginServer.Handle("POST", "/api/av/renderSnapshotAttributeView", model.CheckAuth, model.CheckAdminRole, renderSnapshotAttributeView)
ginServer.Handle("POST", "/api/av/getAttributeViewKeys", model.CheckAuth, getAttributeViewKeys)
- ginServer.Handle("POST", "/api/av/getAttributeViewFieldViews", model.CheckAuth, getAttributeViewFieldViews)
+ ginServer.Handle("POST", "/api/av/getAttributeViewFieldViews", model.CheckAuth, model.CheckReadonly, getAttributeViewFieldViews)
ginServer.Handle("POST", "/api/av/getAttributeViewBacklinks", model.CheckAuth, getAttributeViewBacklinks)
ginServer.Handle("POST", "/api/av/setAttributeViewBlockAttr", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setAttributeViewBlockAttr)
ginServer.Handle("POST", "/api/av/batchSetAttributeViewBlockAttrs", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, batchSetAttributeViewBlockAttrs)