Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
akash-akya opened this issue Feb 14, 2023 · 2 comments

Comments

@akash-akya
Copy link
Contributor

akash-akya commented Feb 14, 2023

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,<<>>,<<>>}
@benoitc
Copy link
Owner

benoitc commented Mar 1, 2023

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

@akash-akya
Copy link
Contributor Author

akash-akya commented Mar 2, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants