Browse Source

Fixed path cleaning algorithm

tobychui 7 months ago
parent
commit
785fb467b3
2 changed files with 4 additions and 2 deletions
  1. 1 1
      main.go
  2. 3 1
      mod/webserv/filemanager/filemanager.go

+ 1 - 1
main.go

@@ -117,7 +117,7 @@ func SetupCloseHandler() {
 
 func ShutdownSeq() {
 	SystemWideLogger.Println("Shutting down " + name)
-	//SystemWideLogger.Println("Closing GeoDB ")
+	//SystemWideLogger.Println("Closing GeoDB")
 	//geodbStore.Close()
 	SystemWideLogger.Println("Closing Netstats Listener")
 	netstatBuffers.Close()

+ 3 - 1
mod/webserv/filemanager/filemanager.go

@@ -44,7 +44,9 @@ func (fm *FileManager) HandleList(w http.ResponseWriter, r *http.Request) {
 
 	// Clean path to prevent path escape #274
 	targetDir = filepath.ToSlash(filepath.Clean(targetDir))
-	targetDir = strings.ReplaceAll(targetDir, "../", "")
+	for strings.Contains(targetDir, "../") {
+		targetDir = strings.ReplaceAll(targetDir, "../", "")
+	}
 
 	// Open the target directory
 	dirEntries, err := os.ReadDir(targetDir)