Enforce webide whitelisting

This commit is contained in:
Kristóf Tóth 2018-04-05 17:16:41 +02:00
parent b73b7307bd
commit bc340e2e19

View File

@ -14,7 +14,7 @@ LOG = logging.getLogger(__name__)
class FileManager: # pylint: disable=too-many-instance-attributes
def __init__(self, working_directory, allowed_directories=None, selected_file=None, exclude=None):
def __init__(self, working_directory, allowed_directories, selected_file=None, exclude=None):
self._exclude, self.exclude = None, exclude
self._allowed_directories, self.allowed_directories = None, allowed_directories
self._workdir, self.workdir = None, working_directory
@ -40,9 +40,8 @@ class FileManager: # pylint: disable=too-many-instance-attributes
def workdir(self, directory):
if not exists(directory) or not isdir(directory):
raise EnvironmentError('"{}" is not a directory!'.format(directory))
if self.allowed_directories:
if not self._is_whitelisted(directory):
raise EnvironmentError('Directory "{}" is not in whitelist!'.format(directory))
if not self._is_whitelisted(directory):
raise EnvironmentError('Directory "{}" is not in whitelist!'.format(directory))
self._workdir = directory
@property
@ -92,7 +91,7 @@ class FileManager: # pylint: disable=too-many-instance-attributes
class SourceCodeEventHandler(TriggerlessEventHandler):
# pylint: disable=too-many-arguments
def __init__(self, key, directory, allowed_directories=None, selected_file=None, exclude=None):
def __init__(self, key, directory, allowed_directories, selected_file=None, exclude=None):
super().__init__(key)
self.filemanager = FileManager(allowed_directories=allowed_directories, working_directory=directory,
selected_file=selected_file, exclude=exclude)