From 231a796200919055161ffb3684eb5d25773e68aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 3 Dec 2019 17:26:29 +0100 Subject: [PATCH] =?UTF-8?q?=E2=98=94=20Limit=20legal=20plugin=20permission?= =?UTF-8?q?=20keys?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/plugins/hooks.rst | 2 +- src/octoprint/server/__init__.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/plugins/hooks.rst b/docs/plugins/hooks.rst index 292875591..7b79a96ed 100644 --- a/docs/plugins/hooks.rst +++ b/docs/plugins/hooks.rst @@ -218,7 +218,7 @@ octoprint.access.permissions and prefixed with ``PLUGIN__`` before being made available on ``octoprint.access.permissions.Permissions``, e.g. ``my_permission`` on the plugin with identifier ``example`` turns into ``PLUGIN_EXAMPLE_MY_PERMISSION`` and can be accessed as ``octoprint.access.permissions.Permissions.PLUGIN_EXAMPLE_MY_PERMISSION`` on the server and - ``permissions.PLUGIN_EXAMPLE_MY_PERMISSION`` on the ``AccessViewModel`` on the client. + ``permissions.PLUGIN_EXAMPLE_MY_PERMISSION`` on the ``AccessViewModel`` on the client. Must only contain a-z, A-Z, 0-9 and _. * ``name``: A human readable name for the permission. * ``description``: A human readable description of the permission. * ``permissions``: A list of permissions this permission includes, by key. diff --git a/src/octoprint/server/__init__.py b/src/octoprint/server/__init__.py index ed00ac566..56cd681f6 100644 --- a/src/octoprint/server/__init__.py +++ b/src/octoprint/server/__init__.py @@ -34,6 +34,7 @@ import logging.config import atexit import signal import base64 +import re try: import fcntl @@ -1870,6 +1871,8 @@ class Server(object): from octoprint.access.permissions import PluginOctoPrintPermission + key_whitelist = re.compile(r"[A-Za-z0-9_]*") + def permission_key(plugin, definition): return "PLUGIN_{}_{}".format(plugin.upper(), definition["key"].upper()) @@ -1942,6 +1945,10 @@ class Server(object): if not "key" in p or not "name" in p: continue + if not key_whitelist.match(p["key"]): + self._logger.warn("Got permission with invalid key from plugin {}: {}".format(name, p["key"])) + continue + if not process_regular_permission(plugin_info, p): postponed.append((plugin_info, p)) except Exception: