fix data validation for archive operations
authorMaciej Tronowski <mtro@man.poznan.pl>
Tue, 21 Apr 2015 11:52:19 +0000 (13:52 +0200)
committerMaciej Tronowski <mtro@man.poznan.pl>
Tue, 21 Apr 2015 11:52:19 +0000 (13:52 +0200)
filex/forms.py
filex/ftp.py

index e9b866f..17563b5 100644 (file)
@@ -41,6 +41,9 @@ class HostPathForm(HostForm):
 class HostPathNameForm(HostPathForm):
     name = forms.CharField(label=u'Nazwa', max_length=256, validators=[name_validator])
 
+    def clean_name(self):
+        return clean_path(self.cleaned_data['name'])
+
 
 class HostItemsForm(HostForm):
     dirs = forms.MultipleChoiceField(label=u'Katalogi', required=False, widget=forms.MultipleHiddenInput())
index 29c4598..4ed4e50 100644 (file)
@@ -4,6 +4,7 @@ from itertools import chain
 import os
 import re
 from threading import Event
+from django.utils.http import urlunquote
 
 from django.utils.timezone import localtime, UTC
 from gridftp import FTPClient, Buffer, HandleAttr, OperationAttr
@@ -162,6 +163,8 @@ class FTPOperation:
         return False
 
     def compress(self, server, path, files, archive):
+        self._check_disk_stack_args(*([path, archive] + files))
+
         if self.match_ext(archive, '.tar.gz', '.tgz'):
             cmd, args = 'tar', ['cvzf', archive, '-C', path] + files
         elif self.match_ext(archive, '.tar.bz2', '.tbz'):
@@ -176,6 +179,8 @@ class FTPOperation:
         return self.get(server)
 
     def extract(self, server, archive, dst):
+        self._check_disk_stack_args(*[archive, dst])
+
         if self.match_ext(archive, '.tar.gz', '.tgz'):
             cmd, args = 'tar', ('xvzf', archive, '-C', dst)
         elif self.match_ext(archive, '.tar.bz2', '.tbz'):
@@ -188,3 +193,10 @@ class FTPOperation:
         self.op_attr.set_disk_stack('#'.join(("popen:argv=", cmd) + args))
 
         return self.get(server)
+
+    @staticmethod
+    def _check_disk_stack_args(*args):
+        for char in ['#', ',', ';', '%23', '%3B']:
+            for arg in args:
+                if char in arg:
+                    raise ValueError('Unsupported character `{}` in `{}`!'.format(urlunquote(char), urlunquote(arg)))