Repository navigation
Percent-decode the --uri user name and password - #764
Conversation
|
🤖 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
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) |
--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]>
84bfc35 to
e705151
Compare
|
Thanks. Addressed in e705151 (rebased on 82119ef):
|
|
On the latest edit:
|
Problem
--uripassed the userinfo to AUTH verbatim. The RFC 3986 spelling of a reserved character in a password (%40for@,%2Ffor/,%3Afor:) was sent as the literal three characters, so AUTH failed. The--urihelp says the format is compatible with redis-cli, andredis-cli -udecodes these. Since #735 a raw@works, but a password with an@followed by a/still could not be given at all, becauseu:a@b/c@hostis split at the/.Reproduced on current master (afbb514) against an ACL user
uwith passwordp@ssand a uservwithp/s:s:redis://u:p%[email protected]:7000-WRONGPASS, rc=2 after the 30 s connection-stage timeoutredis://v:p%2Fs%[email protected]:7000-WRONGPASS, rc=2redis://w:100%@...(password100%)Root cause
parse_uri()copies the userinfo returned byuri_userinfo_end()straight intocfg->authenticate. It does no decoding.Fix
uri_userinfo_end()splits it (soredact_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.[fe80::1%eth0], which works today.%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%25and does not echo the password. A valid%XXis 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).%00(the credentials are handled as a C string and would be cut short), a decoded:in the user name (AUTHcredentials are split at the first:, so it cannot be represented), and control bytes (0x00-0x1F, 0x7F) in the decoded user name, which--show-configand 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.:(redis://a%3Ab@host) is stored as:a:b, whichauthenticate()already reads as "password only". With-P memcache_binarya password-only URI is still rejected with "credentials must be in the form of USER:PASSWORD" (rc 2), as on master./,?or#in the credentials still works as on master, and now prints an informationalnote:(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-configand--json-out-filestill print the password as***.authenticateshows the decoded user name, andurishows the URI as given with the password redacted.--urihelp, the man page and the README (new "Connecting with--uri" section, including that an IPv6 zone id takes a raw%, since%25is not decoded in the host).Release note
--urinow percent-decodes the user name and password, asredis-cli -udoes. A password that contains a valid%XXsequence (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: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(%00in user/password,%3Aand control bytes%0A/%1F/%7F/%1bin the user name; nothing leaks)..._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_rejectedtest_config_uri_at_in_path_without_credentials_warns. The raw-/password tests also check for the new note.Results (local, redis 8.x):
raw_delimiters_note,hex_and_controlandpercent_decoding_rejectsalso fail on master.password_with_raw_colon,host_not_percent_decodedandmemcache_binary_password_only_rejectedpass on master by design: they guard behaviour master already has and kill mutants of this change.--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.pyandtest_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
--uricredentials are parsed and passed to AUTH; valid%XXsequences now decode (behavior change for some existing URIs), though compatibility warnings and tests cover edge cases.Overview
--urinow percent-decodes the user name and password (matchingredis-cli -u), so encoded characters like%40,%2F, and%3Aare sent to AUTH correctly instead of as literal%XXtext.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 newuri_password_onlyflag.Docs add a README Connecting with
--urisection 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.