diff --git a/src/octoprint/plugins/logging/__init__.py b/src/octoprint/plugins/logging/__init__.py index 703d5c8a3..37c91c8c4 100644 --- a/src/octoprint/plugins/logging/__init__.py +++ b/src/octoprint/plugins/logging/__init__.py @@ -19,6 +19,7 @@ from octoprint.access.permissions import Permissions from octoprint.server import NO_CONTENT from octoprint.server.util.flask import no_firstrun_access, redirect_to_tornado from octoprint.settings import settings +from octoprint.util import is_hidden_path try: from os import scandir @@ -88,7 +89,11 @@ class LoggingPlugin( @Permissions.PLUGIN_LOGGING_MANAGE.require(403) def delete_log(self, filename): secure = os.path.join(settings().getBaseFolder("logs"), secure_filename(filename)) - if not os.path.exists(secure): + if ( + not os.path.exists(secure) + or is_hidden_path(secure) + or not filename.endswith(".log") + ): return make_response("File not found: %s" % filename, 404) os.remove(secure) @@ -142,6 +147,12 @@ class LoggingPlugin( files = [] basedir = settings().getBaseFolder("logs", check_writable=False) for entry in scandir(basedir): + if is_hidden_path(entry.path) or not entry.name.endswith(".log"): + continue + + if not entry.is_file(): + continue + files.append( { "name": entry.name, diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index c1adc7451..78e6a1d3a 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -747,10 +747,13 @@ class Server(object): lambda path: not octoprint.util.is_hidden_path(path), status_code=404 ) } + + valid_timelapse = lambda path: not octoprint.util.is_hidden_path( + path + ) and octoprint.timelapse.valid_timelapse(path) timelapse_path_validator = { "path_validation": util.tornado.path_validation_factory( - lambda path: not octoprint.util.is_hidden_path(path) - and octoprint.timelapse.valid_timelapse(path), + valid_timelapse, status_code=404, ) } @@ -761,12 +764,23 @@ class Server(object): status_code=400, ) } + + valid_log = ( + lambda path: not octoprint.util.is_hidden_path(path) + and path.endswith(".log") + and os.path.realpath(os.path.abspath(path)).startswith( + settings().getBaseFolder("logs") + ) + ) + log_path_validator = { + "path_validation": util.tornado.path_validation_factory( + valid_log, + status_code=404, + ) + } logs_path_validator = { "path_validation": util.tornado.path_validation_factory( - lambda path: not octoprint.util.is_hidden_path(path) - and os.path.realpath(os.path.abspath(path)).startswith( - settings().getBaseFolder("logs") - ), + valid_log, status_code=400, ) } @@ -841,6 +855,7 @@ class Server(object): }, download_handler_kwargs, log_permission_validator, + log_path_validator, ), ), # zipped log file bundles