File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -497,6 +497,10 @@ void Acl::InitLimitUser(const std::string& bl, bool limit_exist) {
497497 }
498498 if (!pass.empty ()) {
499499 u->SetUser (" >" + pass);
500+ }else {
501+ // If the userpass password is empty,
502+ // disable the limit user to prevent password-free access
503+ u->SetUser (" off" );
500504 }
501505 } else {
502506 if (pass.empty ()) {
Original file line number Diff line number Diff line change @@ -124,5 +124,22 @@ var _ = Describe("Acl test", func() {
124124 Expect (err ).NotTo (HaveOccurred ())
125125 Expect (len (logEntries )).To (Equal (0 ))
126126 })
127-
127+ // Test case for the bug: any non-empty requirepass could connect when requirepass is set.
128+ // pika.conf: requirepass abc
129+ It ("has wrong password returns error and correct password returns OK" , func () {
130+ ctx := context .TODO ()
131+ client := redis .NewClient (& redis.Options {
132+ Addr : "127.0.0.1:9221" ,
133+ })
134+ authRes := client .Do (ctx , "auth" , "wrongpass" )
135+ Expect (authRes .Err ()).To (MatchError ("WRONGPASS invalid username-password pair or user is disabled." ))
136+ client .Close ()
137+ client = redis .NewClient (& redis.Options {
138+ Addr : "127.0.0.1:9221" ,
139+ })
140+ authRes = client .Do (ctx , "auth" , "abc" )
141+ Expect (authRes .Err ()).NotTo (HaveOccurred ())
142+ Expect (authRes .Val ()).To (Equal ("OK" ))
143+ client .Close ()
144+ })
128145})
You can’t perform that action at this time.
0 commit comments