Skip to content
This repository was archived by the owner on Nov 17, 2020. It is now read-only.

Commit f3048a9

Browse files
committed
URI decode user and password when parsing
Usernames and passwords in the amqp URI may be URI encoded. Ensure we decode them during URI parse. [#159650732]
1 parent 55f3517 commit f3048a9

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/amqp10_client.erl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,6 @@ parse_uri(Uri) ->
347347
Err -> Err
348348
end.
349349

350-
parse_usertoken(U) ->
351-
[User, Pass] = string:tokens(U, ":"),
352-
{plain, to_binary(User), to_binary(Pass)}.
353-
354350
parse_result({Scheme, UserInfo, Host, Port, "/", Query0}) ->
355351
Query = lists:foldl(fun (W, Acc) ->
356352
[K, V] = string:tokens(W, "="),
@@ -389,6 +385,12 @@ parse_result({Scheme, UserInfo, Host, Port, "/", Query0}) ->
389385
Ret0#{tls_opts => {secure_port, TlsOpts}}
390386
end.
391387

388+
parse_usertoken(U) ->
389+
[User, Pass] = string:tokens(U, ":"),
390+
{plain,
391+
to_binary(http_uri:decode(User)),
392+
to_binary(http_uri:decode(Pass))}.
393+
392394

393395
safe_substr(Str, Start) when length(Str) >= Start ->
394396
string:substr(Str, Start);
@@ -454,6 +456,12 @@ parse_uri_test_() ->
454456
sasl => {plain, <<"fred">>, <<"passw">>}}},
455457
parse_uri("amqps://fred:passw@my_proxy:9876?sasl=plain&" ++
456458
"hostname=my_host&max_frame_size=512&idle_time_out=60000")),
459+
%% ensure URI encoded usernames and passwords are decodeded
460+
?_assertEqual({ok, #{address => "my_proxy",
461+
port => 9876,
462+
hostname => <<"my_proxy">>,
463+
sasl => {plain, <<"fr/ed">>, <<"pa/ssw">>}}},
464+
parse_uri("amqp://fr%2Fed:pa%2Fssw@my_proxy:9876")),
457465
%% make sasl plain implicit when username and password is present
458466
?_assertEqual({ok, #{address => "my_proxy",
459467
port => 9876,

0 commit comments

Comments
 (0)