Skip to content

Commit b98e0aa

Browse files
madolsonYaacovHazan
authored andcommitted
Fix Read/Write key pattern selector (CVE-2024-51741) (valkey-io#1514)
The explanation on the original commit was wrong. Key based access must have a `~` in order to correctly configure whey key prefixes to apply the selector to. If this is missing, a server assert will be triggered later. Signed-off-by: Madelyn Olson <[email protected]> Co-authored-by: YaacovHazan <[email protected]>
1 parent 969ae2d commit b98e0aa

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/acl.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -1046,19 +1046,24 @@ int ACLSetSelector(aclSelector *selector, const char* op, size_t oplen) {
10461046
int flags = 0;
10471047
size_t offset = 1;
10481048
if (op[0] == '%') {
1049+
int perm_ok = 1;
10491050
for (; offset < oplen; offset++) {
10501051
if (toupper(op[offset]) == 'R' && !(flags & ACL_READ_PERMISSION)) {
10511052
flags |= ACL_READ_PERMISSION;
10521053
} else if (toupper(op[offset]) == 'W' && !(flags & ACL_WRITE_PERMISSION)) {
10531054
flags |= ACL_WRITE_PERMISSION;
1054-
} else if (op[offset] == '~' && flags) {
1055+
} else if (op[offset] == '~') {
10551056
offset++;
10561057
break;
10571058
} else {
1058-
errno = EINVAL;
1059-
return C_ERR;
1059+
perm_ok = 0;
1060+
break;
10601061
}
10611062
}
1063+
if (!flags || !perm_ok) {
1064+
errno = EINVAL;
1065+
return C_ERR;
1066+
}
10621067
} else {
10631068
flags = ACL_ALL_PERMISSION;
10641069
}

tests/unit/acl-v2.tcl

+22-1
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,32 @@ start_server {tags {"acl external:skip"}} {
116116
assert_match "*NOPERM*key*" $err
117117
}
118118

119-
test {Validate read and write permissions format} {
119+
test {Validate read and write permissions format - empty permission} {
120120
catch {r ACL SETUSER key-permission-RW %~} err
121121
set err
122122
} {ERR Error in ACL SETUSER modifier '%~': Syntax error}
123123

124+
test {Validate read and write permissions format - empty selector} {
125+
catch {r ACL SETUSER key-permission-RW %} err
126+
set err
127+
} {ERR Error in ACL SETUSER modifier '%': Syntax error}
128+
129+
test {Validate read and write permissions format - empty pattern} {
130+
# Empty pattern results with R/W access to no key
131+
r ACL SETUSER key-permission-RW on nopass %RW~ +@all
132+
$r2 auth key-permission-RW password
133+
catch {$r2 SET x 5} err
134+
set err
135+
} {NOPERM No permissions to access a key}
136+
137+
test {Validate read and write permissions format - no pattern} {
138+
# No pattern results with R/W access to no key (currently we accept this syntax error)
139+
r ACL SETUSER key-permission-RW on nopass %RW +@all
140+
$r2 auth key-permission-RW password
141+
catch {$r2 SET x 5} err
142+
set err
143+
} {NOPERM No permissions to access a key}
144+
124145
test {Test separate read and write permissions on different selectors are not additive} {
125146
r ACL SETUSER key-permission-RW-selector on nopass "(%R~read* +@all)" "(%W~write* +@all)"
126147
$r2 auth key-permission-RW-selector password

0 commit comments

Comments
 (0)