Skip to content

Percent-decode the --uri user name and password - #764

Merged
fcostaoliveira merged 2 commits into
masterfrom
fix/732-uri-percent-decoding
Oct 17, 2026
Merged

fcostaoliveira merged 2 commits into
masterfrom
fix/732-uri-percent-decoding

Conversation

@fcostaoliveira

@fcostaoliveira fcostaoliveira commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

--uri passed the userinfo to AUTH verbatim. The RFC 3986 spelling of a reserved character in a password (%40 for @, %2F for /, %3A for :) was sent as the literal three characters, so AUTH failed. The --uri help says the format is compatible with redis-cli, and redis-cli -u decodes these. Since #735 a raw @ works, but a password with an @ followed by a / still could not be given at all, because u:a@b/c@host is split at the /.

Reproduced on current master (afbb514) against an ACL user u with password p@ss and a user v with p/s:s:

URI master this PR
redis://u:p%[email protected]:7000 -WRONGPASS, rc=2 after the 30 s connection-stage timeout runs, rc=0
redis://v:p%2Fs%[email protected]:7000 -WRONGPASS, rc=2 runs, rc=0
redis://w:100%@... (password 100%) runs runs, with a warning

Root cause

parse_uri() copies the userinfo returned by uri_userinfo_end() straight into cfg->authenticate. It does no decoding.

Fix

  • The userinfo is still split where uri_userinfo_end() splits it (so redact_uri() and parsing stay in step), then at the first raw :. The user name and password are decoded only after that, so encoded @, /, :, ?, # end up in the password.
  • Only the userinfo is decoded, as in redis-cli. The port and db number are digits only, and decoding the host would change a raw IPv6 zone id such as [fe80::1%eth0], which works today.
  • Compatibility rule: a % that is not followed by two hex digits (100%, %4, %G1) is kept as a literal % with a warning instead of being rejected. redis-cli rejects it, but master accepted these passwords, and in the spirit of Fix issue #211. Allow key_stddev and key_median options to be set values #212/Redact the password in --json-out-file and --show-config #735 an existing working URI should not start failing. The warning says to write %25 and does not echo the password. A valid %XX is now decoded. That is the intended change, and it is the one case where the meaning of an existing URI changes (documented in the README).
  • Rejected, without echoing the value: %00 (the credentials are handled as a C string and would be cut short), a decoded : in the user name (AUTH credentials are split at the first :, so it cannot be represented), and control bytes (0x00-0x1F, 0x7F) in the decoded user name, which --show-config and the JSON print. Redis rejects such user names anyway. The password may still hold them, since AUTH is length-prefixed and the password is never printed.
  • A password-only userinfo that decodes to a : (redis://a%3Ab@host) is stored as :a:b, which authenticate() already reads as "password only". With -P memcache_binary a password-only URI is still rejected with "credentials must be in the form of USER:PASSWORD" (rc 2), as on master.
  • A raw /, ? or # in the credentials still works as on master, and now prints an informational note: (base64-style passwords often contain /). It says the URI is accepted and to percent-encode (%2F/%3F/%23) if the password is not recognised, and that without credentials an @ after a / is read as the credentials separator. It never echoes the value. This replaces the Redact the password in --json-out-file and --show-config #735 known limit for the credential-less @ in the path (redis://host:6379/1@other:6379), which is now reported instead of passing silently.
  • --show-config and --json-out-file still print the password as ***. authenticate shows the decoded user name, and uri shows the URI as given with the password redacted.
  • Updated the --uri help, the man page and the README (new "Connecting with --uri" section, including that an IPv6 zone id takes a raw %, since %25 is not decoded in the host).

Release note

  • --uri now percent-decodes the user name and password, as redis-cli -u does. A password that contains a valid %XX sequence (for example a literal %41) is now sent decoded: write its % as %25. Otherwise AUTH fails with -WRONGPASS. A % not followed by two hex digits is still taken literally, with a warning.

Tests

tests/test_config_password_redaction.py:

  • new: test_config_uri_percent_decoded_password (%40%2f%3A, including the @-then-/ form), ..._percent_decoded_user, ..._percent_decoded_password_only_with_colon, ..._percent_encoded_percent (%25), ..._literal_percent_kept_with_warning (%, %4, %G1, %zz), ..._percent_decoding_rejects (%00 in user/password, %3A and control bytes %0A/%1F/%7F/%1b in the user name; nothing leaks)
  • added after review: ..._raw_delimiters_note (?, #, password-only raw /), ..._password_with_raw_colon (default:a:b), ..._percent_decoded_password_hex_and_control (%09%39%46%66%7F%7f), ..._host_not_percent_decoded ([::1%lo] and [::1%25lo], server = unchanged), ..._memcache_binary_password_only_rejected
  • flipped: the Redact the password in --json-out-file and --show-config #735 known-limit test (pinned until --uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40) #732) is now test_config_uri_at_in_path_without_credentials_warns. The raw-/ password tests also check for the new note.
  • every new test checks that neither the decoded nor the encoded password appears in the JSON, stdout or stderr. Dummy passwords only.

Results (local, redis 8.x):

  • master binary (afbb514): 9 of 26 failed, all of them the new or flipped tests. At 82119ef the post-review tests raw_delimiters_note, hex_and_control and percent_decoding_rejects also fail on master. password_with_raw_colon, host_not_percent_decoded and memcache_binary_password_only_rejected pass on master by design: they guard behaviour master already has and kill mutants of this change.
  • this PR (rebased on 82119ef), --env oss: 31/31 passed in 5 of 5 runs. --env oss-cluster --shards-count 3: 31/31. --env oss --tls: 31/31.
  • test_cli_validation_ports.py and test_uri_database_number: 9/9.

Fixes #732

Affected versions

2.2.0 through 2.5.2 (latest) and master. The missing decoding dates from 68fb953 "Add URI flag to memtier_benchmark" (#311), first released in 2.2.0. No release has ever decoded the userinfo. Reproduced on master afbb514.

🤖 Generated with Claude Code


Note

Medium Risk
Changes how --uri credentials are parsed and passed to AUTH; valid %XX sequences now decode (behavior change for some existing URIs), though compatibility warnings and tests cover edge cases.

Overview
--uri now percent-decodes the user name and password (matching redis-cli -u), so encoded characters like %40, %2F, and %3A are sent to AUTH correctly instead of as literal %XX text.

Decoding applies only to userinfo; host, port, and DB are unchanged (e.g. IPv6 zone ids with a raw % still work). Invalid %00, : in the decoded user name, and control characters in the user name are rejected without leaking credentials. A lone % without two hex digits stays literal with a warning; raw /, ?, or # in credentials still work but get a note to use %2F / %3F / %23. Password-only URIs that decode to : are handled for memcache_binary validation via a new uri_password_only flag.

Docs add a README Connecting with --uri section and update --help, the man page, and password-redaction tests for decode, warnings, and rejection cases.

Reviewed by Cursor Bugbot for commit e705151. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Oct 17, 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 decoding and the tests, and only have a couple of comments.

The overall approach looks right to me. Splitting at uri_userinfo_end() and the first raw : before decoding means %40/%2F/%3A all land in the password, and leaving the host alone keeps [fe80::1%eth0] working. Keeping a malformed % literal with a warning, where redis-cli would reject it, is the same less-breaking choice as #212, and I think that's the right call. The leading-: trick for a password-only userinfo that decodes to a : matches what redis_protocol::authenticate() already does, and it's good that uri_password_only keeps the memcache_binary check failing as it does on master. The tests fail on master (9/26) and pass with the fix, which is what I'd want for a change like this.

  • Valid %XX now being decoded is the one real semantic change, and you've documented it. I agree it's justified, since --help already promised redis-cli compatibility. Still, someone whose password has a literal %41 in it will now just get -WRONGPASS after the connection-stage timeout, with nothing pointing them to the decoding. Did you consider printing a hint on an AUTH failure when the URI userinfo had a decoded %XX in it? Even a line in the release notes would probably be enough.
  • The raw //?/# note fires on every run for any password with a / in it, and that's common for base64-style generated passwords. I wonder if that's too chatty as a default, since those users can't do anything wrong here unless an @ comes before the /. Could it only fire when there's no : in the userinfo, or when the userinfo contains an @? Those are the shapes that can actually be the credential-less host:port/1@other case. I may be missing a case where the narrower check gives the wrong answer, though.

The core fix looks solid. I'd just like to hear your take on the warning noise before this merges.

(would file this as a comment, not a formal block)

fcostaoliveira and others added 2 commits October 17, 2026 05:03
--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]>
- Reword the raw '/', '?', '#' message as an informational note: it
  fires for working base64-style passwords, so it now says the URI is
  accepted and when to percent-encode, and that without credentials an
  '@' after a '/' is read as the credentials separator.
- Reject control bytes in the decoded user name, which --show-config
  and the JSON print; an ASCII-only URI could otherwise inject log
  lines. The password may still hold them (AUTH is length-prefixed and
  the password is never printed).
- Keep the memcache_binary USER:PASSWORD check for a password-only URI
  whose password decodes to a ':' (stored behind a leading ':'), so it
  fails as on master.
- Help, man page and README: %3A only in the password; an IPv6 zone id
  takes a raw '%', since the host is not decoded.
- Tests for the above, a raw '%' and %25 in a bracketed host, %09 and
  every hex digit class in the password, the note for '?', '#' and a
  password-only raw '/', and a raw ':' in the password.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fcostaoliveira
fcostaoliveira force-pushed the fix/732-uri-percent-decoding branch from 84bfc35 to e705151 Compare October 17, 2026 04:17
@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

Thanks. Addressed in e705151 (rebased on 82119ef):

  • %XX compat: agreed, this is the one intended change of meaning. The README's "Connecting with --uri" section documents it, and the PR description now has a release-note bullet saying a valid %XX in an existing password must be written with %25, since otherwise the user only sees -WRONGPASS.
  • Raw /, ?, # message: reworded as an informational note that says nothing is wrong: note: --uri credentials contain a raw '/', '?' or '#'; this is accepted, but if the password is not being recognised, percent-encode them (%2F, %3F, %23). Without credentials, an '@' after a '/', '?' or '#' is read as the credentials separator. It never echoes the value.
  • Control bytes in the user name: the JSON escapes them, but --show-config on stderr did not, so an ASCII-only URI such as %0A could inject a line there. Control bytes (0x00-0x1F, 0x7F) in the decoded user name are now rejected with error: --uri user name contains a control character., which doesn't echo the value. Redis rejects such user names anyway. They are still allowed in the password, since AUTH is length-prefixed and the password is never printed. Covered by test_config_uri_percent_decoding_rejects (%0A, %1F, %7F, %1b), with %09 in the password covered by ..._hex_and_control.

@fcostaoliveira

Copy link
Copy Markdown
Collaborator Author

On the latest edit:

  • The valid %XX change and remedy are already in the README and release notes: a password containing literal %41 must use %2541. Keeping that migration advice there avoids adding URI-specific state to connection/auth failure handling in this parser fix.
  • I considered narrowing the informational note, but neither suggested predicate reliably identifies the ambiguous case. redis://host:1234/1@other:1234 has a colon in the parsed userinfo and no embedded @, exactly like a legitimate user:password/part@host credential. Restricting the note to no-colon or embedded-@ userinfo would suppress it for that potentially retargeted URI. We therefore keep the one-time note: for raw /, ?, #, explicitly say the input is accepted, and never echo credentials. This intentionally trades one informational line on base64-style passwords for surfacing an ambiguity we cannot safely resolve without breaking those passwords. Percent-encoding removes the note.

@fcostaoliveira
fcostaoliveira merged commit f8b739c into master Oct 17, 2026
129 checks passed
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.

--uri does not percent-decode the user/password, so a password containing '@' cannot be given (redis-cli -u accepts %40)

1 participant