From 28b6155ba5daa252240f334be41774d840bcfbd9 Mon Sep 17 00:00:00 2001 From: Wen Hui Date: Sun, 5 Nov 2023 07:20:15 -0500 Subject: [PATCH] Fix the bug that write redis sensitive command information to redis_cli historyfile (#11489) Currently, we do not write the following sensitive commands into the ~/.rediscli_history file: ACL SETUSER username [rule [rule ...]] AUTH [username] password HELLO [AUTH username password] MIGRATE host port destination-db timeout [[AUTH password | AUTH2 username password]] CONFIG SET masterauth master-password CONFIG SET masteruser username CONFIG SET requirepass foobared However, we still write the following sensitive commands into the ~/.rediscli_history file: ACL GETUSER username Sentinel CONFIG set sentinel-pass password Sentinel CONFIG set sentinel-user username Sentinel set mastername auth-pass password Sentinel set mastername auth-user username This change adds the commands of the second list to be skipped from being written to the history file. --- src/redis-cli.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 34f033947..0177effa2 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -3262,16 +3262,19 @@ void cliLoadPreferences(void) { /* Some commands can include sensitive information and shouldn't be put in the * history file. Currently these commands are include: * - AUTH - * - ACL SETUSER + * - ACL SETUSER, ACL GETUSER * - CONFIG SET masterauth/masteruser/requirepass * - HELLO with [AUTH username password] - * - MIGRATE with [AUTH password] or [AUTH2 username password] */ + * - MIGRATE with [AUTH password] or [AUTH2 username password] + * - SENTINEL CONFIG SET sentinel-pass password, SENTINEL CONFIG SET sentinel-user username + * - SENTINEL SET auth-pass password, SENTINEL SET auth-user username */ static int isSensitiveCommand(int argc, char **argv) { if (!strcasecmp(argv[0],"auth")) { return 1; } else if (argc > 1 && - !strcasecmp(argv[0],"acl") && - !strcasecmp(argv[1],"setuser")) + !strcasecmp(argv[0],"acl") && ( + !strcasecmp(argv[1],"setuser") || + !strcasecmp(argv[1],"getuser"))) { return 1; } else if (argc > 2 && @@ -3310,6 +3313,24 @@ static int isSensitiveCommand(int argc, char **argv) { return 0; } } + } else if (argc > 4 && !strcasecmp(argv[0], "sentinel")) { + /* SENTINEL CONFIG SET sentinel-pass password + * SENTINEL CONFIG SET sentinel-user username */ + if (!strcasecmp(argv[1], "config") && + !strcasecmp(argv[2], "set") && + (!strcasecmp(argv[3], "sentinel-pass") || + !strcasecmp(argv[3], "sentinel-user"))) + { + return 1; + } + /* SENTINEL SET auth-pass password + * SENTINEL SET auth-user username */ + if (!strcasecmp(argv[1], "set") && + (!strcasecmp(argv[3], "auth-pass") || + !strcasecmp(argv[3], "auth-user"))) + { + return 1; + } } return 0; }