Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d37eb4

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 e7033b3 commit 2d37eb4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

coderd/userauth.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -928,15 +928,23 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
928928

929929
if len(api.OIDCConfig.EmailDomain) > 0 {
930930
ok = false
931+
emailSp := strings.Split(email, "@")
932+
if len(emailSp) == 1 {
933+
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
934+
Message: fmt.Sprintf("Your email %q is not in domains %q!", email, api.OIDCConfig.EmailDomain),
935+
})
936+
return
937+
}
938+
userEmailDomain := emailSp[len(emailSp)-1]
931939
for _, domain := range api.OIDCConfig.EmailDomain {
932-
if strings.HasSuffix(strings.ToLower(email), strings.ToLower(domain)) {
940+
if strings.EqualFold(userEmailDomain, domain) {
933941
ok = true
934942
break
935943
}
936944
}
937945
if !ok {
938946
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
939-
Message: fmt.Sprintf("Your email %q is not in domains %q !", email, api.OIDCConfig.EmailDomain),
947+
Message: fmt.Sprintf("Your email %q is not in domains %q!", email, api.OIDCConfig.EmailDomain),
940948
})
941949
return
942950
}

coderd/userauth_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,17 @@ func TestUserOIDC(t *testing.T) {
757757
"kwc.io",
758758
},
759759
StatusCode: http.StatusOK,
760+
}, {
761+
Name: "EmailDomainSubset",
762+
IDTokenClaims: jwt.MapClaims{
763+
"email": "[email protected]",
764+
"email_verified": true,
765+
},
766+
AllowSignups: true,
767+
EmailDomain: []string{
768+
"mail.com",
769+
},
770+
StatusCode: http.StatusForbidden,
760771
}, {
761772
Name: "EmptyClaims",
762773
IDTokenClaims: jwt.MapClaims{},

0 commit comments

Comments
 (0)