Skip to content

Commit 57582f0

Browse files
committed
fixup! fix: map oidc user to iss/sub
1 parent 6d0ff47 commit 57582f0

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

api/oidc.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"fmt"
99
"io"
1010
"net/http"
11+
"net/url"
12+
"strings"
1113
"time"
1214

1315
"github.com/gin-gonic/gin"
@@ -399,6 +401,12 @@ func (a *OIDCAPI) resolveUser(issuer string, info *oidc.UserInfo) (*model.User,
399401
if issuer == "" {
400402
return nil, http.StatusInternalServerError, errors.New("issuer claim was empty")
401403
}
404+
if _, err := url.Parse(issuer); err != nil {
405+
return nil, http.StatusInternalServerError, fmt.Errorf("issuer url %q is not a valid url: %w", issuer, err)
406+
}
407+
if strings.Contains(issuer, "#") {
408+
return nil, http.StatusInternalServerError, fmt.Errorf("issuer url %q may not contain a fragment", issuer)
409+
}
402410
subject := info.GetSubject()
403411
if subject == "" {
404412
return nil, http.StatusInternalServerError, errors.New("subject claim was empty")

api/oidc_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ func (s *OIDCSuite) Test_ResolveUser_LinkByUsername_BindsExistingUser() {
100100
assert.Equal(s.T(), uint(1), bound.ID)
101101
}
102102

103+
func (s *OIDCSuite) Test_ResolveUser_InvalidIssuer() {
104+
s.db.NewUserWithName(1, "alice")
105+
106+
info := &oidc.UserInfo{Subject: "sub-1", Claims: map[string]any{"preferred_username": "alice"}}
107+
_, status, err := s.a.resolveUser("://example.org", info)
108+
109+
assert.EqualError(s.T(), err, `issuer url "://example.org" is not a valid url: parse "://example.org": missing protocol scheme`)
110+
assert.Equal(s.T(), 500, status)
111+
}
112+
113+
func (s *OIDCSuite) Test_ResolveUser_InvalidIssuer_containsFragment() {
114+
s.db.NewUserWithName(1, "alice")
115+
116+
info := &oidc.UserInfo{Subject: "sub-1", Claims: map[string]any{"preferred_username": "alice"}}
117+
_, status, err := s.a.resolveUser(testIssuer+"#", info)
118+
119+
assert.EqualError(s.T(), err, `issuer url "https://idp.example.com#" may not contain a fragment`)
120+
assert.Equal(s.T(), 500, status)
121+
}
122+
103123
func (s *OIDCSuite) Test_ResolveUser_LinkDisabled_RejectsExistingUsername() {
104124
s.db.NewUserWithName(1, "alice")
105125

0 commit comments

Comments
 (0)