mirror of
https://github.com/gogs/gogs.git
synced 2026-01-12 10:22:25 +01:00
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
17 lines
405 B
Go
17 lines
405 B
Go
package pathutil
|
|
|
|
import (
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
// Clean cleans up given path and returns a relative path that goes straight
|
|
// down to prevent path traversal.
|
|
//
|
|
// 🚨 SECURITY: This function MUST be used for any user input that is used as
|
|
// file system path to prevent path traversal.
|
|
func Clean(p string) string {
|
|
p = strings.ReplaceAll(p, `\`, "/")
|
|
return strings.Trim(path.Clean("/"+p), "/")
|
|
}
|