Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raise no-authorization warning once and allow disabled authorization #738

Merged
merged 2 commits into from Mar 16, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 18 additions & 9 deletions jupyter_server/auth/decorator.py
Expand Up @@ -14,6 +14,9 @@
from .utils import HTTP_METHOD_TO_AUTH_ACTION


WARNED_ABOUT_DISABLED_AUTHORIZATION = False


def raise_no_authorizer_warning():
warnings.warn(
"The Tornado web application does not have an 'authorizer' defined "
Expand All @@ -24,7 +27,7 @@ def raise_no_authorizer_warning():
"https://github.com/jupyter-server/jupyter_server/blob/"
"653740cbad7ce0c8a8752ce83e4d3c2c754b13cb/jupyter_server/serverapp.py"
"#L234-L256",
# stacklevel=2
DeprecationWarning,
Zsailer marked this conversation as resolved.
Show resolved Hide resolved
)


Expand Down Expand Up @@ -74,17 +77,23 @@ def inner(self, *args, **kwargs):
if not user:
app_log.warning("Attempting to authorize request without authentication!")
raise HTTPError(status_code=403, log_message=message)
# If the user is allowed to do this action,
# call the method.

# Handle the case where an authorizer wasn't attached to the handler.
if not self.authorizer:
with warnings.catch_warnings():
warnings.simplefilter("once")
raise_no_authorizer_warning()
elif self.authorizer.is_authorized(self, user, action, resource):
warnings.simplefilter("default")
global WARNED_ABOUT_DISABLED_AUTHORIZATION
if not WARNED_ABOUT_DISABLED_AUTHORIZATION:
raise_no_authorizer_warning()
WARNED_ABOUT_DISABLED_AUTHORIZATION = True
return method(self, *args, **kwargs)
# else raise an exception.
else:
raise HTTPError(status_code=403, log_message=message)

# Only return the method if the action is authorized.
if self.authorizer.is_authorized(self, user, action, resource):
return method(self, *args, **kwargs)

# Raise an exception if the method wasn't returned (i.e. not authorized)
raise HTTPError(status_code=403, log_message=message)

return inner

Expand Down