Skip to content

Commit e1cf760

Browse files
authored
OIDC: case-insensitive comparison for auth scheme Basic (#31706)
@kylef pointed out on #31632 that [RFC7617](https://www.rfc-editor.org/rfc/rfc7617.html#section-2) mandates case-insensitive comparison of the scheme field `Basic`. #31632 copied a case-sensitive comparison from #6293. This PR fixes both comparisons. The issue only affects OIDC, since the implementation for normal Gitea endpoints is already correct: https://github.com/go-gitea/gitea/blob/930ca92d7ce80e8b0bdaf92e495026baf2a1d419/services/auth/basic.go#L55-L58
1 parent 4b376a0 commit e1cf760

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

routers/web/auth/oauth.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ func getOAuthGroupsForUser(ctx go_context.Context, user *user_model.User) ([]str
327327

328328
func parseBasicAuth(ctx *context.Context) (username, password string, err error) {
329329
authHeader := ctx.Req.Header.Get("Authorization")
330-
if authType, authData, ok := strings.Cut(authHeader, " "); ok && authType == "Basic" {
330+
if authType, authData, ok := strings.Cut(authHeader, " "); ok && strings.EqualFold(authType, "Basic") {
331331
return base.BasicAuthDecode(authData)
332332
}
333333
return "", "", errors.New("invalid basic authentication")
@@ -661,7 +661,7 @@ func AccessTokenOAuth(ctx *context.Context) {
661661
// if there is no ClientID or ClientSecret in the request body, fill these fields by the Authorization header and ensure the provided field matches the Authorization header
662662
if form.ClientID == "" || form.ClientSecret == "" {
663663
authHeader := ctx.Req.Header.Get("Authorization")
664-
if authType, authData, ok := strings.Cut(authHeader, " "); ok && authType == "Basic" {
664+
if authType, authData, ok := strings.Cut(authHeader, " "); ok && strings.EqualFold(authType, "Basic") {
665665
clientID, clientSecret, err := base.BasicAuthDecode(authData)
666666
if err != nil {
667667
handleAccessTokenError(ctx, AccessTokenError{

0 commit comments

Comments
 (0)