Skip to content

Commit c6541da

Browse files
committed
Bug Fix: Directory Traversal
1 parent 2b36b3d commit c6541da

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

echo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import (
5353
"path/filepath"
5454
"reflect"
5555
"runtime"
56+
"strings"
5657
"sync"
5758
"time"
5859

@@ -487,6 +488,10 @@ func (common) static(prefix, root string, get func(string, HandlerFunc, ...Middl
487488
}
488489

489490
name := filepath.Join(root, path.Clean("/"+p)) // "/"+ for security
491+
// Prevent directory traversal
492+
if !strings.HasPrefix(name+string(filepath.Separator), path.Clean(root)+string(filepath.Separator)) {
493+
return ErrForbidden
494+
}
490495
fi, err := os.Stat(name)
491496
if err != nil {
492497
// The access path does not exist

0 commit comments

Comments
 (0)