Skip to content

Commit 2ba8491

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 72708c7 commit 2ba8491

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
@@ -906,15 +906,23 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
906906

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

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)