Skip to content

DoH: auto-completion logic for /dns-query never works due to pathname check #95

@lsongdev

Description

@lsongdev

Description of the bug

The current makeRequest method attempts to automatically complete the user-provided DoH server address into the standard /dns-query?dns= path.

However, the original code has an issue:

if (!u.pathname) url += '/dns-query?dns={query}';

https://github.com/lsongdev/node-dns/blob/e4fa035aca0b8eb730bde3431fbf0c60a31a09c9/client/doh.js#L42C3-L42C52

the condition u.pathname == '' will never be true, because in Node.js the pathname of a URL object is always at least / and never an empty string. As a result, the auto-completion logic never actually takes effect.

When a developer provides 1.1.1.1, the expected request should be: https://1.1.1.1/dns-query?dns=<query>

But when a developer provides some-doh-server.example.com, we cannot be sure whether the intended request is: https://some-doh-server.example.com/dns-query?dns=<query> or https://some-doh-server.example.com?dns=<query>

Since the RFC4648 DoH specification does not mandate that the path must be /dns-query, the latter form is also valid. In this situation, we must not automatically rewrite a URL whose pathname is / into /dns-query, as this could break the endpoint explicitly chosen by the developer.

In addition, according to RFC4648#4.1

The DNS query is included in a single variable named “dns” in the
query component of the request URI. The value of the “dns” variable
is the content of the DNS request message, encoded with base64url.

The ?dns= parameter is mandatory, and we must follow the RFC specification. Therefore, the feature of using custom query parameter names is no longer necessary.

Steps To Reproduce

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions