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: Restrict sensitive asset APIs to administrators https://github.com/siyuan-note/siyuan/security/advisories/GHSA-jv8v-xq2h-657v
Danieleee3410aa131
diff --git a/kernel/api/asset_authorization_test.go b/kernel/api/asset_authorization_test.gonew file mode 100644index 0000000000..5991a94e27--- /dev/null+++ b/kernel/api/asset_authorization_test.go@@ -0,0 +1,59 @@+// 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 (+ "net/http"+ "net/http/httptest"+ "strings"+ "testing"++ "github.com/gin-gonic/gin"+ "github.com/siyuan-note/siyuan/kernel/model"+)++func TestAssetAdminEndpointsRejectReader(t *testing.T) {+ gin.SetMode(gin.TestMode)++ engine := gin.New()+ engine.Use(func(c *gin.Context) {+ c.Set(model.RoleContextKey, model.RoleReader)+ c.Next()+ })+ ServeAPI(engine)++ tests := []struct {+ path string+ body string+ }{+ {path: "/api/asset/resolveAssetPath", body: `{"path":"assets/test.png"}`},+ {path: "/api/asset/getUnusedAssets", body: `{}`},+ {path: "/api/asset/getMissingAssets", body: `{}`},+ }+ for _, test := range tests {+ t.Run(test.path, func(t *testing.T) {+ recorder := httptest.NewRecorder()+ request := httptest.NewRequest(http.MethodPost, test.path, strings.NewReader(test.body))+ request.Header.Set("Content-Type", "application/json")+ engine.ServeHTTP(recorder, request)++ if recorder.Code != http.StatusForbidden {+ t.Fatalf("reader request returned status %d: %s", recorder.Code, recorder.Body.String())+ }+ })+ }+}diff --git a/kernel/api/router.go b/kernel/api/router.goindex 804d2d29be..add6edf46c 100644--- a/kernel/api/router.go+++ b/kernel/api/router.go@@ -342,12 +342,12 @@ func ServeAPI(ginServer *gin.Engine) {ginServer.Handle("POST", "/api/asset/uploadCloudByAssetsPaths", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, uploadCloudByAssetsPaths)ginServer.Handle("POST", "/api/asset/insertLocalAssets", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, insertLocalAssets)ginServer.Handle("POST", "/api/asset/insertCover", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, insertCover)- ginServer.Handle("POST", "/api/asset/resolveAssetPath", model.CheckAuth, resolveAssetPath)+ ginServer.Handle("POST", "/api/asset/resolveAssetPath", model.CheckAuth, model.CheckAdminRole, resolveAssetPath)ginServer.Handle("POST", "/api/asset/upload", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, model.Upload)ginServer.Handle("POST", "/api/asset/setFileAnnotation", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setFileAnnotation)ginServer.Handle("POST", "/api/asset/getFileAnnotation", model.CheckAuth, getFileAnnotation)- ginServer.Handle("POST", "/api/asset/getUnusedAssets", model.CheckAuth, getUnusedAssets)- ginServer.Handle("POST", "/api/asset/getMissingAssets", model.CheckAuth, getMissingAssets)+ ginServer.Handle("POST", "/api/asset/getUnusedAssets", model.CheckAuth, model.CheckAdminRole, getUnusedAssets)+ ginServer.Handle("POST", "/api/asset/getMissingAssets", model.CheckAuth, model.CheckAdminRole, getMissingAssets)ginServer.Handle("POST", "/api/asset/removeUnusedAsset", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, removeUnusedAsset)ginServer.Handle("POST", "/api/asset/removeUnusedAssets", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, removeUnusedAssets)ginServer.Handle("POST", "/api/asset/getDocImageAssets", model.CheckAuth, getDocImageAssets)