mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 03:18:24 +00:00 
			
		
		
		
	Fix http auth header parsing (#34936)
Using `strings.EqualFold` is wrong in many cases.
This commit is contained in:
		| @@ -13,6 +13,7 @@ import ( | ||||
| 	actions_model "code.gitea.io/gitea/models/actions" | ||||
| 	auth_model "code.gitea.io/gitea/models/auth" | ||||
| 	user_model "code.gitea.io/gitea/models/user" | ||||
| 	"code.gitea.io/gitea/modules/auth/httpauth" | ||||
| 	"code.gitea.io/gitea/modules/log" | ||||
| 	"code.gitea.io/gitea/modules/setting" | ||||
| 	"code.gitea.io/gitea/modules/timeutil" | ||||
| @@ -97,9 +98,9 @@ func parseToken(req *http.Request) (string, bool) { | ||||
|  | ||||
| 	// check header token | ||||
| 	if auHead := req.Header.Get("Authorization"); auHead != "" { | ||||
| 		auths := strings.Fields(auHead) | ||||
| 		if len(auths) == 2 && (auths[0] == "token" || strings.ToLower(auths[0]) == "bearer") { | ||||
| 			return auths[1], true | ||||
| 		parsed, ok := httpauth.ParseAuthorizationHeader(auHead) | ||||
| 		if ok && parsed.BearerToken != nil { | ||||
| 			return parsed.BearerToken.Token, true | ||||
| 		} | ||||
| 	} | ||||
| 	return "", false | ||||
|   | ||||
		Reference in New Issue
	
	Block a user