Skip to content

Commit 1e18aae

Browse files
jiajunjieZsailer
andauthored
Add authorization to AuthenticatedFileHandler (#1021)
Co-authored-by: Zachary Sailer <[email protected]>
1 parent e66306d commit 1e18aae

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

jupyter_server/auth/authorizer.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
"""
88
# Copyright (c) Jupyter Development Team.
99
# Distributed under the terms of the Modified BSD License.
10+
from __future__ import annotations
11+
12+
from typing import TYPE_CHECKING
13+
1014
from traitlets import Instance
1115
from traitlets.config import LoggingConfigurable
1216

13-
from jupyter_server.base.handlers import JupyterHandler
14-
1517
from .identity import IdentityProvider, User
1618

19+
if TYPE_CHECKING:
20+
from jupyter_server.base.handlers import JupyterHandler
21+
1722

1823
class Authorizer(LoggingConfigurable):
1924
"""Base class for authorizing access to resources

jupyter_server/base/handlers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import jupyter_server
2929
from jupyter_server._sysinfo import get_sys_info
3030
from jupyter_server._tz import utcnow
31+
from jupyter_server.auth import authorized
3132
from jupyter_server.i18n import combine_translations
3233
from jupyter_server.services.security import csp_report_uri
3334
from jupyter_server.utils import (
@@ -813,18 +814,22 @@ async def prepare(self):
813814
class AuthenticatedFileHandler(JupyterHandler, web.StaticFileHandler):
814815
"""static files should only be accessible when logged in"""
815816

817+
auth_resource = "contents"
818+
816819
@property
817820
def content_security_policy(self):
818821
# In case we're serving HTML/SVG, confine any Javascript to a unique
819822
# origin so it can't interact with the Jupyter server.
820823
return super().content_security_policy + "; sandbox allow-scripts"
821824

822825
@web.authenticated
826+
@authorized
823827
def head(self, path):
824828
self.check_xsrf_cookie()
825829
return super().head(path)
826830

827831
@web.authenticated
832+
@authorized
828833
def get(self, path):
829834
if os.path.splitext(path)[1] == ".ipynb" or self.get_argument("download", None):
830835
name = path.rsplit("/", 1)[-1]

0 commit comments

Comments
 (0)