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: Prevent API token leakage via slow-search timing logs and block siyuan.log reads https://github.com/siyuan-note/siyuan/security/advisories/GHSA-3wvc-5754-gp67
Danielcf9972ff17a4
diff --git a/kernel/model/session.go b/kernel/model/session.goindex cb683ef796..ac63d1f313 100644--- a/kernel/model/session.go+++ b/kernel/model/session.go@@ -481,7 +481,7 @@ func Timing(c *gin.Context) {c.Next()elapsed := int(time.Now().UnixMilli() - now)if timing < elapsed {- logging.LogWarnf("[%s] elapsed [%dms]", c.Request.RequestURI, elapsed)+ logging.LogWarnf("[%s] elapsed [%dms]", p, elapsed)util.PushMsg(Conf.Language(tip), 7000)}}diff --git a/kernel/util/path_guard.go b/kernel/util/path_guard.goindex 1c0d009231..1945ac91cb 100644--- a/kernel/util/path_guard.go+++ b/kernel/util/path_guard.go@@ -25,11 +25,17 @@ import (// IsForbiddenAbsPath 判断绝对路径是否为敏感路径,HTTP 文件 API(kernel/api/file.go 的 refuseToAccess)// 与 MCP 文件工具(kernel/mcp/tools/file.go 的 resolvePath)共用同一黑名单:-// conf 目录下的 conf.json 与 TLS 密钥材料、data/snippets/conf.json、data/templates 目录以及-// data/.siyuan/publishAccess.json。+// conf 目录下的 conf.json 与 TLS 密钥材料、data/snippets/conf.json、data/templates 目录、+// data/.siyuan/publishAccess.json 以及 temp 目录下的 siyuan.log 日志文件。func IsForbiddenAbsPath(abs string) bool {fileNorm := NormalizeAndResolve(abs)+ // 禁止访问日志文件 siyuan.log:Timing 中间件可能把含 API token 的查询串写入日志(如慢查询告警),+ // 日志被任意已认证用户读取即等于泄露管理员凭据,因此即使日志不再记录查询串也保持拦截+ if "" != LogPath && fileNorm == NormalizeAndResolve(LogPath) {+ return true+ }+// 禁止访问 conf 目录下的敏感文件:conf.json(含 accessAuthCode/api.token/cookieKey 等明文凭据)// 以及 TLS 私钥与证书(见 GetOrCreateTLSCert,私钥被读取可导致 HTTPS 流量被解密或证书被伪造)forbiddenConfFiles := []string{diff --git a/kernel/util/path_guard_test.go b/kernel/util/path_guard_test.goindex e45d9d2078..de00b31dfa 100644--- a/kernel/util/path_guard_test.go+++ b/kernel/util/path_guard_test.go@@ -25,15 +25,19 @@ import ()// TestIsForbiddenAbsPath 覆盖 HTTP 文件 API 与 MCP 文件工具共用的敏感路径黑名单:-// conf 目录下的 conf.json 与 TLS 密钥材料、data/snippets/conf.json、data/templates 目录以及-// data/.siyuan/publishAccess.json。+// conf 目录下的 conf.json 与 TLS 密钥材料、data/snippets/conf.json、data/templates 目录、+// data/.siyuan/publishAccess.json 以及 temp 目录下的 siyuan.log 日志文件。func TestIsForbiddenAbsPath(t *testing.T) {tmpWorkspace := t.TempDir()- origWorkspace, origConf, origData := WorkspaceDir, ConfDir, DataDir+ origWorkspace, origConf, origData, origTemp, origLog := WorkspaceDir, ConfDir, DataDir, TempDir, LogPathWorkspaceDir = tmpWorkspaceConfDir = filepath.Join(tmpWorkspace, "conf")DataDir = filepath.Join(tmpWorkspace, "data")- t.Cleanup(func() { WorkspaceDir, ConfDir, DataDir = origWorkspace, origConf, origData })+ TempDir = filepath.Join(tmpWorkspace, "temp")+ LogPath = filepath.Join(TempDir, "siyuan.log")+ t.Cleanup(func() {+ WorkspaceDir, ConfDir, DataDir, TempDir, LogPath = origWorkspace, origConf, origData, origTemp, origLog+ })cases := []struct {name string@@ -48,6 +52,7 @@ func TestIsForbiddenAbsPath(t *testing.T) {{"templates dir", filepath.Join("data", "templates")},{"templates file", filepath.Join("data", "templates", "a.txt")},{"publish access", filepath.Join("data", ".siyuan", "publishAccess.json")},+ {"log", filepath.Join("temp", "siyuan.log")},}for _, c := range cases {abs := filepath.Join(tmpWorkspace, c.rel)@@ -76,11 +81,15 @@ func TestIsForbiddenAbsPathCaseInsensitive(t *testing.T) {t.Skip("case-insensitive comparison only on windows/darwin")}tmpWorkspace := t.TempDir()- origWorkspace, origConf, origData := WorkspaceDir, ConfDir, DataDir+ origWorkspace, origConf, origData, origTemp, origLog := WorkspaceDir, ConfDir, DataDir, TempDir, LogPathWorkspaceDir = tmpWorkspaceConfDir = filepath.Join(tmpWorkspace, "conf")DataDir = filepath.Join(tmpWorkspace, "data")- t.Cleanup(func() { WorkspaceDir, ConfDir, DataDir = origWorkspace, origConf, origData })+ TempDir = filepath.Join(tmpWorkspace, "temp")+ LogPath = filepath.Join(TempDir, "siyuan.log")+ t.Cleanup(func() {+ WorkspaceDir, ConfDir, DataDir, TempDir, LogPath = origWorkspace, origConf, origData, origTemp, origLog+ })// 模拟 MCP 工具输入的大小写变体路径(Windows 上 CONF.JSON 与 conf.json 指向同一文件)。cases := []string{@@ -92,6 +101,7 @@ func TestIsForbiddenAbsPathCaseInsensitive(t *testing.T) {filepath.Join(tmpWorkspace, "DATA", "SNIPPETS", "CONF.JSON"),filepath.Join(tmpWorkspace, "DATA", ".SIYUAN", "PUBLISHACCESS.JSON"),strings.ToUpper(filepath.Join(tmpWorkspace, "data", "templates")),+ strings.ToUpper(filepath.Join(tmpWorkspace, "temp", "siyuan.log")),}for _, p := range cases {if got := IsForbiddenAbsPath(p); !got {