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

Multiple leading slashes in path causes hostname to be parsed incorrectly #3965

Closed
BanovMiroslav opened this issue Aug 13, 2019 · 0 comments

Comments

@BanovMiroslav
Copy link

commented Aug 13, 2019

Steps to reproduce

Urls such as http://localhost:3000//path cause incorrect parsing of the url.

Here is a catch-all route to show the result:

  server.route({
    method: 'GET',
    path: '/{p*}',
    handler: (request, h) => {
      return {
        p_param: request.params.p,
        request_url: request.url,
        request_path: request.path,
        info_hostname: request.info.hostname,
        info_host: request.info.host,
      };
    },
  });

What was the result you received?

{"p_param":"","request_url":"http://path/","request_path":"/","info_hostname":"path","info_host":"path"}

What did you expect?

{"p_param":"/path","request_url":"http://localhost:3000//path","request_path":"//path","info_hostname":"localhost","info_host":"localhost:3000"}

Context

  • node version: v10.16.2
  • hapi version: 18.3.1
  • os: Ubuntu 18.04.3 LTS

Reason

In _setUrl this code relies on native nodejs Url.URL class.

const base = (url[0] === '/' ? `${this._core.info.protocol}://${this.info.host || `${this._core.info.host}:${this._core.info.port}`}` : undefined);

url = new Url.URL(url, base);

Problem is url "//path" is protocol-relative url that has only domain component. So it is considered absolute for the purpose of the call and base is ignored.

@hueniverse hueniverse self-assigned this Sep 15, 2019
@hueniverse hueniverse added the bug label Sep 15, 2019
@hueniverse hueniverse added this to the 18.4.0 milestone Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.