🐛 Fix missing protection for blueprint plugins

is_blueprint_protected should mean a requirement of a logged in non
anonymous user. Implemented accordingly. Got forgotten during switch to
granular permission system.
This commit is contained in:
Gina Häußge committed 2020-02-25 15:37:50 +01:00
1 parent b7fdc82d30
commit 20c55f4d3d
3 files changed
+17 -2

No files matched your search

+4 -1
View File
@@ -1391,9 +1391,12 @@ class BlueprintPlugin(OctoPrintPlugin, RestartNeedingPlugin):
# noinspection PyMethodMayBeStatic
def is_blueprint_protected(self):
"""
Whether a login session is needed to access the blueprint if the forcelogin plugin is enabled or not. Requiring
Whether a login session by a registered user is needed to access the blueprint's endpoints. Requiring
a session is the default. Note that this only restricts access to the blueprint's dynamic methods, static files
are always accessible.
If you want your blueprint's endpoints to have specific permissions, return ``False`` for this and do your
permissions checks explicitly.
"""
return True
+4 -1
View File
@@ -100,7 +100,7 @@ import octoprint.filemanager.storage
import octoprint.filemanager.analysis
import octoprint.slicing
from octoprint.server.util import loginFromApiKeyRequestHandler, corsRequestHandler, \
corsResponseHandler
corsResponseHandler, requireLoginRequestHandler
from octoprint.server.util.flask import PreemptiveCache
VERSION = __version__
@@ -1329,6 +1329,9 @@ class Server(object):
blueprint.before_request(loginFromApiKeyRequestHandler)
blueprint.after_request(corsResponseHandler)
if plugin.is_blueprint_protected():
blueprint.before_request(requireLoginRequestHandler)
url_prefix = "/plugin/{name}".format(name=name)
app.register_blueprint(blueprint, url_prefix=url_prefix)
+9
View File
@@ -102,6 +102,15 @@ def loginUser(user, remember=False):
return False
def requireLoginRequestHandler():
if _flask.request.endpoint.endswith(".static"):
return
user = flask_login.current_user
if user is None or user.is_anonymous() or not user.is_active():
return flask.make_response("Forbidden", 403)
def corsRequestHandler():
"""
``before_request`` handler for blueprints which sets CORS headers for OPTIONS requests if enabled