mirror of
https://github.com/labstack/echo.git
synced 2025-07-15 01:34:53 +02:00
Enabled security while serving static files
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
@ -3,6 +3,7 @@ package middleware
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@ -66,11 +67,11 @@ func StaticWithConfig(config StaticConfig) echo.MiddlewareFunc {
|
||||
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
path := c.Request().URL.Path
|
||||
p := c.Request().URL.Path
|
||||
if strings.HasSuffix(c.Path(), "*") { // When serving from a group, e.g. `/static*`.
|
||||
path = c.Param("*")
|
||||
p = c.Param("*")
|
||||
}
|
||||
name := filepath.Join(config.Root, path)
|
||||
name := filepath.Join(config.Root, path.Clean("/"+p)) // "/"+ for security
|
||||
|
||||
fi, err := os.Stat(name)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user