fix: relative path judgment (close #3130)
This commit is contained in:
@ -75,7 +75,17 @@ func EncodePath(path string, all ...bool) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func JoinBasePath(basePath, reqPath string) (string, error) {
|
func JoinBasePath(basePath, reqPath string) (string, error) {
|
||||||
if strings.HasSuffix(reqPath, "..") || strings.Contains(reqPath, "../") {
|
/** relative path:
|
||||||
|
* 1. ..
|
||||||
|
* 2. ../
|
||||||
|
* 3. /..
|
||||||
|
* 4. /../
|
||||||
|
* 5. /a/b/..
|
||||||
|
*/
|
||||||
|
if reqPath == ".." ||
|
||||||
|
strings.HasSuffix(reqPath, "/..") ||
|
||||||
|
strings.HasPrefix(reqPath, "../") ||
|
||||||
|
strings.Contains(reqPath, "/../") {
|
||||||
return "", errs.RelativePath
|
return "", errs.RelativePath
|
||||||
}
|
}
|
||||||
return stdpath.Join(FixAndCleanPath(basePath), FixAndCleanPath(reqPath)), nil
|
return stdpath.Join(FixAndCleanPath(basePath), FixAndCleanPath(reqPath)), nil
|
||||||
|
Reference in New Issue
Block a user