Skip to content

Commit

Permalink
Bug Fix: Directory Traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
little-cui committed Dec 13, 2020
1 parent 2b36b3d commit c6541da
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
"path/filepath"
"reflect"
"runtime"
"strings"
"sync"
"time"

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

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

0 comments on commit c6541da

Please # to comment.