Skip to content

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

:lock: Enforce publish visibility for read-only raw file access https://github.com/siyuan-note/siyuan/security/advisories/GHSA-8ggq-wq3f-vxrw

Danield1007ecfdf3b
diff --git a/kernel/api/asset.go b/kernel/api/asset.go
index 3c942b0783..f4c65a281a 100644
--- a/kernel/api/asset.go
+++ b/kernel/api/asset.go
@@ -388,7 +388,7 @@ func getFileAnnotation(c *gin.Context) {
}
if model.IsReadOnlyRoleContext(c) {
publishAccess := model.GetPublishAccess()
- if !model.CheckAbsPathAccessableByPublishAccess(c, assetAbsPath, publishAccess) {
+ if !model.CheckAbsPathAccessableByPublishAccessForReadOnly(c, assetAbsPath, publishAccess) {
ret.Code = http.StatusForbidden
ret.Msg = http.StatusText(http.StatusForbidden)
return
diff --git a/kernel/api/file.go b/kernel/api/file.go
index 7b42c8e9ad..7690225fa8 100644
--- a/kernel/api/file.go
+++ b/kernel/api/file.go
@@ -529,7 +529,7 @@ func getFile(c *gin.Context) {
if model.IsReadOnlyRoleContext(c) {
publishAccess := model.GetPublishAccess()
- if !model.CheckAbsPathAccessableByPublishAccess(c, fileAbsPath, publishAccess) {
+ if !model.CheckAbsPathAccessableByPublishAccessForReadOnly(c, fileAbsPath, publishAccess) {
ret.Code = http.StatusForbidden
ret.Msg = http.StatusText(http.StatusForbidden)
c.JSON(http.StatusAccepted, ret)
diff --git a/kernel/api/file_test.go b/kernel/api/file_test.go
index 899d0e4869..e024027dac 100644
--- a/kernel/api/file_test.go
+++ b/kernel/api/file_test.go
@@ -134,3 +134,190 @@ func TestGetFileAdminCanFollowAssetsSymlinkOutsideWorkspace(t *testing.T) {
t.Fatalf("unexpected symlink target content: %q", recorder.Body.String())
}
}
+
+// TestGetFileReaderDeniesHiddenNotebookFile 验证 reader 无法通过原始文件 API 读取
+// 显式隐藏(Visible:false)笔记本下的普通文件与 .sy 文档(security advisory GHSA-8ggq-wq3f-vxrw)。
+func TestGetFileReaderDeniesHiddenNotebookFile(t *testing.T) {
+ workspaceDir := t.TempDir()
+ origWorkspaceDir, origDataDir := util.WorkspaceDir, util.DataDir
+ util.WorkspaceDir = workspaceDir
+ util.DataDir = filepath.Join(workspaceDir, "data")
+ t.Cleanup(func() {
+ util.WorkspaceDir, util.DataDir = origWorkspaceDir, origDataDir
+ if err := model.SetPublishAccess(model.PublishAccess{}); err != nil {
+ t.Errorf("reset publish access failed: %v", err)
+ }
+ })
+
+ const boxID = "20260821000000-hidebox"
+ boxDir := filepath.Join(util.DataDir, boxID)
+ if err := os.MkdirAll(boxDir, 0755); err != nil {
+ t.Fatal(err)
+ }
+ canary := []byte("PRIVATE_NOTE_CANARY")
+ names := []string{"private.txt", "20260821000001-hiddoc.sy"}
+ for _, name := range names {
+ if err := os.WriteFile(filepath.Join(boxDir, name), canary, 0644); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if err := model.SetPublishAccess(model.PublishAccess{{ID: boxID, Visible: false}}); err != nil {
+ t.Fatal(err)
+ }
+
+ for _, name := range names {
+ recorder := httptest.NewRecorder()
+ context, _ := gin.CreateTestContext(recorder)
+ context.Set(model.RoleContextKey, model.RoleReader)
+ request := httptest.NewRequest(http.MethodPost, "/api/file/getFile",
+ strings.NewReader(`{"path":"data/`+boxID+`/`+name+`"}`))
+ request.Header.Set("Content-Type", "application/json")
+ context.Request = request
+ getFile(context)
+
+ if recorder.Code == http.StatusOK {
+ t.Fatalf("reader must not read file [%s] under hidden notebook, got status %d: %s",
+ name, recorder.Code, recorder.Body.String())
+ }
+ if strings.Contains(recorder.Body.String(), string(canary)) {
+ t.Fatalf("hidden notebook file [%s] leaked to reader: %s", name, recorder.Body.String())
+ }
+ }
+}
+
+// TestGetFileReaderCanReadVisibleNotebookFile 验证 reader 仍可读取可见笔记本下的文件,
+// 防止 Visible 校验误伤正常发布访问。
+func TestGetFileReaderCanReadVisibleNotebookFile(t *testing.T) {
+ workspaceDir := t.TempDir()
+ origWorkspaceDir, origDataDir := util.WorkspaceDir, util.DataDir
+ util.WorkspaceDir = workspaceDir
+ util.DataDir = filepath.Join(workspaceDir, "data")
+ t.Cleanup(func() {
+ util.WorkspaceDir, util.DataDir = origWorkspaceDir, origDataDir
+ if err := model.SetPublishAccess(model.PublishAccess{}); err != nil {
+ t.Errorf("reset publish access failed: %v", err)
+ }
+ })
+
+ const boxID = "20260821000002-showbox"
+ boxDir := filepath.Join(util.DataDir, boxID)
+ if err := os.MkdirAll(boxDir, 0755); err != nil {
+ t.Fatal(err)
+ }
+ content := []byte("public note content")
+ if err := os.WriteFile(filepath.Join(boxDir, "public.txt"), content, 0644); err != nil {
+ t.Fatal(err)
+ }
+ if err := model.SetPublishAccess(model.PublishAccess{{ID: boxID, Visible: true}}); err != nil {
+ t.Fatal(err)
+ }
+
+ recorder := httptest.NewRecorder()
+ context, _ := gin.CreateTestContext(recorder)
+ context.Set(model.RoleContextKey, model.RoleReader)
+ request := httptest.NewRequest(http.MethodPost, "/api/file/getFile",
+ strings.NewReader(`{"path":"data/`+boxID+`/public.txt"}`))
+ request.Header.Set("Content-Type", "application/json")
+ context.Request = request
+ getFile(context)
+
+ if recorder.Code != http.StatusOK {
+ t.Fatalf("reader should read file under visible notebook, got status %d: %s",
+ recorder.Code, recorder.Body.String())
+ }
+ if recorder.Body.String() != string(content) {
+ t.Fatalf("unexpected file content: %q", recorder.Body.String())
+ }
+}
+
+// TestGetFileEditorCanReadHiddenNotebookFile 验证编辑者不受发布可见性限制,
+// 仍可通过原始文件 API 读取隐藏笔记本下的普通文件。
+func TestGetFileEditorCanReadHiddenNotebookFile(t *testing.T) {
+ workspaceDir := t.TempDir()
+ origWorkspaceDir, origDataDir := util.WorkspaceDir, util.DataDir
+ util.WorkspaceDir = workspaceDir
+ util.DataDir = filepath.Join(workspaceDir, "data")
+ t.Cleanup(func() {
+ util.WorkspaceDir, util.DataDir = origWorkspaceDir, origDataDir
+ if err := model.SetPublishAccess(model.PublishAccess{}); err != nil {
+ t.Errorf("reset publish access failed: %v", err)
+ }
+ })
+
+ const boxID = "20260821000003-editbox"
+ boxDir := filepath.Join(util.DataDir, boxID)
+ if err := os.MkdirAll(boxDir, 0755); err != nil {
+ t.Fatal(err)
+ }
+ content := []byte("editor accessible content")
+ if err := os.WriteFile(filepath.Join(boxDir, "private.txt"), content, 0644); err != nil {
+ t.Fatal(err)
+ }
+ if err := model.SetPublishAccess(model.PublishAccess{{ID: boxID, Visible: false}}); err != nil {
+ t.Fatal(err)
+ }
+
+ recorder := httptest.NewRecorder()
+ context, _ := gin.CreateTestContext(recorder)
+ context.Set(model.RoleContextKey, model.RoleEditor)
+ request := httptest.NewRequest(http.MethodPost, "/api/file/getFile",
+ strings.NewReader(`{"path":"data/`+boxID+`/private.txt"}`))
+ request.Header.Set("Content-Type", "application/json")
+ context.Request = request
+ getFile(context)
+
+ if recorder.Code != http.StatusOK {
+ t.Fatalf("editor should read file under hidden notebook, got status %d: %s",
+ recorder.Code, recorder.Body.String())
+ }
+ if recorder.Body.String() != string(content) {
+ t.Fatalf("unexpected file content: %q", recorder.Body.String())
+ }
+}
+
+// TestGetFileDeniesNotebookSiyuanConf 验证非管理员无法通过原始文件 API 读取笔记本
+// .siyuan 目录下的内部文件(与发布可见性无关,黑名单独立拦截)。
+func TestGetFileDeniesNotebookSiyuanConf(t *testing.T) {
+ workspaceDir := t.TempDir()
+ origWorkspaceDir, origDataDir := util.WorkspaceDir, util.DataDir
+ util.WorkspaceDir = workspaceDir
+ util.DataDir = filepath.Join(workspaceDir, "data")
+ t.Cleanup(func() {
+ util.WorkspaceDir, util.DataDir = origWorkspaceDir, origDataDir
+ if err := model.SetPublishAccess(model.PublishAccess{}); err != nil {
+ t.Errorf("reset publish access failed: %v", err)
+ }
+ })
+
+ const boxID = "20260821000004-confbox"
+ confDir := filepath.Join(util.DataDir, boxID, ".siyuan")
+ if err := os.MkdirAll(confDir, 0755); err != nil {
+ t.Fatal(err)
+ }
+ canary := []byte(`{"name":"private notebook"}`)
+ if err := os.WriteFile(filepath.Join(confDir, "conf.json"), canary, 0644); err != nil {
+ t.Fatal(err)
+ }
+ if err := model.SetPublishAccess(model.PublishAccess{{ID: boxID, Visible: true}}); err != nil {
+ t.Fatal(err)
+ }
+
+ for _, role := range []model.Role{model.RoleEditor, model.RoleReader} {
+ recorder := httptest.NewRecorder()
+ context, _ := gin.CreateTestContext(recorder)
+ context.Set(model.RoleContextKey, role)
+ request := httptest.NewRequest(http.MethodPost, "/api/file/getFile",
+ strings.NewReader(`{"path":"data/`+boxID+`/.siyuan/conf.json"}`))
+ request.Header.Set("Content-Type", "application/json")
+ context.Request = request
+ getFile(context)
+
+ if recorder.Code == http.StatusOK {
+ t.Fatalf("role [%d] must not read notebook .siyuan/conf.json, got status %d: %s",
+ role, recorder.Code, recorder.Body.String())
+ }
+ if strings.Contains(recorder.Body.String(), string(canary)) {
+ t.Fatalf("notebook conf leaked to role [%d]: %s", role, recorder.Body.String())
+ }
+ }
+}
diff --git a/kernel/model/publish_access.go b/kernel/model/publish_access.go
index 3f028b4849..81f8e9314a 100644
--- a/kernel/model/publish_access.go
+++ b/kernel/model/publish_access.go
@@ -491,6 +491,29 @@ func assetPathFromDataRelativePath(relPath string) (assetPath, boxID string, ok
}
func CheckAbsPathAccessableByPublishAccess(c *gin.Context, absPath string, publishAccess PublishAccess) bool {
+ return checkAbsPathAccessableByPublishAccess(c, absPath, publishAccess, false)
+}
+
+// CheckAbsPathAccessableByPublishAccessForReadOnly 在只读角色(读者、访客)场景下检查绝对路径的
+// 发布访问权限:在禁用与密码之外,还要求所属笔记本未被显式隐藏(Visible:false)。
+// 用于原始文件通道(getFile 等),只读角色不通过其他内容 API 获取这些路径,
+// 显式隐藏的笔记本应被视为机密边界(security advisory GHSA-8ggq-wq3f-vxrw)。
+func CheckAbsPathAccessableByPublishAccessForReadOnly(c *gin.Context, absPath string, publishAccess PublishAccess) bool {
+ return checkAbsPathAccessableByPublishAccess(c, absPath, publishAccess, true)
+}
+
+// CheckNotebookVisibleByPublishAccess 判断笔记本在发布访问配置中是否被显式隐藏:
+// 未配置的笔记本默认可见,与 isNotebookVisibleByPublishAccess(kernel/api/notebook.go)保持一致。
+func CheckNotebookVisibleByPublishAccess(boxID string, publishAccess PublishAccess) bool {
+ for _, item := range publishAccess {
+ if item.ID == boxID {
+ return item.Visible
+ }
+ }
+ return true
+}
+
+func checkAbsPathAccessableByPublishAccess(c *gin.Context, absPath string, publishAccess PublishAccess, enforceNotebookVisible bool) bool {
absPath = filepath.Clean(absPath)
if gulu.File.IsSubPath(util.HistoryDir, absPath) {
@@ -516,6 +539,9 @@ func CheckAbsPathAccessableByPublishAccess(c *gin.Context, absPath string, publi
if ast.IsNodeIDPattern(pathParts[0]) {
box := pathParts[0]
+ if enforceNotebookVisible && !CheckNotebookVisibleByPublishAccess(box, publishAccess) {
+ return false
+ }
blockPath := "/" + strings.Join(pathParts[1:], "/")
passwordID, password := GetPathPasswordByPublishAccess(box, blockPath, publishAccess)
publishIgnore := GetDisablePublishAccess(publishAccess)
diff --git a/kernel/model/publish_access_test.go b/kernel/model/publish_access_test.go
index 402fe7a0fd..bc0d701877 100644
--- a/kernel/model/publish_access_test.go
+++ b/kernel/model/publish_access_test.go
@@ -1473,3 +1473,65 @@ func TestFilterAssetContentByPublishAccess(t *testing.T) {
t.Fatalf("unexpected authenticated asset contents: %+v", filtered)
}
}
+
+// TestCheckAbsPathAccessableByPublishAccessForReadOnly 验证只读角色的原始文件通道
+// 会将显式隐藏(Visible:false)的笔记本视为机密边界(security advisory GHSA-8ggq-wq3f-vxrw),
+// 而基础校验保持原有的未列出但可直接访问语义不变。
+func TestCheckAbsPathAccessableByPublishAccessForReadOnly(t *testing.T) {
+ const (
+ boxID = "20260821000005-visboxa"
+ docID = "20260821000006-visdoca"
+ password = "password"
+ )
+ oldDataDir := util.DataDir
+ util.DataDir = t.TempDir()
+ invalidateEncryptedPublishAccessCache()
+ t.Cleanup(func() {
+ util.DataDir = oldDataDir
+ invalidateEncryptedPublishAccessCache()
+ })
+
+ c, _ := gin.CreateTestContext(httptest.NewRecorder())
+ c.Request = httptest.NewRequest(http.MethodGet, "/", nil)
+ fileAbs := filepath.Join(util.DataDir, boxID, "private.txt")
+ docAbs := filepath.Join(util.DataDir, boxID, docID+".sy")
+
+ // 基础校验:显式隐藏的笔记本仍保持可直接访问语义(与文档内容 API 一致)
+ if !CheckAbsPathAccessableByPublishAccess(c, fileAbs, PublishAccess{{ID: boxID, Visible: false}}) {
+ t.Fatal("base check should keep hidden notebook directly accessible")
+ }
+
+ // 只读校验:显式隐藏的笔记本应被拒绝,普通文件与 .sy 文档均如此
+ if CheckAbsPathAccessableByPublishAccessForReadOnly(c, fileAbs, PublishAccess{{ID: boxID, Visible: false}}) {
+ t.Fatal("read-only check should deny file under hidden notebook")
+ }
+ if CheckAbsPathAccessableByPublishAccessForReadOnly(c, docAbs, PublishAccess{{ID: boxID, Visible: false}}) {
+ t.Fatal("read-only check should deny doc under hidden notebook")
+ }
+
+ // 可见、未配置、禁用与密码保护场景应保持原有判定
+ if !CheckAbsPathAccessableByPublishAccessForReadOnly(c, fileAbs, PublishAccess{{ID: boxID, Visible: true}}) {
+ t.Fatal("read-only check should allow file under visible notebook")
+ }
+ if !CheckAbsPathAccessableByPublishAccessForReadOnly(c, fileAbs, PublishAccess{}) {
+ t.Fatal("read-only check should allow file under unconfigured notebook")
+ }
+ if CheckAbsPathAccessableByPublishAccessForReadOnly(c, fileAbs, PublishAccess{{ID: boxID, Visible: true, Disable: true}}) {
+ t.Fatal("read-only check should deny disabled notebook")
+ }
+ if CheckAbsPathAccessableByPublishAccessForReadOnly(c, fileAbs, PublishAccess{{ID: boxID, Visible: true, Password: password}}) {
+ t.Fatal("read-only check should deny password protected notebook without auth cookie")
+ }
+ c.Request.AddCookie(&http.Cookie{
+ Name: "publish-auth-" + boxID,
+ Value: util.SHA256Hash([]byte(boxID + password)),
+ })
+ if !CheckAbsPathAccessableByPublishAccessForReadOnly(c, fileAbs, PublishAccess{{ID: boxID, Visible: true, Password: password}}) {
+ t.Fatal("read-only check should allow password protected notebook after authorization")
+ }
+
+ // 隐藏且带密码的笔记本应被隐藏判定直接拒绝,即使已通过密码授权
+ if CheckAbsPathAccessableByPublishAccessForReadOnly(c, fileAbs, PublishAccess{{ID: boxID, Visible: false, Password: password}}) {
+ t.Fatal("read-only check should deny hidden notebook even after password authorization")
+ }
+}
diff --git a/kernel/server/serve.go b/kernel/server/serve.go
index f4da39b900..123e90761a 100644
--- a/kernel/server/serve.go
+++ b/kernel/server/serve.go
@@ -975,7 +975,13 @@ func serveAssets(ginServer *gin.Engine) {
if !model.IsAdminRoleContext(context) {
publishAccess := model.GetPublishAccess()
- if !model.CheckAbsPathAccessableByPublishAccess(context, p, publishAccess) {
+ var accessible bool
+ if model.IsReadOnlyRoleContext(context) {
+ accessible = model.CheckAbsPathAccessableByPublishAccessForReadOnly(context, p, publishAccess)
+ } else {
+ accessible = model.CheckAbsPathAccessableByPublishAccess(context, p, publishAccess)
+ }
+ if !accessible {
context.Status(http.StatusForbidden)
return
}
diff --git a/kernel/util/path_guard.go b/kernel/util/path_guard.go
index f79aec9384..260ed1f687 100644
--- a/kernel/util/path_guard.go
+++ b/kernel/util/path_guard.go
@@ -21,12 +21,14 @@ import (
"path/filepath"
"runtime"
"strings"
+
+ "github.com/88250/lute/ast"
)
// 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 以及 temp 目录下的 siyuan.log 日志文件。
+// data/.siyuan/publishAccess.json、笔记本目录下的 .siyuan 内部文件以及 temp 目录下的 siyuan.log 日志文件。
func IsForbiddenAbsPath(abs string) bool {
fileNorm := NormalizeAndResolve(abs)
@@ -62,9 +64,10 @@ func IsForbiddenAbsPath(abs string) bool {
}
// IsForbiddenDataRelPath 判断数据目录下的相对路径是否指向敏感位置(data/snippets/conf.json、
-// data/templates 目录以及 data/.siyuan/publishAccess.json)。历史快照与仓库 diff 检出中的文件副本
-// 位于其他绝对路径下,无法用 IsForbiddenAbsPath 的精确匹配拦截,因此 /history 与 /repo/diff 路由
-// (kernel/server/serve.go)在去掉快照目录前缀后按数据相对路径调用本函数进行片段匹配。
+// data/templates 目录、data/.siyuan/publishAccess.json 以及笔记本目录下的 .siyuan 内部文件
+// 如 conf.json、sort.json、历史快照和 notebook-crypto-backup.json)。历史快照与仓库 diff 检出
+// 中的文件副本位于其他绝对路径下,无法用 IsForbiddenAbsPath 的精确匹配拦截,因此 /history
+// 与 /repo/diff 路由(kernel/server/serve.go)在去掉快照目录前缀后按数据相对路径调用本函数进行片段匹配。
func IsForbiddenDataRelPath(rel string) bool {
// 统一为斜杠并清理(path.Clean 使用斜杠语义,避免 Windows 上分隔符差异)
rel = path.Clean("/" + filepath.ToSlash(rel))
@@ -89,6 +92,14 @@ func IsForbiddenDataRelPath(rel string) bool {
if rel == "/.siyuan/publishAccess.json" || strings.ToLower(rel) == "/.siyuan/publishaccess.json" {
return true
}
+
+ // 禁止访问笔记本目录下的 .siyuan 内部文件(含目录本身):conf.json、sort.json、
+ // 历史快照与 notebook-crypto-backup.json 等均为内部数据,不应通过原始文件通道暴露。
+ // 笔记本 ID 目录名以时间戳开头,据此限定匹配范围避免误伤用户文档
+ pathParts := strings.Split(rel, "/")
+ if 3 <= len(pathParts) && ast.IsNodeIDPattern(pathParts[1]) && ".siyuan" == pathParts[2] {
+ return true
+ }
return false
}
diff --git a/kernel/util/path_guard_test.go b/kernel/util/path_guard_test.go
index ae56912729..828079fad6 100644
--- a/kernel/util/path_guard_test.go
+++ b/kernel/util/path_guard_test.go
@@ -26,7 +26,8 @@ import (
// TestIsForbiddenAbsPath 覆盖 HTTP 文件 API 与 MCP 文件工具共用的敏感路径黑名单:
// conf 目录下的 conf.json 与 TLS 密钥材料、data/snippets/conf.json、data/templates 目录、
-// data/.siyuan/publishAccess.json 以及 temp 目录下的 siyuan.log 日志文件。
+// data/.siyuan/publishAccess.json、笔记本目录下的 .siyuan 内部文件以及 temp 目录下的
+// siyuan.log 日志文件。
func TestIsForbiddenAbsPath(t *testing.T) {
tmpWorkspace := t.TempDir()
origWorkspace, origConf, origData, origTemp, origLog := WorkspaceDir, ConfDir, DataDir, TempDir, LogPath
@@ -52,6 +53,8 @@ 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")},
+ {"notebook conf", filepath.Join("data", "20210808180117-6v0mkxr", ".siyuan", "conf.json")},
+ {"notebook sort", filepath.Join("data", "20210808180117-6v0mkxr", ".siyuan", "sort.json")},
{"log", filepath.Join("temp", "siyuan.log")},
}
for _, c := range cases {
@@ -66,6 +69,8 @@ func TestIsForbiddenAbsPath(t *testing.T) {
filepath.Join(tmpWorkspace, "data", "assets", "image.png"),
filepath.Join(tmpWorkspace, "data", "snippets", "custom.css"),
filepath.Join(tmpWorkspace, "data", "plugins", "example", "main.js"),
+ filepath.Join(tmpWorkspace, "data", "20210808180117-6v0mkxr", "20240101.sy"),
+ filepath.Join(tmpWorkspace, "data", "20210808180117-6v0mkxr", "conf.json"),
filepath.Join(tmpWorkspace, "temp", "siyuan", "kernel.log"),
}
for _, p := range allowed {
@@ -100,6 +105,7 @@ func TestIsForbiddenAbsPathCaseInsensitive(t *testing.T) {
filepath.Join(tmpWorkspace, "CONF", strings.ToUpper(TLSKeyFilename)),
filepath.Join(tmpWorkspace, "DATA", "SNIPPETS", "CONF.JSON"),
filepath.Join(tmpWorkspace, "DATA", ".SIYUAN", "PUBLISHACCESS.JSON"),
+ strings.ToUpper(filepath.Join(tmpWorkspace, "data", "20210808180117-6v0mkxr", ".siyuan", "conf.json")),
strings.ToUpper(filepath.Join(tmpWorkspace, "data", "templates")),
strings.ToUpper(filepath.Join(tmpWorkspace, "temp", "siyuan.log")),
}
@@ -169,7 +175,8 @@ func TestIsForbiddenAbsPathSymlinkBypass(t *testing.T) {
// TestIsForbiddenDataRelPath 覆盖 /history 与 /repo/diff 路由共用的数据相对路径片段匹配黑名单。
// 历史快照副本位于 HistoryDir 等绝对路径下,无法用 IsForbiddenAbsPath 精确匹配,因此按数据目录下的
-// 相对位置拦截:data/snippets/conf.json、data/templates 目录以及 data/.siyuan/publishAccess.json。
+// 相对位置拦截:data/snippets/conf.json、data/templates 目录、data/.siyuan/publishAccess.json
+// 以及笔记本目录下的 .siyuan 内部文件。
func TestIsForbiddenDataRelPath(t *testing.T) {
forbidden := []string{
".siyuan/publishAccess.json",
@@ -182,6 +189,11 @@ func TestIsForbiddenDataRelPath(t *testing.T) {
filepath.Join("templates", "a.md"),
"snippets/conf.json",
filepath.Join("snippets", "conf.json"),
+ filepath.Join("20210808180117-6v0mkxr", ".siyuan", "conf.json"),
+ filepath.Join("20210808180117-6v0mkxr", ".siyuan", "sort.json"),
+ filepath.Join("20210808180117-6v0mkxr", ".siyuan"),
+ filepath.Join("20210808180117-6v0mkxr", ".siyuan", "history", "2021-01-01-120000-x.sy"),
+ filepath.Join("20210808180117-6v0mkxr", ".siyuan", "publishAccess.json"),
}
for _, p := range forbidden {
if got := IsForbiddenDataRelPath(p); !got {
@@ -196,9 +208,9 @@ func TestIsForbiddenDataRelPath(t *testing.T) {
"assets/image.png",
filepath.Join("20210808180117-6v0mkxr", "templates", "a.sy"),
filepath.Join("20210808180117-6v0mkxr", "20240101.sy"),
+ filepath.Join("20210808180117-6v0mkxr", "conf.json"),
"plugins/example/main.js",
".siyuan/publishAccess.json.bak",
- filepath.Join("20210808180117-6v0mkxr", ".siyuan", "publishAccess.json"),
}
for _, p := range allowed {
if got := IsForbiddenDataRelPath(p); got {
@@ -217,6 +229,7 @@ func TestIsForbiddenDataRelPathCaseInsensitive(t *testing.T) {
filepath.Join(".SIYUAN", "PUBLISHACCESS.JSON"),
strings.ToUpper(filepath.Join("templates", "A.MD")),
filepath.Join("SNIPPETS", "CONF.JSON"),
+ filepath.Join("20210808180117-6v0mkxr", ".SIYUAN", "CONF.JSON"),
}
for _, p := range cases {
if got := IsForbiddenDataRelPath(p); !got {