Fix: sub path join is url encode, can not check prefix

pull/154/head
zijiren233 10 months ago
parent efce1e4a67
commit 16686c470f

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"net/url" "path"
"strings" "strings"
"time" "time"
@ -184,10 +184,7 @@ func NewAlistMovieCacheInitFunc(movie *model.Movie, subPath string) func(ctx con
return nil, err return nil, err
} }
if movie.IsFolder { if movie.IsFolder {
newPath, err := url.JoinPath(truePath, subPath) newPath := path.Join(truePath, subPath)
if err != nil {
return nil, err
}
// check new path is in parent path // check new path is in parent path
if !strings.HasPrefix(newPath, truePath) { if !strings.HasPrefix(newPath, truePath) {
return nil, errors.New("sub path is not in parent path") return nil, errors.New("sub path is not in parent path")

@ -12,6 +12,7 @@ import (
"math/rand" "math/rand"
"net/http" "net/http"
"net/url" "net/url"
"path"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
@ -309,10 +310,7 @@ func listVendorDynamicMovie(ctx context.Context, reqUser *op.User, room *op.Room
if err != nil { if err != nil {
return nil, fmt.Errorf("load alist server id error: %w", err) return nil, fmt.Errorf("load alist server id error: %w", err)
} }
newPath, err := url.JoinPath(truePath, subPath) newPath := path.Join(truePath, subPath)
if err != nil {
return nil, fmt.Errorf("join path error: %w", err)
}
// check new path is in parent path // check new path is in parent path
if !strings.HasPrefix(newPath, truePath) { if !strings.HasPrefix(newPath, truePath) {
return nil, fmt.Errorf("sub path is not in parent path") return nil, fmt.Errorf("sub path is not in parent path")

Loading…
Cancel
Save