Skip to content

Commit 24d65c3

Browse files
authored
fix: acl pubsub should only glob match the channel (#5769)
publish command accepts only a single channel and a message, yet IsUserAllowedToInvokeCmd glob matched both the channel and the message which effectively rejected incorrectly the command execution because of permissions. Signed-off-by: kostas <[email protected]>
1 parent 9c01e3a commit 24d65c3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/server/acl/acl_family_test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,15 @@ TEST_F(AclFamilyTest, TestPubSub) {
538538
vec = resp.GetVec();
539539
EXPECT_THAT(vec[8], "channels");
540540
EXPECT_THAT(vec[9], "resetchannels &foo");
541+
542+
resp =
543+
Run("ACL setuser demo on resetkeys resetchannels ~app|managed-resources|* "
544+
"&app|managed-resources|* +publish +ping >passwd");
545+
resp = Run("AUTH demo passwd");
546+
EXPECT_THAT(resp, "OK");
547+
548+
resp = Run("publish app|managed-resources|xyz test");
549+
EXPECT_THAT(resp, IntArg(0));
541550
}
542551

543552
TEST_F(AclFamilyTest, TestAlias) {

src/server/acl/validator.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ bool ValidateCommand(const std::vector<uint64_t>& acl_commands, const CommandId&
5050

5151
bool allowed = true;
5252
if (!pub_sub.all_channels) {
53-
for (auto channel : tail_args) {
53+
std::string_view name = id.name();
54+
if (name == "PUBLISH" || name == "SPUBLISH") {
55+
auto channel = tail_args[0];
5456
allowed &= iterate_globs(facade::ToSV(channel));
57+
} else {
58+
for (auto channel : tail_args) {
59+
allowed &= iterate_globs(facade::ToSV(channel));
60+
}
5561
}
5662
}
5763

0 commit comments

Comments
 (0)