🥅 logging: Don't manage anything but .log files
You never know what people might do.
This commit is contained in:
1 parent
47cf12e9f3
commit
07c1d53a44
2 files changed
+33
-7
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user