Skip to content

Commit 8fbd9d9

Browse files
namsicjhpark816
authored andcommitted
FIX: Fix authorization check for gat and touch commands
1 parent 9ca75b7 commit 8fbd9d9

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

memcached.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8814,13 +8814,6 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens,
88148814
ENGINE_ERROR_CODE ret = ENGINE_SUCCESS;
88158815
int64_t exptime = 0;
88168816

8817-
#ifdef SASL_ENABLED
8818-
if (settings.require_sasl && !check_ascii_auth(c, AUTHZ_KV, key_token->value, tokens, ntokens)) {
8819-
out_string(c, "CLIENT_ERROR unauthorized");
8820-
return;
8821-
}
8822-
#endif
8823-
88248817
if (should_touch) {
88258818
// For get and touch commands, use first token as exptime
88268819
if (!safe_strtoll(tokens[1].value, &exptime)) {
@@ -8830,6 +8823,21 @@ static inline void process_get_command(conn *c, token_t *tokens, size_t ntokens,
88308823
key_token++;
88318824
}
88328825

8826+
#ifdef SASL_ENABLED
8827+
uint16_t need_perm = AUTHZ_KV;
8828+
if (should_touch) need_perm |= AUTHZ_ATTR;
8829+
8830+
// get with `arcus:` prefix without authentication are allowed for a single key only.
8831+
bool need_prefix_check = (ntokens == 3 || (should_touch && ntokens == 4));
8832+
8833+
if (settings.require_sasl && !check_ascii_auth(c, need_perm,
8834+
need_prefix_check ? key_token->value : NULL,
8835+
tokens, ntokens)) {
8836+
out_string(c, "CLIENT_ERROR unauthorized");
8837+
return;
8838+
}
8839+
#endif
8840+
88338841
do {
88348842
while (key_token->length != 0) {
88358843
if (key_token->length > KEY_MAX_LENGTH) {
@@ -13820,7 +13828,7 @@ static void process_touch_command(conn *c, token_t *tokens, const size_t ntokens
1382013828
size_t nkey = tokens[KEY_TOKEN].length;
1382113829

1382213830
#ifdef SASL_ENABLED
13823-
if (settings.require_sasl && !check_ascii_auth(c, AUTHZ_KV, key, tokens, ntokens)) {
13831+
if (settings.require_sasl && !check_ascii_auth(c, AUTHZ_ATTR, key, tokens, ntokens)) {
1382413832
out_string(c, "CLIENT_ERROR unauthorized");
1382513833
return;
1382613834
}

0 commit comments

Comments
 (0)