Skip to content
Snippets Groups Projects
Unverified Commit 6f688b29 authored by Ian Chen's avatar Ian Chen Committed by GitHub
Browse files

bugfix: prevent path traversal (#31)

parent 01452c39
No related branches found
No related tags found
No related merge requests found
package webui_service
import (
"path/filepath"
"strings"
"github.com/gin-gonic/gin"
)
......@@ -14,9 +17,19 @@ func ReturnPublic() gin.HandlerFunc {
if destPath[len(destPath)-1] == '/' {
destPath = destPath[:len(destPath)-1]
}
destPath = verifyDestPath(destPath)
context.File(destPath)
} else {
context.Next()
}
}
}
func verifyDestPath(requestedURI string) string {
destPath := filepath.Clean(requestedURI)
// if destPath contains ".." then it is not a valid path
if strings.Contains(destPath, "..") {
return PublicPath
}
return destPath
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment