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: Block SQL search in read-only mode https://github.com/siyuan-note/siyuan/security/advisories/GHSA-4qwm-3p58-vh67
Danielf3db2d764406
diff --git a/kernel/api/search.go b/kernel/api/search.goindex c16e2f254d..ca7a7aad66 100644--- a/kernel/api/search.go+++ b/kernel/api/search.go@@ -554,6 +554,14 @@ func fullTextSearchBlock(c *gin.Context) {return}+ // SQL mode is blocked in read-only mode, consistent with /api/query/sql+ if method == 2 && util.ReadOnly {+ ret.Code = -1+ ret.Msg = model.Conf.Language(34)+ ret.Data = map[string]any{"closeTimeout": 5000}+ return+ }+notebook, _ := arg["notebook"].(string)if isEncryptedNotebookDeniedForPublish(c, notebook) {ret.Data = map[string]any{diff --git a/kernel/api/search_readonly_test.go b/kernel/api/search_readonly_test.gonew file mode 100644index 0000000000..251f5618e3--- /dev/null+++ b/kernel/api/search_readonly_test.go@@ -0,0 +1,62 @@+// SiYuan - From thought to insight, with agents+// 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"+ "github.com/siyuan-note/siyuan/kernel/util"+)++// SQL 搜索模式在只读模式下必须被拦截,与 /api/query/sql 保持一致+// https://github.com/siyuan-note/siyuan/security/advisories/GHSA-4qwm-3p58-vh67+func TestFullTextSearchBlockSQLModeReadonly(t *testing.T) {+ gin.SetMode(gin.TestMode)++ previousReadOnly := util.ReadOnly+ previousConf := model.Conf+ util.ReadOnly = true+ model.Conf = &model.AppConf{Lang: "en"}+ defer func() {+ util.ReadOnly = previousReadOnly+ model.Conf = previousConf+ }()++ recorder := httptest.NewRecorder()+ c, _ := gin.CreateTestContext(recorder)+ payload := `{"query":"SELECT * FROM blocks LIMIT 1","method":2,"types":{},"subTypes":{},"paths":[],"groupBy":0,"orderBy":0,"page":1,"pageSize":1}`+ c.Request = httptest.NewRequest(http.MethodPost, "/api/search/fullTextSearchBlock", strings.NewReader(payload))+ c.Request.Header.Set("Content-Type", "application/json")+ c.Set(model.RoleContextKey, model.RoleAdministrator)+ fullTextSearchBlock(c)++ response := &struct {+ Code int `json:"code"`+ }{}+ if err := json.Unmarshal(recorder.Body.Bytes(), response); err != nil {+ t.Fatalf("unmarshal response failed: %v", err)+ }+ if response.Code != -1 {+ t.Fatalf("SQL search in readonly mode returned code %d: %s", response.Code, recorder.Body.String())+ }+}