hackney
hackney copied to clipboard
Incorrect URL parsing when path is not set and query contains `/` character
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,<<>>,<<>>}
is http://example.com?foo=/ a valid URI though? I need to check.
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