Skip to content

Commit 3dab491

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

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

echo.go

Lines changed: 6 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,11 @@ 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+
const sep = string(filepath.Separator)
493+
if !strings.HasPrefix(name+sep, path.Clean(root)+sep) {
494+
return ErrForbidden
495+
}
490496
fi, err := os.Stat(name)
491497
if err != nil {
492498
// The access path does not exist

0 commit comments

Comments
 (0)