Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa
2026-03-14 11:28:11 +08:00
3 changed files with 146 additions and 9 deletions
+96
View File
@@ -741,6 +741,22 @@ func getBlockDOM(c *gin.Context) {
id := arg["id"].(string)
dom := model.GetBlockDOM(id)
if model.IsReadOnlyRoleContext(c) {
publishAccess := model.GetPublishAccess()
publishIgnore := model.GetDisablePublishAccess(publishAccess)
bt := treenode.GetBlockTree(id)
if bt != nil {
passwordID, password := model.GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)
if password != "" && !model.CheckPublishAuthCookie(c, passwordID, password) {
dom = ""
}
if !model.CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {
dom = ""
}
}
}
ret.Data = map[string]string{
"id": id,
"dom": dom,
@@ -763,6 +779,22 @@ func getBlockDOMs(c *gin.Context) {
}
doms := model.GetBlockDOMs(ids)
if model.IsReadOnlyRoleContext(c) {
publishAccess := model.GetPublishAccess()
publishIgnore := model.GetDisablePublishAccess(publishAccess)
bts := treenode.GetBlockTrees(ids)
for id, bt := range bts {
_, ok := doms[id]
if ok {
passwordID, password := model.GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)
if (password != "" && !model.CheckPublishAuthCookie(c, passwordID, password)) || !model.CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {
doms[id] = ""
}
}
}
}
ret.Data = doms
}
@@ -777,6 +809,22 @@ func getBlockDOMWithEmbed(c *gin.Context) {
id := arg["id"].(string)
dom := model.GetBlockDOMWithEmbed(id)
if model.IsReadOnlyRoleContext(c) {
publishAccess := model.GetPublishAccess()
publishIgnore := model.GetDisablePublishAccess(publishAccess)
bt := treenode.GetBlockTree(id)
if bt != nil {
passwordID, password := model.GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)
if password != "" && !model.CheckPublishAuthCookie(c, passwordID, password) {
dom = ""
}
if !model.CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {
dom = ""
}
}
}
ret.Data = map[string]string{
"id": id,
"dom": dom,
@@ -799,6 +847,22 @@ func getBlockDOMsWithEmbed(c *gin.Context) {
}
doms := model.GetBlockDOMsWithEmbed(ids)
if model.IsReadOnlyRoleContext(c) {
publishAccess := model.GetPublishAccess()
publishIgnore := model.GetDisablePublishAccess(publishAccess)
bts := treenode.GetBlockTrees(ids)
for id, bt := range bts {
_, ok := doms[id]
if ok {
passwordID, password := model.GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)
if (password != "" && !model.CheckPublishAuthCookie(c, passwordID, password)) || !model.CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {
doms[id] = ""
}
}
}
}
ret.Data = doms
}
@@ -830,6 +894,22 @@ func getBlockKramdown(c *gin.Context) {
}
kramdown := model.GetBlockKramdown(id, mode)
if model.IsReadOnlyRoleContext(c) {
publishAccess := model.GetPublishAccess()
publishIgnore := model.GetDisablePublishAccess(publishAccess)
bt := treenode.GetBlockTree(id)
if bt != nil {
passwordID, password := model.GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)
if password != "" && !model.CheckPublishAuthCookie(c, passwordID, password) {
kramdown = ""
}
if !model.CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {
kramdown = ""
}
}
}
ret.Data = map[string]string{
"id": id,
"kramdown": kramdown,
@@ -869,6 +949,22 @@ func getBlockKramdowns(c *gin.Context) {
}
kramdowns := model.GetBlockKramdowns(ids, mode)
if model.IsReadOnlyRoleContext(c) {
publishAccess := model.GetPublishAccess()
publishIgnore := model.GetDisablePublishAccess(publishAccess)
bts := treenode.GetBlockTrees(ids)
for id, bt := range bts {
_, ok := kramdowns[id]
if ok {
passwordID, password := model.GetPathPasswordByPublishAccess(bt.BoxID, bt.Path, publishAccess)
if (password != "" && !model.CheckPublishAuthCookie(c, passwordID, password)) || !model.CheckPathAccessableByPublishIgnore(bt.BoxID, bt.Path, publishIgnore) {
kramdowns[id] = ""
}
}
}
}
ret.Data = kramdowns
}
+19
View File
@@ -274,6 +274,25 @@ func refuseToAccess(c *gin.Context, fileAbsPath string, ret *gulu.Result) bool {
c.JSON(http.StatusAccepted, ret)
return true
}
// 禁止访问 data/.siyuan/publishAccess.json
publishAccessPath := normalizeAndResolve(filepath.Join(util.DataDir, ".siyuan", "publishAccess.json"))
if fileNorm == publishAccessPath {
ret.Code = http.StatusForbidden
ret.Msg = http.StatusText(http.StatusForbidden)
c.JSON(http.StatusAccepted, ret)
return true
}
// 禁止访问 无发布访问权限的文件
publishAccess := model.GetPublishAccess()
if !model.CheckAbsPathAccessableByPublishAccess(c, fileAbsPath, publishAccess) {
ret.Code = http.StatusForbidden
ret.Msg = http.StatusText(http.StatusForbidden)
c.JSON(http.StatusAccepted, ret)
return true
}
return false
}
+31 -9
View File
@@ -353,18 +353,28 @@ func IsSensitivePath(p string) bool {
if p == "" {
return false
}
pp := filepath.Clean(strings.ToLower(p))
toCheckPathLower := filepath.Clean(strings.ToLower(p))
toCheckNameLower := filepath.Base(toCheckPathLower)
// 敏感目录前缀(UNIX 风格)
prefixes := []string{
"/etc/ssh",
"/.",
"/etc",
"/root",
"/etc",
"/var/lib/",
"/.",
"/var",
"/proc",
"/sys",
"/run",
"/bin",
"/boot",
"/dev",
"/lib",
"/srv",
"/tmp",
}
for _, pre := range prefixes {
if strings.HasPrefix(pp, pre) {
if strings.HasPrefix(toCheckPathLower, pre) {
return true
}
}
@@ -375,7 +385,7 @@ func IsSensitivePath(p string) bool {
`c:\windows\system`,
}
for _, wp := range winPrefixes {
if strings.HasPrefix(pp, strings.ToLower(wp)) {
if strings.HasPrefix(toCheckPathLower, strings.ToLower(wp)) {
return true
}
}
@@ -386,17 +396,18 @@ func IsSensitivePath(p string) bool {
strings.ToLower(filepath.Join(os.Getenv("ProgramData"), "Microsoft", "Windows", "Start Menu")),
}
for _, sp := range startMenuPrefixes {
if strings.HasPrefix(pp, sp) {
if strings.HasPrefix(toCheckPathLower, sp) {
return true
}
}
// 工作空间/conf 目录(小写比较)
workspaceConfPrefix := strings.ToLower(filepath.Join(WorkspaceDir, "conf"))
if strings.HasPrefix(pp, workspaceConfPrefix) {
if strings.HasPrefix(toCheckPathLower, workspaceConfPrefix) {
return true
}
// 用户家目录下的敏感目录(小写比较)
homePrefixes := []string{
strings.ToLower(filepath.Join(HomeDir, ".ssh")),
strings.ToLower(filepath.Join(HomeDir, ".config")),
@@ -405,7 +416,18 @@ func IsSensitivePath(p string) bool {
strings.ToLower(filepath.Join(HomeDir, ".profile")),
}
for _, hp := range homePrefixes {
if strings.HasPrefix(pp, hp) {
if strings.HasPrefix(toCheckPathLower, hp) {
return true
}
}
// 特定的文件名(小写比较)
namePrefixes := []string{
strings.ToLower("credentials"),
strings.ToLower("id_"),
}
for _, np := range namePrefixes {
if strings.HasPrefix(toCheckNameLower, np) {
return true
}
}