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

DNS over HTTPS support #40

Open
szmarczak opened this issue Aug 19, 2021 · 16 comments
Open

DNS over HTTPS support #40

szmarczak opened this issue Aug 19, 2021 · 16 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@szmarczak
Copy link
Owner

No description provided.

@szmarczak szmarczak added enhancement New feature or request help wanted Extra attention is needed labels Aug 19, 2021
@lokesh411
Copy link

lokesh411 commented May 2, 2022

One question, would we be using cloudflare or google DoH APIs for this (Ex.: https://cloudflare-dns.com/dns-query). Interested to contribute here

@szmarczak
Copy link
Owner Author

I think the CloudFlare one is a good start to implement, then we can do something like this:

const cacheable = new CacheableLookup();

cacheable.servers = [
	  '8.8.8.8', // DNS over UDP/TCP
	  'https://1.1.1.1/dns-query', // DNS over HTTPS
];

There's a spec at https://datatracker.ietf.org/doc/html/rfc8484


I'd do this by storing HTTP/2 sessions in an object (key would be a string starting with https://). We can detect cacheable.servers changes in

set servers(servers) {
this.clear();
this._resolver.setServers(servers);
}

so when it's updated, we close sessions that are no longer required and open new ones if there shall be. Then when a user makes a DNS request

async _resolve(hostname) {

we simply go through the list and send a HTTP/2 request to the DoH server and handle that. Note that dns.Resolver doesn't accept DoH servers so we need to filter the list before calling resolver.setServers.


It's possible that there may be multiple DoH servers. This can be quite a hassle, so no need to do this all in one PR.

@lokesh411
Copy link

Thanks, would go through the specification once, DoH queries should be round robin if multiple DoH servers are given right?

@szmarczak
Copy link
Owner Author

No, those should be fallback servers. As per Node.js docs:

Fallback DNS servers will only be used if the earlier ones time out or result in some other error.

@lokesh411
Copy link

Got it, thanks

@Kikobeats
Copy link
Contributor

Kikobeats commented Jul 1, 2022

I created doh-resolver to use DNS-over-HTTPS as resolver with cacheable-lookup:

const CacheableLookup = require('cacheable-lookup')
const DoHResolver = require('doh-resolver')
const https = require('https')

const resolver = new DoHResolver({ servers: ['1.1.1.1', '8.8.8.8'] })

const cacheable = new CacheableLookup({ resolver })

https.get('https://example.com', { lookup: cacheable.lookup }, response => {
  // Handle the response here
})

@szmarczak
Copy link
Owner Author

Awesome! It's quite heavy though, can you reduce the size?

@Kikobeats
Copy link
Contributor

yea, I'm working on it; the main dependency is dns2 that is exporting a lot of things I really don't need

@szmarczak
Copy link
Owner Author

Are you sure?

image

@Kikobeats
Copy link
Contributor

gotcha; shipped [email protected] that removes the logger dependency

CleanShot 2022-07-05 at 10 54 47@2x

@szmarczak
Copy link
Owner Author

Awesome! Would you be up to sending a PR mentioning this in the docs?

@titanism
Copy link

PR #77 fixes this! 🎉

See 🍊 Tangerine and forwardemail/nodejs-dns-over-https-tangerine#1.

@titanism
Copy link

titanism commented Jan 1, 2024

Reported as spam to GitHub

@titanism
Copy link

titanism commented Jan 1, 2024

Reported for spam

@Kikobeats
Copy link
Contributor

Kikobeats commented Jan 10, 2024

BTW this is how I use cacheable-lookup with tangerine for getting DNS-over-HTTPs:

new CacheableLookup({
  resolver: new Tangerine(
    {
      cache: false,
    },
    require('got').extend({
      responseType: 'buffer',
      decompress: false,
      retry: 0
    })
  )
})

If this looks good to @titanism I can create a PR to add it into the README 🙂

@titanism
Copy link

You're welcome to add whatever you like! This nicely shows how it supports things other than undici.

@github-staff github-staff deleted a comment from akashakki Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants