mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-07-03 14:09:06 +02:00
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user