Skip to content

Redact the password in --json-out-file and --show-config - #735

Merged
fcostaoliveira merged 9 commits into
masterfrom
fix/731-redact-password
Oct 17, 2026
Merged

fcostaoliveira merged 9 commits into
masterfrom
fix/731-redact-password

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

--json-out-file wrote the server password in clear text: the full --uri (with user:password@) in configuration.uri, and the -a/--authenticate value (or the credentials taken from the URI) in configuration.authenticate. --show-config printed 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() and config_print() wrote cfg->uri and cfg->authenticate verbatim.

Fix

Two small helpers next to config_print(), used only in those two functions:

  • redact_credentials(): user:pw becomes user:***, pw becomes ***. The split is at the first :, the same place where the redis and memcache_binary authenticate() split the user off. No credentials still gives "".
  • redact_uri(): the URI userinfo goes through redact_credentials(), so redis://default:pw@host:port/db becomes redis://default:***@host:port/db.
  • parse_uri() now ends the userinfo at the last @ inside the authority, through a shared uri_userinfo_end() that redact_uri() also uses. The authority ends at the first /, ? or # after the first @ (RFC 3986).
    • Before, a password containing @ had its tail taken for the host. That tail was printed by --show-config server = ... and by the invalid port number '...', Name or service not known and invalid IPv6 host errors. A raw @ in the password now works.
    • With a host present, a stray @ in the db path (redis://u:pw@host:port/1@) gives invalid database number '1@', unchanged from master.
    • An @ in a query or fragment does not move the credentials to another host: redis://u:[email protected]:[email protected]:Q (and the # form) gives invalid port number, unchanged from master.
    • A raw / 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.
    • Empty host, with no --server/--unix-socket (redis://u:pw@:6379, redis://u:pw@, redis://u:a/b@, redis://:6379, and a stray @ after the path such as redis://host:6379/1@): falls back to the default server as on master, but now prints warning: --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.
    • With an explicit target the host-less URI works as on master, with no warning: -s myhost --uri redis://default:pw@:6379 runs against myhost, and -S /tmp/redis.sock --uri redis://default:pw@ sends the credentials over the unix socket.
    • Known limit, same as master: without credentials, an @ in the path still ends a "userinfo". redis://host:6379/1@other:6379 connects to other with AUTH host 6379/1, redacted as host:***, and redis://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.
    • Percent-decoding is left to --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732.

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-stats CSVs, -D debug logs, the auth-failure error (it prints only the server's -WRONGPASS ... reply), statsd/graphite (they never see uri/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 JSON cert/key fields already hold only basenames.

Release notes:

  • JSON consumers that read configuration.authenticate now see *** (or user:***) instead of the credential, and configuration.uri has 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/--uri again.
  • A host-less --uri with 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.
  • No new rejections. Every --uri that 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 sets requirepass (and masterauth) 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 that uri/authenticate hold exactly the redacted forms in both the JSON and --show-config. Cases:

  • --uri redis://default:PW@... gives default:***
  • --uri redis://PW@.../0 gives ***
  • -a PW gives ***
  • -a default:PW gives default:***
  • -a default:a:PW (a password containing :) gives default:***
  • --uri redis://default:HEAD@TAIL@host:port connects with the password HEAD@TAIL, and neither half leaks
  • --uri redis://default:HEAD@TAIL:TAIL2@host:notaport fails with invalid port number 'notaport' and no password part in the output
  • a credential-less --uri redis://host:port is printed unchanged, with authenticate ""
  • no credentials at all gives authenticate ""
  • a stray @ in the db path, --uri redis://default:PW@host:port/1@, exits with rc 1 and invalid database number '1@'
  • --uri redis://default:HEAD@TAIL@host:port/x@y, and .../x@wrong/2, are not read as host y or wrong (rc 1, invalid database number ...)
  • --uri redis://default:PW@host:[email protected]:D and the #x@ form exit with rc 1, and a decoy listener on port D sees no connection
  • a raw / in the password, --uri redis://default:a/PW@host:port, connects and is redacted
  • known limit, pinned until --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732: --uri redis://host:port/[email protected]:C targets 127.0.0.1:C with authenticate host:***, 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.
  • credentials with an empty host and no -s/-S, --uri redis://default:PW@:port, print the --uri has no host warning and connect to the default server, redacted everywhere. RLTest nodes are on loopback (localhost, or 127.0.0.1 as the fallback), which is the default server. The test asserts that instead of skipping, so it runs in every cell.
  • a raw / 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, and authenticate is ""
  • -s HOST --uri redis://default:PW@:port connects to HOST (rc 0) and is redacted
  • -S PATH --uri redis://default:PW@ tries PATH (nothing listens there, so connect failed, error = No such file or directory, rc 1), with no URI error and the credentials redacted

_run() passes --tls-protocols when TLS_PROTOCOLS is 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.

  • origin/master 193f6a8 (14 tests at that point): 9 of 14 fail. Every credential case leaks. The @ case fails with cfg731-tail-dummy@localhost:...: error: Name or service not known. The bad-port case prints invalid 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.
  • Earlier heads of this PR rejected some host-less forms; 184a1c7 removed every such rejection, and the tests now expect warn-and-fallback. Separately, 95ce587 failed the query/fragment test (it connected to the decoy).
  • With the fix (184a1c7, rebased on 63c0009 / Reopen closed stdin/stdout/stderr on /dev/null at startup #736): 20/20 in 5/5 runs on OSS standalone, and 20/20 on each of OSS cluster (3 shards), standalone with --use-slaves, and standalone TLS with TLS_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):

u.json:  ,"uri": "redis://default:[email protected]:19700"
u.json:  ,"authenticate": "default:dummypw731"
u.err:   uri = redis://default:[email protected]:19700

With the fix:

,"uri": "redis://default:***@127.0.0.1:19700"
,"authenticate": "default:***"
uri = redis://default:***@127.0.0.1:19700
authenticate = default:***

Fixes #731

Affected versions

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

🤖 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. redact_credentials() / redact_uri() only run when the config is printed, so they don't touch the hot path. The field names and the "" value for "no credentials" stay the same. The test was shown to fail on master (9 of 14 at that point) and passes with the fix, which is the same bar test_json_output_integrity.py met in PR#364. A few comments:

  1. The PR description is behind the final commit. The body still says "The only new rejection is ... error: missing host in URI." Both the "Release notes" and "Test evidence" sections still list redis://host:6379/1@ and redis://u:a/b@ as rejected. 184a1c7 changed both to warn and fall back, and the commit message now says "This PR now rejects no URI that master accepted." Could you update the body so whoever writes the release notes doesn't copy the old text?

  2. Backward compatibility of configuration.authenticate / configuration.uri. This is a content change to existing JSON keys, and it's disclosed. I don't see a less-breaking design that still keeps the secret out of CI artifacts, and keeping the key names was the compatible choice. So I'm fine with it as is, just noting that it was weighed rather than only disclosed (PR#60 / PR#212 are the precedents here).

  3. Scope. The title says redaction, but the diff also changes where parse_uri() splits the userinfo (last @ inside the authority instead of the first @) and adds a new stderr warning for a host-less --uri. The reasoning holds up: the tail of the password was showing up in server = ... and in host/port errors. Still, it's a change in parsing behaviour that someone running git log won't expect from this title. Did you consider splitting the uri_userinfo_end() change into its own commit or PR, or at least saying so in the title? I'll leave that to you.

  4. test_config_uri_at_in_path_without_credentials_known_limit pins behaviour we know is wrong: redis://host:port/1@other:port sends AUTH host port/1 to other. I see why you want it pinned until --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732. I just wonder if it's worth a short # TODO(#732): flip this in the test, so whoever fixes --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732 knows the failure is expected and doesn't "fix" the test back.

  5. Just checking: _CLOSED_PORT = 19799 is described as being in "the range reserved for these tests". Is that range documented anywhere in tests/, or is it a convention you picked here? If another test ever listens on it, the test skips quietly instead of failing. That's safe, but it could hide lost coverage.

  6. Nitpicking: the warning hardcodes localhost in the format string, while config_init_defaults() is what actually picks the default. They match today. A shared constant would keep them from drifting apart, but that's optional.

I traced uri_userinfo_end() by hand: no @, @ as the last character, and @ right before //?/#. The backward walk always stops at the first @, so I don't see an unbounded loop or an off-by-one. parse_uri() runs after option parsing, so -s / -S are set no matter where they appear on the command line, as the new comment says. The URI-parsing half might be worth a second look from whoever owns the --uri code (#720 / #732).

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.)

@fcostaoliveira
fcostaoliveira force-pushed the fix/731-redact-password branch from 84d94f8 to 95ce587 Compare October 16, 2026 20:15
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. On the replica-discovery nit: RLTest starts every node on loopback, so the ip that INFO replication reports is always reachable from the test host. RLTest also has no getSlaveNodesList, so INFO replication is the only way to find replicas in both standalone --use-slaves and cluster --use-slaves. Both topologies pass. If a replica ever can't be reached, the test fails loudly at CONFIG SET. It doesn't hang or skip it silently. I've left it as is.

About "no URI that worked before parses differently": there was one counterexample. With a stray @ in the db path (redis://u:pw@host:port/1@), a whole-string strrchr produced an empty host, and the run fell back to the default server. 95ce587 fixes that. The search for @ now stops at the authority, which ends at the first / after the first @ (RFC 3986). Credentials followed by an empty host are now rejected. Both cases have tests.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread memtier_benchmark.cpp Resolved
@fcostaoliveira
fcostaoliveira force-pushed the fix/731-redact-password branch from 95ce587 to 6bb1195 Compare October 16, 2026 20:54
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. Answers to the points in the first-pass review, as of 6bb1195:

  • PR description: updated. It describes uri_userinfo_end() (the authority now ends at /, ? or #) and the new error, and the release note covers both.
  • Host-less form: I'm not aware of anyone writing redis://user:pw@:6379 or redis://pw@/0 on purpose to mean localhost. The README and --help document redis://user:password@host:port/dbnum, and the host-less form only worked because an empty host fell back to the default. I kept it as an error rather than a warning, because a warning still runs the benchmark against a server the user may not have meant. It is in the release note, and redis://user:pw@localhost:6379 is the explicit spelling.
  • '@' followed by '/' in the password: right. redis://u:a@b/c@host:6379 is still split at the /, the same as on master, and the db error then echoes c. The comment above uri_userinfo_end() now says this and points to --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732, since such a password needs percent-encoding. A raw / with no @ before it in the password still works, and test_config_password_redaction_uri_password_with_slash now covers that.
  • Downstream readers: nothing in this repo reads configuration.authenticate or configuration.uri, and I know of no tooling that reads them back to rerun a benchmark. Anything that did was reusing a credential from a results file, and now has to pass -a/--uri again.
  • _requirepass() except branch: it now has a comment explaining why only masterauth is restored there: requirepass never changed on that node.

@fcostaoliveira
fcostaoliveira force-pushed the fix/731-redact-password branch from 6bb1195 to 1be5463 Compare October 16, 2026 21:40
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. Point by point, as of 1be5463:

  1. Credential-less @ in the path: you're right. That case is pre-existing and the same as master.
  2. redact_uri(): it now has a note that it assumes a URI parse_uri() has already validated, and that the no-:// fallback is only a guard.
  3. Release note: the PR description has it under "Release notes". URIs with an @ and an empty host after it (redis://user:pw@:6379, redis://pw@/0, redis://host:6379/1@) now exit with rc 1 and error: missing host in URI. instead of running against the default server. It also gives the explicit spelling to use instead. The description also covers the parse_uri scope (last-@ split, /?# authority end, empty-host check).

@fcostaoliveira
fcostaoliveira force-pushed the fix/731-redact-password branch from 1be5463 to 626ae59 Compare October 16, 2026 22:33
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. Point by point, as of 626ae59:

  1. --server/--unix-socket with a host-less --uri: agreed, the check was too broad. It now fires only when the host is empty and neither --server nor --unix-socket was given, which is the only case that fell back to the default server. parse_uri() runs before config_init_defaults(), so a non-NULL server or unix_socket at that point can only come from the command line, and no extra flag is needed.
    • -s myhost --uri redis://default:pw@:6379 runs against myhost again. test_config_uri_without_host_uses_explicit_server covers it: rc 0, credentials redacted.
    • -S /path.sock --uri redis://default:pw@ goes to the socket again. test_config_uri_without_host_uses_explicit_unix_socket covers it: it reaches the socket, not a URI error, and the credentials are redacted.
    • With neither option, the URI is still rejected.
    • The release note now says the rejection applies only without -s/-S, and that the host-less form with -s/-S works as before.
  2. JSON value change: thanks for checking. Nothing more to add.
  3. Author identity: that was a local slip. The commit is re-authored, and all six commits are now fcostaoliveira <[email protected]>. The tree is unchanged.
  4. Comment length: I kept the "Known limits" lines in the code. They sit next to the split they describe, which is where the next person editing it will look, and each one points to --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732.

@fcostaoliveira
fcostaoliveira force-pushed the fix/731-redact-password branch from 626ae59 to a87bd79 Compare October 16, 2026 23:19
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. I followed both of your suggestions, as of a87bd79:

  • Keep the fallback and warn: redis://user:pw@:6379 and redis://user:pw@, with no -s/-S, connect to the default server as on master. They now also print warning: --uri has no host; connecting to the default server localhost:<port>. The warning never includes the credentials. Input that used to work keeps working, per the reasoning in PR#212.
  • Reject only the stray @ after the path: an empty host where the "credentials" contain /, ? or # (redis://host:6379/1@) still gives error: missing host in URI. That URI never worked meaningfully: it sent AUTH host 6379/1 to the default server. This is now the only new rejection, and the release note says so. With -s/-S given, nothing changes from master.
  • Tests: test_config_uri_credentials_without_host_warns_and_uses_default checks the warning, that the run reaches the default server, and that the credentials are redacted in the JSON, stdout and stderr. test_config_uri_at_in_path_without_credentials_known_limit still checks that redis://host:port/1@ is rejected.
  • Splitting out the parse_uri() changes: I'd rather keep them here. The last-@ split and the /?# authority end are what stop the password tail from being echoed as the host, in --show-config server = ... and in the port and host errors. That makes them part of the --json-out-file writes the server password in clear text (configuration.uri and configuration.authenticate) #731 leak. What remains of the empty-host change is a warning plus rejecting a URI that never worked. A maintainer can still ask for a split.

@fcostaoliveira
fcostaoliveira force-pushed the fix/731-redact-password branch from a87bd79 to 7c22f34 Compare October 17, 2026 00:05
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. Point by point, as of 7c22f34:

  1. PR body: my a87bd79 edit had gone through (gh pr view 735 --json body shows it), so I think you read an earlier copy. I've gone through the whole body again for 7c22f34. The Fix bullets, the release notes and the test evidence all describe the current behaviour: a host-less --uri with no -s/-S warns and uses the default server, and the only new rejection is a stray @ after the path with nothing following it.
  2. Raw / in the password with an empty host: good catch. The check no longer rejects that. It now rejects only when nothing at all follows the @ and the userinfo contains /, ? or #, which is the exact shape of redis://host:6379/1@. redis://u:a/b@:6379 warns and falls back like the other host-less forms (test_config_uri_password_with_slash_without_host_warns). redis://u:a/b@ has the same shape as the stray-@ case and can't be told apart from it without --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732's percent-encoding. So it stays rejected; this is an explicit decision, documented in the code comment and the release note, and pinned by test_config_uri_password_with_slash_nothing_after_at_rejected.
  3. Does the warn test run? It did run before, but it no longer depends on that. RLTest's standalone and cluster shards report their host as localhost (redis_std.getMasterNodesList), so host != "localhost" was false and the test ran. That is also why it passed in every local cell. The 127.0.0.1 fallback in _target() only applies when RLTest gives no host. Now the test accepts either loopback name and asserts it instead of skipping, so a non-loopback target makes it fail loudly rather than skip silently. The default server, localhost, is the test target in every cell.
  4. Consistency: the warning now keys on the empty host, not on @. redis://:6379 warns the same way as redis://u:pw@:6379, covered by test_config_uri_without_host_or_credentials_warns.

Local runs at 7c22f34: 20/20 in 5/5 runs on OSS standalone, and 20/20 on OSS cluster, standalone with --use-slaves, and standalone TLS 1.3. On cluster with --use-slaves, I ran the four host-less tests (4/4).

fcostaoliveira and others added 8 commits October 17, 2026 01:38
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]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/731-redact-password branch from 7c22f34 to 184a1c7 Compare October 17, 2026 00:48
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. Point by point, as of 184a1c7 (rebased on #736):

  1. Rejection vs warning: done. The last rejection is gone. redis://u:a/b@ and a stray @ after the path (redis://host:6379/1@) now print the same host-less warning (warning: --uri has no host; connecting to the default server localhost:<port>.) and fall back to the default server, as on master. missing host in URI no longer exists, so this PR rejects no URI that master accepted. The stray-@ form only ever sent a meaningless AUTH, and telling it apart from a raw / in a password is --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732's job. The tests now check warn-and-fallback with the credentials redacted, and the release notes say there are no new rejections.
  2. parse_uri() split vs --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732: you're right to flag it, and I've coordinated it with --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732. The split here (the last @ inside the authority, where the authority ends at the first /, ? or # after the first @) goes through uri_userinfo_end(). Both parse_uri() and redact_uri() use it, so --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732 should build its percent-decoding on that same helper rather than adding a second way to split the userinfo. The known limits listed in the code comment (an @ followed by / in a password, and a credential-less @ in the path) are exactly the cases --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732 resolves.
  3. Port reuse in the known-limit test: fixed. The test no longer binds and releases an ephemeral port. It uses a fixed port in the range reserved for these tests (19799), skips if something is listening there, and checks only the printed configuration, so a busy runner can't make it flaky. The fallback part uses -p to stay off localhost:6379.

The branch is rebased on 63c0009 (#736). The workflow conflict was the TEST lists, and I resolved it by keeping test_closed_std_fds.py and adding this test next to test_prometheus_redaction.py. test_closed_std_fds.py passes 23/23 on the rebased branch.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. Point by point, as of 184a1c7. I've only edited the description this round; there is no code change.

  1. Description: I think you read a copy from before my 00:49 edit. The live body already said "No new rejections" and listed redis://host:6379/1@ and redis://u:a/b@ as warn-and-fallback. I've gone through it again anyway. It no longer mentions missing host in URI at all. The Release notes now open with No new rejections: every --uri that master accepted still runs. The only two URI errors left (invalid database number, invalid port number) are named as unchanged from master.
  2. JSON compatibility: agreed, thanks for weighing it.
  3. Scope: the userinfo split stays in this PR because it is part of closing the leak. With the first-@ split, the tail of a password containing @ was printed as server = ... and in the host and port errors, so redacting uri/authenticate alone would still leak it. It is coordinated with --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732: I noted on --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732 (--uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732 (comment)) that its percent-decoding should build on the shared uri_userinfo_end() helper, so parsing and redaction keep splitting in the same place. I'm leaving the commit and title as they are so CI stays green. The description's Fix section spells out the parsing change, and a maintainer can retitle at squash time, e.g. "... and split --uri userinfo at the last @".
  4. TODO(#732) on the known-limit test: good idea. Rather than push now and re-run CI, I'll add # TODO(#732): flip this with the --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732 change, which is the change that flips the expectation. The docstring already says "pinned until --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732".
  5. _CLOSED_PORT = 19799: it's a fixed port chosen for this test, not a documented reserved range in tests/, and the description now says so. If something is listening there, the test skips rather than fail, and only the printed-configuration checks are lost. The connect itself is never asserted. I can make the skip message name the port in a follow-up.
  6. Hard-coded localhost in the warning: acknowledged. They match config_init_defaults() today. A shared constant is a reasonable optional cleanup, which I'd leave for a follow-up so this PR stays small.

@fcostaoliveira
fcostaoliveira merged commit 7e107ff into master Oct 17, 2026
129 checks passed
fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
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]>
fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
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]>
fcostaoliveira added a commit that referenced this pull request Oct 17, 2026
--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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--json-out-file writes the server password in clear text (configuration.uri and configuration.authenticate)

1 participant