Skip to content

Commit 75ec423

Browse files
committed
Add blocklist and allowlist for oidc domains
1 parent 2a01115 commit 75ec423

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

oidc/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
ERR_INVALID_RESPONSE = (
1212
"Unable to fetch user information from provider. Please check the log."
1313
)
14+
ERR_INVALID_DOMAIN = (
15+
"The domain for your account (%s) is not allowed to authenticate with this provider."
16+
)
17+
OIDC_DOMAIN_BLOCKLIST = frozenset(getattr(settings, "OIDC_DOMAIN_BLOCKLIST", []))
18+
OIDC_DOMAIN_ALLOWLIST = frozenset(getattr(settings, "OIDC_DOMAIN_ALLOWLIST", []))
1419
ISSUER = None
1520

1621
DATA_VERSION = "1"

oidc/views.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sentry.utils.compat import map
66
from sentry.utils.signing import urlsafe_b64decode
77

8-
from .constants import ERR_INVALID_RESPONSE, ISSUER
8+
from .constants import ERR_INVALID_RESPONSE, ISSUER, ERR_INVALID_DOMAIN
99

1010
logger = logging.getLogger("sentry.auth.oidc")
1111

@@ -47,6 +47,15 @@ def dispatch(self, request, helper):
4747
else:
4848
domain = payload.get("hd")
4949

50+
if domain is None:
51+
return helper.error(ERR_INVALID_DOMAIN % (domain,))
52+
53+
if domain in OIDC_DOMAIN_BLOCKLIST:
54+
return helper.error(ERR_INVALID_DOMAIN % (domain,))
55+
56+
if OIDC_DOMAIN_ALLOWLIST != set() and domain not in OIDC_DOMAIN_ALLOWLIST:
57+
return helper.error(ERR_INVALID_DOMAIN % (domain,))
58+
5059
helper.bind_state("domain", domain)
5160
helper.bind_state("user", payload)
5261

0 commit comments

Comments
 (0)