Daniel
2026-06-03 12:18:33 +08:00
parent 8564a03a11
commit 0bc765c54a
3 changed files with 9 additions and 26 deletions
-13
View File
@@ -551,22 +551,9 @@ func GetAssetAbsPath(relativePath string) (string, error) {
return absPath, nil
}
// supports URL-encoded local file names
unescaped, secondErr := url.PathUnescape(relativePath)
if secondErr == nil && unescaped != relativePath {
absPathUnescaped, secondErr := getAssetAbsPath(unescaped)
if secondErr == nil && absPathUnescaped != "" {
return absPathUnescaped, nil
}
}
// 优先返回原始路径错误,其次返回反转义路径错误
if err != nil {
return "", err
}
if secondErr != nil {
return "", secondErr
}
return "", fmt.Errorf(Conf.Language(12), relativePath)
}
+1 -1
View File
@@ -285,7 +285,7 @@ func CheckAbsPathAccessableByPublishAccess(c *gin.Context, absPath string, publi
return false
}
}
return true
return false
}
func FilterViewByPublishAccess(c *gin.Context, publishAccess PublishAccess, viewable av.Viewable) (ret av.Viewable) {
+8 -12
View File
@@ -641,18 +641,8 @@ func serveAssets(ginServer *gin.Engine) {
relativePath := path.Join("assets", requestPath)
p, err := model.GetAssetAbsPath(relativePath)
if err != nil {
if strings.Contains(strings.TrimPrefix(requestPath, "/"), "/") {
// 再使用编码过的路径解析一次 https://github.com/siyuan-note/siyuan/issues/11823
dest := url.PathEscape(strings.TrimPrefix(requestPath, "/"))
dest = strings.ReplaceAll(dest, ":", "%3A")
relativePath = path.Join("assets", dest)
p, err = model.GetAssetAbsPath(relativePath)
}
if err != nil {
context.Status(http.StatusNotFound)
return
}
context.Status(http.StatusNotFound)
return
}
if !model.IsAdminRoleContext(context) {
@@ -663,6 +653,12 @@ func serveAssets(ginServer *gin.Engine) {
}
}
if util.IsSensitivePath(p) {
logging.LogErrorf("refuse to serve sensitive file [%s]", context.Request.URL.Path)
context.Status(http.StatusForbidden)
return
}
if serveThumbnail(context, p, requestPath) || serveSVG(context, p) {
return
}