Skip to content

Commit 1171ce7

Browse files
committed
Merge pull request from GHSA-7cc2-r658-7xpf
This fixes a vulnerability with the `CODER_OIDC_EMAIL_DOMAIN` option, where users with a superset of the allowed email domain would be allowed to login. For example, given `CODER_OIDC_EMAIL_DOMAIN=google.com`, a user would be permitted entry if their email domain was `colin-google.com`. (cherry picked from commit 4439a92)
1 parent b3e3521 commit 1171ce7

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

coderd/userauth.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,15 +905,23 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
905905

906906
if len(api.OIDCConfig.EmailDomain) > 0 {
907907
ok = false
908+
emailSp := strings.Split(email, "@")
909+
if len(emailSp) == 1 {
910+
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
911+
Message: fmt.Sprintf("Your email %q is not in domains %q!", email, api.OIDCConfig.EmailDomain),
912+
})
913+
return
914+
}
915+
userEmailDomain := emailSp[len(emailSp)-1]
908916
for _, domain := range api.OIDCConfig.EmailDomain {
909-
if strings.HasSuffix(strings.ToLower(email), strings.ToLower(domain)) {
917+
if strings.EqualFold(userEmailDomain, domain) {
910918
ok = true
911919
break
912920
}
913921
}
914922
if !ok {
915923
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
916-
Message: fmt.Sprintf("Your email %q is not in domains %q !", email, api.OIDCConfig.EmailDomain),
924+
Message: fmt.Sprintf("Your email %q is not in domains %q!", email, api.OIDCConfig.EmailDomain),
917925
})
918926
return
919927
}

coderd/userauth_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,17 @@ func TestUserOIDC(t *testing.T) {
664664
"kwc.io",
665665
},
666666
StatusCode: http.StatusOK,
667+
}, {
668+
Name: "EmailDomainSubset",
669+
IDTokenClaims: jwt.MapClaims{
670+
"email": "colin@gmail.com",
671+
"email_verified": true,
672+
},
673+
AllowSignups: true,
674+
EmailDomain: []string{
675+
"mail.com",
676+
},
677+
StatusCode: http.StatusForbidden,
667678
}, {
668679
Name: "EmptyClaims",
669680
IDTokenClaims: jwt.MapClaims{},

0 commit comments

Comments
 (0)