mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 06:40:54 +03:00
improve validations for user provided file and directory paths
This commit is contained in:
@@ -47,7 +47,7 @@ func GetLogger() *zerolog.Logger {
|
||||
// InitLogger configures the logger using the given parameters
|
||||
func InitLogger(logFilePath string, logMaxSize int, logMaxBackups int, logMaxAge int, logCompress bool, level zerolog.Level) {
|
||||
zerolog.TimeFieldFormat = dateFormat
|
||||
if len(logFilePath) > 0 && filepath.Clean(logFilePath) != "." {
|
||||
if isLogFilePathValid(logFilePath) {
|
||||
logger = zerolog.New(&lumberjack.Logger{
|
||||
Filename: logFilePath,
|
||||
MaxSize: logMaxSize,
|
||||
@@ -183,3 +183,11 @@ func ConnectionFailedLog(user, ip, loginType, errorString string) {
|
||||
Str("error", errorString).
|
||||
Msg("")
|
||||
}
|
||||
|
||||
func isLogFilePathValid(logFilePath string) bool {
|
||||
cleanInput := filepath.Clean(logFilePath)
|
||||
if cleanInput == "." || cleanInput == ".." {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user