You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-07-17 01:52:30 +02:00
Protect htpasswd user list from race condition
This commit is contained in:
@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
## Changes since v7.4.0
|
## Changes since v7.4.0
|
||||||
|
|
||||||
|
- [#1882](https://github.com/oauth2-proxy/oauth2-proxy/pull/1882) Make `htpasswd.GetUsers` racecondition safe
|
||||||
|
|
||||||
# V7.4.0
|
# V7.4.0
|
||||||
|
|
||||||
## Release Highlights
|
## Release Highlights
|
||||||
|
@ -139,6 +139,17 @@ func passShaOrBcrypt(h *htpasswdMap, user, password string) (invalidEntries []st
|
|||||||
return invalidEntries
|
return invalidEntries
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUsers return a "thread safe" copy of the internal user list
|
||||||
|
func (h *htpasswdMap) GetUsers() map[string]interface{} {
|
||||||
|
newUserList := make(map[string]interface{})
|
||||||
|
h.rwm.Lock()
|
||||||
|
for key, value := range h.users {
|
||||||
|
newUserList[key] = value
|
||||||
|
}
|
||||||
|
h.rwm.Unlock()
|
||||||
|
return newUserList
|
||||||
|
}
|
||||||
|
|
||||||
// Validate checks a users password against the htpasswd entries
|
// Validate checks a users password against the htpasswd entries
|
||||||
func (h *htpasswdMap) Validate(user string, password string) bool {
|
func (h *htpasswdMap) Validate(user string, password string) bool {
|
||||||
realPassword, exists := h.users[user]
|
realPassword, exists := h.users[user]
|
||||||
|
@ -149,7 +149,7 @@ var _ = Describe("HTPasswd Suite", func() {
|
|||||||
fileNames = append(fileNames, file.Name())
|
fileNames = append(fileNames, file.Name())
|
||||||
|
|
||||||
It("has the correct number of users", func() {
|
It("has the correct number of users", func() {
|
||||||
Expect(len(htpasswd.users)).To(Equal(hu.expectedLen))
|
Expect(len(htpasswd.GetUsers())).To(Equal(hu.expectedLen))
|
||||||
})
|
})
|
||||||
|
|
||||||
It(hu.testText, func() {
|
It(hu.testText, func() {
|
||||||
|
Reference in New Issue
Block a user