mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
minor
This commit is contained in:
parent
6167d3ed6b
commit
d88273ab55
|
@ -4,7 +4,6 @@ import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -326,7 +325,7 @@ type prefixedDir struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *prefixedDir) Open(name string) (http.File, error) {
|
func (p *prefixedDir) Open(name string) (http.File, error) {
|
||||||
destPath, filename, ok, err := context.SafeFilename(p.prefix, name)
|
destPath, _, ok, err := context.SafeFilename(p.prefix, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -334,8 +333,8 @@ func (p *prefixedDir) Open(name string) (http.File, error) {
|
||||||
return nil, http.ErrMissingFile // unsafe.
|
return nil, http.ErrMissingFile // unsafe.
|
||||||
}
|
}
|
||||||
|
|
||||||
name = path.Join(destPath, filename)
|
// name = path.Join(destPath, filename)
|
||||||
return p.fs.Open(name)
|
return p.fs.Open(destPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
type partyConfiguratorMiddleware struct {
|
type partyConfiguratorMiddleware struct {
|
||||||
|
|
|
@ -2418,19 +2418,22 @@ func SafeFilename(prefixDir string, name string) (string, string, bool, error) {
|
||||||
return prefixDir, name, false, nil
|
return prefixDir, name, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join the sanitized input with the destination directory.
|
var destPath string
|
||||||
destPath := filepath.Join(prefixDir, filename)
|
if prefixDir != "" {
|
||||||
|
// Join the sanitized input with the destination directory.
|
||||||
|
destPath = filepath.Join(prefixDir, filename)
|
||||||
|
|
||||||
// Get the canonical path of the destination directory.
|
// Get the canonical path of the destination directory.
|
||||||
canonicalDestDir, err := filepath.EvalSymlinks(prefixDir) // the prefix dir should exists.
|
canonicalDestDir, err := filepath.EvalSymlinks(prefixDir) // the prefix dir should exists.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return prefixDir, name, false, fmt.Errorf("dest directory: %s: eval symlinks: %w", prefixDir, err)
|
return prefixDir, name, false, fmt.Errorf("dest directory: %s: eval symlinks: %w", prefixDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the destination path is within the destination directory.
|
// Check if the destination path is within the destination directory.
|
||||||
if !strings.HasPrefix(destPath, canonicalDestDir) {
|
if !strings.HasPrefix(destPath, canonicalDestDir) {
|
||||||
// Reject the input as it is a path traversal attempt.
|
// Reject the input as it is a path traversal attempt.
|
||||||
return prefixDir, name, false, nil
|
return prefixDir, name, false, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return destPath, filename, true, nil
|
return destPath, filename, true, nil
|
||||||
|
|
|
@ -134,7 +134,15 @@ var ResolveHTTPFS = func(fsOrDir interface{}) http.FileSystem {
|
||||||
// FindNames accepts a "http.FileSystem" and a root name and returns
|
// FindNames accepts a "http.FileSystem" and a root name and returns
|
||||||
// the list containing its file names.
|
// the list containing its file names.
|
||||||
func FindNames(fileSystem http.FileSystem, name string) ([]string, error) {
|
func FindNames(fileSystem http.FileSystem, name string) ([]string, error) {
|
||||||
f, err := fileSystem.Open(name)
|
_, filename, ok, err := SafeFilename("", name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("invalid file name: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := fileSystem.Open(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -160,8 +168,8 @@ func FindNames(fileSystem http.FileSystem, name string) ([]string, error) {
|
||||||
// Note:
|
// Note:
|
||||||
// go-bindata has absolute names with os.Separator,
|
// go-bindata has absolute names with os.Separator,
|
||||||
// http.Dir the basename.
|
// http.Dir the basename.
|
||||||
filename := toBaseName(info.Name())
|
baseFilename := toBaseName(info.Name())
|
||||||
fullname := path.Join(name, filename)
|
fullname := path.Join(name, baseFilename)
|
||||||
if fullname == name { // prevent looping through itself.
|
if fullname == name { // prevent looping through itself.
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user