]> git.proxmox.com Git - proxmox-backup.git/commitdiff
santtize paths in handle_request
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 12 Nov 2018 12:19:53 +0000 (13:19 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 12 Nov 2018 12:19:53 +0000 (13:19 +0100)
src/main.rs

index cc317e8cd7baf81f211f13f0f37179d8c842f45e..796d80bd9b27baf96f9edcbe2591b315cd5cc181 100644 (file)
@@ -219,13 +219,24 @@ fn handle_request(req: Request<Body>) -> BoxFut {
     let path = parts.uri.path();
 
     // normalize path
-    let components: Vec<&str> = path.split('/').filter(|x| !x.is_empty()).collect();
+    // do not allow ".", "..", or hidden files ".XXXX"
+    // also remove empty path components
+
+    let items = path.split('/');
+    let mut path = String::new();
+    let mut components = vec![];
+
+    for name in items {
+        if name.is_empty() { continue; }
+        if name.starts_with(".") {
+            http_error_future!(BAD_REQUEST, "Path contains illegal components.\n");
+        }
+        path.push('/');
+        path.push_str(name);
+        components.push(name);
+    }
+
     let comp_len = components.len();
-    let path = components.iter().fold(String::new(), |mut acc, chunk| {
-        acc.push('/');
-        acc.push_str(chunk);
-        acc
-    });
 
     println!("REQUEST {} {}", method, path);
     println!("COMPO {:?}", components);