Skip to content

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

:lock: Block MCP file tools from accessing encrypted notebook directories #18034

Daniel6348f4cb997d
diff --git a/kernel/mcp/tools/file.go b/kernel/mcp/tools/file.go
index e52aeab95b..e5a6e51e95 100644
--- a/kernel/mcp/tools/file.go
+++ b/kernel/mcp/tools/file.go
@@ -23,8 +23,10 @@ import (
"path/filepath"
"strings"
- "github.com/88250/gulu"
+ "github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/util"
+
+ "github.com/88250/gulu"
)
var FileTool = &Tool{
@@ -89,9 +91,23 @@ func resolvePath(rel string) (string, error) {
if !gulu.File.IsSubPath(util.WorkspaceDir, abs) {
return "", fmt.Errorf("path escapes workspace: %s", rel)
}
+ // 拒绝加密笔记本目录:MCP 文件工具不能读写加密 box 下的文件(防止密文泄漏或明文破坏加密格式)
+ if boxID, encrypted := rejectEncryptedPath(abs); encrypted {
+ return "", fmt.Errorf("path belongs to encrypted notebook [%s]: %s", boxID, rel)
+ }
return abs, nil
}
+// rejectEncryptedPath 检查路径是否属于加密笔记本(含 symlink 绕过)。
+// 返回 boxID 和是否为加密 box。
+func rejectEncryptedPath(absPath string) (boxID string, encrypted bool) {
+ boxID = model.ExtractBoxIDFromAssetsPath(absPath)
+ if boxID != "" && model.IsEncryptedBox(boxID) {
+ return boxID, true
+ }
+ return "", false
+}
+
func fileList(args map[string]interface{}) (CallToolResult, error) {
p, _ := args["path"].(string)
if p == "" {