Skip to content

Commit 0eaab74

Browse files
author
caiyu
committed
fix: requirepass allows connection with any non-empty password
1 parent 0014d47 commit 0eaab74

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/acl.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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()) {

tests/integration/acl_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff 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
})

0 commit comments

Comments
 (0)