hackney icon indicating copy to clipboard operation
hackney copied to clipboard

Incorrect URL parsing when path is not set and query contains `/` character

Open akash-akya opened this issue 3 years ago • 2 comments

Hackney fails with nxdomain when the URL does not have path set and has query with / character. Likely because it is parsing URL incorrectly in this case.

$ rebar3 shell example:

> application:ensure_all_started(hackney).
ok

> hackney:get("http://example.com?foo=/"). 
{error,nxdomain}

> % It works if we set path to / in the URL
> hackney:get("http://example.com/?foo=/"). 
{ok,200,
    [{<<"Age">>,<<"489847">>},
     {<<"Cache-Control">>,<<"max-age=604800">>},
     {<<"Content-Type">>,<<"text/html; charset=UTF-8">>},
     {<<"Date">>,<<"Tue, 14 Feb 2023 08:01:55 GMT">>},
     {<<"Etag">>,<<"\"3147526947+ident\"">>},
     {<<"Expires">>,<<"Tue, 21 Feb 2023 08:01:55 GMT">>},
     {<<"Last-Modified">>,<<"Thu, 17 Oct 2019 07:18:26 GMT">>},
     {<<"Server">>,<<"ECS (dcb/7EEF)">>},
     {<<"Vary">>,<<"Accept-Encoding">>},
     {<<"X-Cache">>,<<"HIT">>},
     {<<"Content-Length">>,<<"1256">>}],
    #Ref<0.2060195221.1788346373.92043>}

Issue seems to be with hackney_url:parse module, it is parsing example.com?foo= as hostname leading to nxdomain error.

> hackney_url:parse_url("http://example.com?foo=/").
{hackney_url,hackney_tcp,http,<<"example.com?foo=">>,
             <<"/">>,<<"/">>,<<>>,<<>>,"example.com?foo=",80,<<>>,<<>>}

akash-akya avatar Feb 14 '23 08:02 akash-akya

is http://example.com?foo=/ a valid URI though? I need to check.

benoitc avatar Mar 01 '23 22:03 benoitc

Spec mentions that / can appear in the query part, and path can be empty. So it should be parsed as, path: "" query:"foo=/" I think

akash-akya avatar Mar 02 '23 08:03 akash-akya