Skip to content

Commit d1aea05

Browse files
authored
Merge pull request from GHSA-gprj-3p75-f996
globus: apply identity_provider restriction in `check_blocked_users`
2 parents 79db03c + 04d11f8 commit d1aea05

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

oauthenticator/globus.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -297,30 +297,39 @@ async def check_allowed(self, username, auth_model):
297297
if auth_model is None:
298298
return True
299299

300+
if await super().check_allowed(username, auth_model):
301+
return True
302+
303+
if self.allowed_globus_groups:
304+
user_groups = set(auth_model["auth_state"]["globus_groups"])
305+
if user_groups & self.allowed_globus_groups:
306+
return True
307+
self.log.warning(f"{username} not in an allowed Globus Group")
308+
309+
# users should be explicitly allowed via config, otherwise they aren't
310+
return False
311+
312+
async def check_blocked_users(self, username, authentication):
313+
"""Check if the user should be blocked
314+
315+
Called _before_ checking if the user should be allowed
316+
"""
317+
# any restrictions on access go here - allow config only _grants_ access,
318+
# restrictions belong in the `block` stage
300319
# before considering allowing a username by being recognized in a list
301320
# of usernames or similar, we must ensure that the authenticated user is
302321
# from an allowed identity provider domain.
303322
if self.identity_provider:
304323
# It's possible for identity provider domains to be namespaced
305324
# https://docs.globus.org/api/auth/specification/#identity_provider_namespaces
306-
user_info = auth_model["auth_state"][self.user_auth_state_key]
325+
user_info = authentication["auth_state"][self.user_auth_state_key]
307326
user_domain = user_info.get(self.username_claim).split('@', 1)[-1]
308327
if user_domain != self.identity_provider:
309328
message = f"This site is restricted to {self.identity_provider} accounts. Link your account at app.globus.org/account."
310329
self.log.warning(message)
311330
raise web.HTTPError(403, message)
312331

313-
if await super().check_allowed(username, auth_model):
314-
return True
315-
316-
if self.allowed_globus_groups:
317-
user_groups = set(auth_model["auth_state"]["globus_groups"])
318-
if user_groups & self.allowed_globus_groups:
319-
return True
320-
self.log.warning(f"{username} not in an allowed Globus Group")
321-
322-
# users should be explicitly allowed via config, otherwise they aren't
323-
return False
332+
return super().check_blocked_users(username, authentication)
324333

325334
async def update_auth_model(self, auth_model):
326335
"""

0 commit comments

Comments
 (0)