Repository navigation
Redact the password in --json-out-file and --show-config - #735
Conversation
d768ac9 to
84d94f8
Compare
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the C++ change and the new test file. The redaction itself looks right to me.
I traced The core fix looks solid to me. I'd just like the description brought up to date and the scope question answered before this merges. (I'd file this as a comment, not a formal block.) |
84d94f8 to
95ce587
Compare
|
Thanks. On the replica-discovery nit: RLTest starts every node on loopback, so the About "no URI that worked before parses differently": there was one counterexample. With a stray |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 95ce587. Configure here.
95ce587 to
6bb1195
Compare
|
Thanks. Answers to the points in the first-pass review, as of 6bb1195:
|
6bb1195 to
1be5463
Compare
|
Thanks. Point by point, as of 1be5463:
|
1be5463 to
626ae59
Compare
|
Thanks. Point by point, as of 626ae59:
|
626ae59 to
a87bd79
Compare
|
Thanks. I followed both of your suggestions, as of a87bd79:
|
a87bd79 to
7c22f34
Compare
|
Thanks. Point by point, as of 7c22f34:
Local runs at 7c22f34: 20/20 in 5/5 runs on OSS standalone, and 20/20 on OSS cluster, standalone with |
config_print_to_json() and config_print() wrote --uri and -a/--authenticate verbatim, so "uri" and "authenticate" in the JSON configuration (and the matching --show-config lines on stderr) carried the server password. JSON result files are routinely uploaded as CI artifacts or attached to reports, so the password travelled with them. Both now go through redact_uri()/redact_credentials(): the user name is kept and only the secret is replaced, e.g. redis://default:***@host:port and "default:***", or "***" for a bare password. With no credentials the fields stay "" as before, and the field names do not change. Consumers that read "authenticate" will now see "***" instead of the credential. Fixes #731 Co-Authored-By: Claude Opus 5.5 <[email protected]>
parse_uri() ended the userinfo at the first '@'. With a password that contains '@', the rest of the password became the host (or host:port), and --show-config "server = ...", "invalid port number '...'", "Name or service not known" and "invalid IPv6 host" all printed it, even though redact_uri() already hid it in "uri". '@' cannot appear in host, port or db (RFC 3986), so ending at the last '@' is correct, matches redact_uri(), and makes a raw '@' in the password work. Tests: cover a password containing '@' (connects, nothing leaks) and a bad-port variant whose error must not carry the tail, a password with ':', and a credential-less --uri. requirepass/masterauth are now set on replicas too and restored only on the nodes that were changed. The test also joins the sanitizer TLS "misc" lists next to test_prometheus_redaction.py. Refs #731 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Searching the whole URI for the last '@' let an '@' in the db path end the credentials: redis://default:[email protected]:23300/1@ became userinfo "default:[email protected]:23300/1" with an empty host, and the run fell back to the default server, benchmarking the wrong target. Before e63a787 it was rejected as "invalid database number". uri_userinfo_end() now limits the search to the authority: it ends at the first '/' after the first '@' (RFC 3986), and the userinfo ends at the last '@' before that, so a raw '@' (or '/') in the password still works and its tail is still never taken for the host. parse_uri() and redact_uri() both use it. Credentials followed by an empty host are now rejected ("missing host after credentials in URI") instead of silently falling back to the default server. Tests: a stray '@' in the path gives rc 1, redis://u:p@w@host:port/x@y is not read as host y, credentials with an empty host are rejected, and _run() passes --tls-protocols when TLS_PROTOCOLS is set so the TLS 1.3 cells really force 1.3. Refs #731 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e host uri_userinfo_end() stopped the '@' search only at '/'. With no db path, an '@' in a query or fragment ended the credentials instead: redis://u:[email protected]:[email protected]:Q connected to 127.0.0.2:Q and sent it "AUTH u [email protected]:P?x=". Master rejected that URI (invalid port). RFC 3986 ends the authority at '/', '?' or '#', so stop at the first of those (strpbrk). The URI is rejected again and nothing reaches the second host. The comment now also says that a password with an '@' followed by '/' is still split at that '/' as before, which needs #732's percent-encoding. Tests: '?' and '#' forms exit with rc 1 and a decoy listener on the second host sees no connection; a raw '/' in the password keeps working; a /x@wrong/2 path catches a whole-string last-'@' split. Refs #731 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The empty-host check fires on any '@' with nothing after it, including a credential-less redis://host:6379/1@, so "missing host after credentials" was misleading; it now says "missing host in URI". The uri_userinfo_end() comment claimed a stray '@' in the db path never ends the credentials. That holds only once credentials are present: without them, redis://host:6379/1@other:6379 still reads "host:6379/1" as credentials for host "other", as on master. Fixing that by treating a '/', '?' or '#' before the first '@' as "no userinfo" would break a raw '/' in passwords, which master supports, so it is left to #732 and pinned by a test. redact_uri() now notes that it assumes a URI parse_uri() has already validated. Refs #731 Co-Authored-By: Claude Opus 5.5 <[email protected]>
On master, parse_uri() overrides the server only when the URI has a host, so "-s myhost --uri redis://default:pw@:6379" ran against myhost and "-S /tmp/redis.sock --uri redis://default:pw@" sent the credentials over the unix socket. The "missing host in URI" check rejected both. Reject an empty host only when neither --server nor --unix-socket was given; that is the case that fell back to the default server. parse_uri() runs before config_init_defaults(), so a non-NULL server or unix_socket there can only come from the command line, and no extra flag is needed. Tests: -s HOST with a host-less --uri connects to HOST and is redacted; -S PATH with a host-less --uri tries PATH (connect fails, nothing listens there) instead of being rejected, and is redacted; a host-less --uri with neither is still rejected. Refs #731 Co-Authored-By: Claude Opus 5.5 <[email protected]>
redis://user:pw@:6379 (or redis://user:pw@) with no -s/-S fell back to the default server on master. Erroring out on it broke input that used to work, which the project avoids (#212). Keep the fallback and say where the run goes instead: warning: --uri has no host; connecting to the default server localhost:6379. The warning never includes the credentials. Still reject the case that is clearly wrong: an empty host where the "credentials" contain '/', '?' or '#', i.e. the '@' was a stray one after the path (redis://host:6379/1@). That never authenticated anything meaningful. It is now the only new URI rejection. Tests: the host-less case warns, connects to the default server and is redacted; the stray-'@' case is still rejected. Refs #731 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The warning only fired when the URI had an '@', so redis://:6379 still fell back to the default server silently while redis://u:pw@:6379 warned. Key it on the empty host instead. The stray-'@' rejection matched any "credentials" containing '/', '?' or '#', which also caught a real password with a raw '/' such as redis://u:a/b@:6379. On master that fell back to the default server. Reject only the exact stray-'@'-after-path shape: nothing at all after the '@' and one of '/?#' in the userinfo (redis://host:6379/1@). redis://u:a/b@:6379 now warns and falls back like the other host-less forms. redis://u:a/b@ cannot be told apart from a stray '@' without #732's percent-encoding, so it stays rejected. Tests: pin both '/'-in-password forms, add redis://:port (warns), and let the warn-and-default test run on either loopback name rather than skip unless the target is exactly "localhost". Refs #731 Co-Authored-By: Claude Opus 5.5 <[email protected]>
… back redis://host:6379/1@ (a stray '@' after the path) and redis://u:a/b@ were still rejected with "missing host in URI". On master both ran against the default server, so rejecting them broke input that used to run (#212). The stray-'@' form only ever sent a meaningless AUTH, and telling it apart from a raw '/' in a password is #732's job. Give them the same host-less warning and default-server fallback as every other empty host. This PR now rejects no URI that master accepted. Tests: the two rejection tests become warn-and-fallback tests, still redacted. -p keeps their fallback off localhost:6379, and the known-limit test uses a fixed closed port in the test range (it skips if something listens there) instead of binding and releasing an ephemeral one. Refs #731 Co-Authored-By: Claude Opus 5.5 <[email protected]>
7c22f34 to
184a1c7
Compare
|
Thanks. Point by point, as of 184a1c7 (rebased on #736):
The branch is rebased on 63c0009 (#736). The workflow conflict was the TEST lists, and I resolved it by keeping |
|
Thanks. Point by point, as of 184a1c7. I've only edited the description this round; there is no code change.
|
parse_uri() read the database number of redis://host:port/N with (int) strtol() and only checked db < 0, so the cast wrapped values outside int: /4294967296 selected db 0, /4294967297 db 1, /6442450943 db 2147483647, and the saturated -99999999999999999999999 became db 0. That is the #725 class #748 fixed for --select-db. The number now goes through parse_unsigned() with an INT_MAX bound, the same rule as --select-db: leading whitespace, one '+' and "-0" are accepted; any other negative, overflow, junk and values above INT_MAX are rejected with the existing "invalid database number '...'" error. An empty path ("redis://host:port/") still selects no database, and #735's userinfo split (including the known '@'-in-path limits pinned by test_config_password_redaction.py) is unchanged. Refs #725 Co-Authored-By: Claude Opus 5.5 <[email protected]>
parse_uri() read the database number in redis://host:port/N with (int) strtol() and only checked the end pointer and db < 0, so values outside int wrapped silently: /4294967296 selected db 0, /4294967297 db 1, /6442450943 db 2147483647, and large negatives such as /-4294967295 or /-99999999999999999999999 also landed on a valid db. The number now goes through parse_unsigned() with an INT_MAX bound, the same rule as --select-db: leading whitespace, a single '+' and -0 are accepted; any other negative, overflow, junk or value above INT_MAX is rejected with "error: invalid database number '...'.". An empty path still selects no database and keeps any --select-db value. The userinfo split from #735 is unchanged. Refs #725 Co-Authored-By: Claude Opus 5.5 <[email protected]>
--uri took the userinfo verbatim, so the RFC 3986 spelling of a reserved character (%40 for '@', %2F for '/', %3A for ':') reached AUTH as the literal three characters and authentication failed, although the help says the format is redis-cli compatible and redis-cli -u decodes them. A password with an '@' followed by a '/' could not be given at all. The userinfo is still split where uri_userinfo_end() splits it (#735), then at the first raw ':', and only then are the user name and password decoded, so encoded delimiters land in the password. Only the userinfo is decoded, as in redis-cli: the port and db number are digits, and a raw IPv6 zone id ("[fe80::1%eth0]") keeps working. Compatibility with URIs master accepted: - A '%' not followed by two hex digits (a password such as "100%") is kept as a literal '%' with a warning, instead of being rejected as redis-cli does, since master accepted it. - A valid %XX is now decoded; that is the fix, and %25 spells a '%'. - %00 is rejected (credentials are passed on as a C string), and so is a decoded ':' in the user name, which AUTH credentials split at the first ':' cannot carry. A password-only userinfo that decodes to a ':' gets a leading ':' so authenticate() still reads it as a password. - A raw '/', '?' or '#' in the credentials keeps working but now warns, since it cannot be told apart from an '@' in the path; this flips the #735 known-limit test for the credential-less '@' in the path. No message echoes the credentials, and --show-config/--json-out-file keep printing the password as "***". Fixes #732 Co-Authored-By: Claude Opus 5.5 <[email protected]>

Problem
--json-out-filewrote the server password in clear text: the full--uri(withuser:password@) inconfiguration.uri, and the-a/--authenticatevalue (or the credentials taken from the URI) inconfiguration.authenticate.--show-configprinted the same two values to stderr. JSON result files are commonly uploaded as CI artifacts, so the password went with them.Root cause
config_print_to_json()andconfig_print()wrotecfg->uriandcfg->authenticateverbatim.Fix
Two small helpers next to
config_print(), used only in those two functions:redact_credentials():user:pwbecomesuser:***,pwbecomes***. The split is at the first:, the same place where the redis and memcache_binaryauthenticate()split the user off. No credentials still gives"".redact_uri(): the URI userinfo goes throughredact_credentials(), soredis://default:pw@host:port/dbbecomesredis://default:***@host:port/db.parse_uri()now ends the userinfo at the last@inside the authority, through a shareduri_userinfo_end()thatredact_uri()also uses. The authority ends at the first/,?or#after the first@(RFC 3986).@had its tail taken for the host. That tail was printed by--show-configserver = ...and by theinvalid port number '...',Name or service not knownandinvalid IPv6 hosterrors. A raw@in the password now works.@in the db path (redis://u:pw@host:port/1@) givesinvalid database number '1@', unchanged from master.@in a query or fragment does not move the credentials to another host:redis://u:[email protected]:[email protected]:Q(and the#form) givesinvalid port number, unchanged from master./in the password still works, as on master. Known limit, same as master: when a password has an@followed by a/(redis://u:a@b/c@host), it is split at that/. Such passwords need the percent-encoding of --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732.--server/--unix-socket(redis://u:pw@:6379,redis://u:pw@,redis://u:a/b@,redis://:6379, and a stray@after the path such asredis://host:6379/1@): falls back to the default server as on master, but now printswarning: --uri has no host; connecting to the default server localhost:<port>.The warning is keyed on the empty host, so it fires with or without credentials, and it never includes them. No URI that master accepted is rejected.-s myhost --uri redis://default:pw@:6379runs againstmyhost, and-S /tmp/redis.sock --uri redis://default:pw@sends the credentials over the unix socket.@in the path still ends a "userinfo".redis://host:6379/1@other:6379connects tootherwithAUTH host 6379/1, redacted ashost:***, andredis://host:6379/1@sends that AUTH to the default server, now with the host-less warning. Treating a/,?or#before the first@as "no userinfo" would break a raw/in passwords, so this is left to --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732. A test pins the current behaviour.Field names and the "no credentials" value do not change. Apart from the userinfo split and the empty-host warning in
parse_uri(), the diff stays inside the JSON and config-print code.Other places I checked that do not carry the password: text output and
--out-file,--client-statsCSVs,-Ddebug logs, the auth-failure error (it prints only the server's-WRONGPASS ...reply), statsd/graphite (they never seeuri/authenticate), and the Prometheus exporter (already redacted,test_prometheus_redaction.py). URI parse errors no longer echo credentials since #720. memtier has no TLS key passphrase option. The JSONcert/keyfields already hold only basenames.Release notes:
configuration.authenticatenow see***(oruser:***) instead of the credential, andconfiguration.urihas the password replaced by***. Nothing in this repo reads these fields, and I know of no tooling that reads them back to rerun a benchmark. Such tooling would now have to pass-a/--uriagain.--uriwith no-s/-S(redis://user:pw@:6379,redis://user:pw@,redis://:6379,redis://host:6379/1@) still uses the default server, as before, but now prints a one-line warning saying so.--urithat master accepted still runs, including the host-less forms above. The only parsing change is that a password containing@is no longer split at its first@. On master that misparse took the tail of the password for the host. The two errors above (invalid database number,invalid port number) are the same as on master.Test evidence
New
tests/test_config_password_redaction.py(20 tests). Each one setsrequirepass(andmasterauth) to a dummy password on every master and replica, and restores only the nodes it changed. It then checks that no part of the password appears in the JSON file, stdout or stderr, and thaturi/authenticatehold exactly the redacted forms in both the JSON and--show-config. Cases:--uri redis://default:PW@...givesdefault:***--uri redis://PW@.../0gives***-a PWgives***-a default:PWgivesdefault:***-a default:a:PW(a password containing:) givesdefault:***--uri redis://default:HEAD@TAIL@host:portconnects with the passwordHEAD@TAIL, and neither half leaks--uri redis://default:HEAD@TAIL:TAIL2@host:notaportfails withinvalid port number 'notaport'and no password part in the output--uri redis://host:portis printed unchanged, withauthenticate""authenticate""@in the db path,--uri redis://default:PW@host:port/1@, exits with rc 1 andinvalid database number '1@'--uri redis://default:HEAD@TAIL@host:port/x@y, and.../x@wrong/2, are not read as hostyorwrong(rc 1,invalid database number ...)--uri redis://default:PW@host:[email protected]:Dand the#x@form exit with rc 1, and a decoy listener on port D sees no connection/in the password,--uri redis://default:a/PW@host:port, connects and is redacted--uri redis://host:port/[email protected]:Ctargets 127.0.0.1:C withauthenticatehost:***, and-p C --uri redis://host:port/1@warns and falls back to the default server. C is_CLOSED_PORT(19799), a fixed port chosen for this test; it is not a documented reserved range. If the port is busy, the test skips rather than fail. Only the printed configuration is checked.-s/-S,--uri redis://default:PW@:port, print the--uri has no hostwarning and connect to the default server, redacted everywhere. RLTest nodes are on loopback (localhost, or127.0.0.1as the fallback), which is the default server. The test asserts that instead of skipping, so it runs in every cell./in the password with an empty host and a port,--uri redis://default:a/PW@:port, warns, connects to the default server and is redacted-p PORT --uri redis://default:a/PW@(nothing after the@) warns, falls back to the default server (the target), authenticates and is redacted--uri redis://:port(no credentials) warns the same way, andauthenticateis""-s HOST --uri redis://default:PW@:portconnects to HOST (rc 0) and is redacted-S PATH --uri redis://default:PW@tries PATH (nothing listens there, soconnect failed, error = No such file or directory, rc 1), with no URI error and the credentials redacted_run()passes--tls-protocolswhenTLS_PROTOCOLSis set, so the TLS 1.3 cells really force TLS 1.3.The test is also added to the sanitizer TLS "misc" TEST lists (asan.yml and tsan.yml), next to
test_prometheus_redaction.py.@case fails withcfg731-tail-dummy@localhost:...: error: Name or service not known. The bad-port case printsinvalid port number 'cfg731-tail2-dummy@localhost:notaport'. The 5 that pass on master do so by design: the credential-less tests guard against over-redaction, and the stray-@tests guard against splitting past the authority. Master already rejected those URIs. Later tests are not run on master where they would fall back to localhost:6379, which on a shared host is someone else's server.--use-slaves, and standalone TLS withTLS_PROTOCOLS=TLSv1.3. On OSS cluster with--use-slaves, the three changed host-less tests pass (3/3). The full 20-test run in that cell goes over my 290 s local limit on a heavily loaded host; CI runs it.test_closed_std_fds.py(Reopen closed stdin/stdout/stderr on /dev/null at startup #736) passes 23/23 on the rebased branch.Manual repro on master (from the issue):
With the fix:
Fixes #731
Affected versions
"authenticate"in the JSON: introduced by fb6888d "add support for JSON output" (add support for JSON output #18). Affects 1.2.9 through 2.5.2 and master."uri"in the JSON anduri =in--show-config: introduced by 68fb953 "Add URI flag ..." (Add URI flag to memtier_benchmark (compatible with redis-cli and redis-benchmark parsing) #311). Affects 2.2.0 through 2.5.2 and master.🤖 Generated with Claude Code