☔ Limit legal plugin permission keys
This commit is contained in:
1 parent
fe755405e8
commit
231a796200
2 files changed
+8
-1
No files matched your search
@@ -218,7 +218,7 @@ octoprint.access.permissions
|
||||
and prefixed with ``PLUGIN_<PLUGIN IDENTIFIER>_`` 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.
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user