git.iko.soy/typeable/oauth2-proxy
on master help sign in
Protect htpasswd user list from race condition
commit86011e8ac7e41b522a17ae191bbb2a55b5f3eba3 authorDamien Degois <damien@degois.info> dateThu 3 Nov 2022, 13:57 (4 years ago) parentaafa966
3 files changed+14−1
CHANGELOG.md+2 pkg/authentication/basic/htpasswd.go+11 pkg/authentication/basic/htpasswd_test.go+1−1
CHANGELOG.md+2
@@ -8,6 +8,8 @@
88
99## Changes since v7.4.0
1010
11+- [#1882](https://github.com/oauth2-proxy/oauth2-proxy/pull/1882) Make `htpasswd.GetUsers` racecondition safe
12+
1113# V7.4.0
1214
1315## Release Highlights
pkg/authentication/basic/htpasswd.go+11
@@ -139,6 +139,17 @@ func passShaOrBcrypt(h *htpasswdMap, user, password string) (invalidEntries []st
139139 return invalidEntries
140140}
141141
142+// GetUsers return a "thread safe" copy of the internal user list
143+func (h *htpasswdMap) GetUsers() map[string]interface{} {
144+ newUserList := make(map[string]interface{})
145+ h.rwm.Lock()
146+ for key, value := range h.users {
147+ newUserList[key] = value
148+ }
149+ h.rwm.Unlock()
150+ return newUserList
151+}
152+
142153// Validate checks a users password against the htpasswd entries
143154func (h *htpasswdMap) Validate(user string, password string) bool {
144155 realPassword, exists := h.users[user]
pkg/authentication/basic/htpasswd_test.go+1−1
@@ -149,7 +149,7 @@ var _ = Describe("HTPasswd Suite", func() {
149149 fileNames = append(fileNames, file.Name())
150150
151151 It("has the correct number of users", func() {
152− Expect(len(htpasswd.users)).To(Equal(hu.expectedLen))
152+ Expect(len(htpasswd.GetUsers())).To(Equal(hu.expectedLen))
153153 })
154154
155155 It(hu.testText, func() {