You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2021/05/04 21:04:06 UTC

[couchdb] branch 3.x updated: Fix bug in Replicator authentication for password contains @

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch 3.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/3.x by this push:
     new f672b91  Fix bug in Replicator authentication for password contains @
f672b91 is described below

commit f672b911db19981a81d7fc6ce8ac33b150234fd7
Author: Jiahui Li <54...@users.noreply.github.com>
AuthorDate: Tue May 4 09:39:50 2021 -0500

    Fix bug in Replicator authentication for password contains @
---
 .../src/couch_replicator_auth_session.erl          | 54 +++++++++++++++++++++-
 1 file changed, 53 insertions(+), 1 deletion(-)

diff --git a/src/couch_replicator/src/couch_replicator_auth_session.erl b/src/couch_replicator/src/couch_replicator_auth_session.erl
index 30f499a..8daa7bc 100644
--- a/src/couch_replicator/src/couch_replicator_auth_session.erl
+++ b/src/couch_replicator/src/couch_replicator_auth_session.erl
@@ -288,7 +288,9 @@ extract_creds_from_url(Url) ->
             Prefix = lists:concat([Proto, "://", User, ":", Pass, "@"]),
             Suffix = lists:sublist(Url, length(Prefix) + 1, length(Url) + 1),
             NoCreds = lists:concat([Proto, "://", Suffix]),
-            {ok, User, Pass, NoCreds}
+            User1 = chttpd:unquote(User),
+            Pass1 = chttpd:unquote(Pass),
+            {ok, User1, Pass1, NoCreds}
     end.
 
 
@@ -576,14 +578,38 @@ extract_creds_success_test_() ->
             {"u", "p", #httpdb{url = "http://x.y/db"}}
         },
         {
+            #httpdb{url = "http://u%40:p%40@x.y/db"},
+            {"u@", "p@", #httpdb{url = "http://x.y/db"}}
+        },
+        {
+            #httpdb{url = "http://u%40u:p%40p@x.y/db"},
+            {"u@u", "p@p", #httpdb{url = "http://x.y/db"}}
+        },
+        {
+            #httpdb{url = "http://u%40%401:p%40%401@x.y/db"},
+            {"u@@1", "p@@1", #httpdb{url = "http://x.y/db"}}
+        },
+        {
+            #httpdb{url = "http://u%40%2540:p%40%2540@x.y/db"},
+            {"u@%40", "p@%40", #httpdb{url = "http://x.y/db"}}
+        },
+        {
             #httpdb{url = "http://u:p@h:80/db"},
             {"u", "p", #httpdb{url = "http://h:80/db"}}
         },
         {
+            #httpdb{url = "http://u%3A:p%3A@h:80/db"},
+            {"u:", "p:", #httpdb{url = "http://h:80/db"}}
+        },
+        {
             #httpdb{url = "https://u:p@h/db"},
             {"u", "p", #httpdb{url = "https://h/db"}}
         },
         {
+            #httpdb{url = "https://u%2F:p%2F@h/db"},
+            {"u/", "p/", #httpdb{url = "https://h/db"}}
+        },
+        {
             #httpdb{url = "http://u:p@127.0.0.1:5984/db"},
             {"u", "p", #httpdb{url = "http://127.0.0.1:5984/db"}}
         },
@@ -596,10 +622,18 @@ extract_creds_success_test_() ->
             {"u", "p", #httpdb{url = "http://[2001:db8:a1b:12f9::1]:81/db"}}
         },
         {
+            #httpdb{url = "http://u:p%3A%2F%5B%5D%40@[2001:db8:a1b:12f9::1]:81/db"},
+            {"u", "p:/[]@", #httpdb{url = "http://[2001:db8:a1b:12f9::1]:81/db"}}
+        },
+        {
             #httpdb{url = "http://u:p@x.y/db/other?query=Z&query=w"},
             {"u", "p", #httpdb{url = "http://x.y/db/other?query=Z&query=w"}}
         },
         {
+            #httpdb{url = "http://u:p%3F@x.y/db/other?query=Z&query=w"},
+            {"u", "p?", #httpdb{url = "http://x.y/db/other?query=Z&query=w"}}
+        },
+        {
             #httpdb{
                 url = "http://h/db",
                 headers = DefaultHeaders ++ [
@@ -612,6 +646,24 @@ extract_creds_success_test_() ->
             #httpdb{
                 url = "http://h/db",
                 headers = DefaultHeaders ++ [
+                    {"Authorization", "Basic " ++ b64creds("u", "p@")}
+                ]
+            },
+            {"u", "p@", #httpdb{url = "http://h/db"}}
+        },
+        {
+            #httpdb{
+                url = "http://h/db",
+                headers = DefaultHeaders ++ [
+                    {"Authorization", "Basic " ++ b64creds("u", "p@%40")}
+                ]
+            },
+            {"u", "p@%40", #httpdb{url = "http://h/db"}}
+        },
+        {
+            #httpdb{
+                url = "http://h/db",
+                headers = DefaultHeaders ++ [
                     {"aUthoriZation", "bASIC " ++ b64creds("U", "p")}
                 ]
             },