mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-25 21:31:31 +00:00
Enforce webide whitelisting
This commit is contained in:
parent
b73b7307bd
commit
bc340e2e19
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user