Closed camhart closed 4 years ago
The doh example was written during the time that DOH was experimental and before RFC 8484 was finalized. It needs updated with the standard URLs. This patch makes it work. I'll submit a pull request.
diff --git a/examples/doh.js b/examples/doh.js
index 37ef19f..b9a6b91 100644
--- a/examples/doh.js
+++ b/examples/doh.js
@@ -26,12 +26,12 @@ const buf = dnsPacket.encode({
})
const options = {
- hostname: 'dns.google.com',
+ hostname: 'dns.google',
port: 443,
- path: '/experimental',
+ path: '/dns-query',
method: 'POST',
headers: {
- 'Content-Type': 'application/dns-udpwireformat',
+ 'Content-Type': 'application/dns-message',
'Content-Length': Buffer.byteLength(buf)
}
The error I posted is from decoding a response from Google dns--not encoding one to be sent.
Send sample code if you want someone to look at it where we can reproduce it. This doesn’t sound DoH related anymore.
const doh = require('@sagi.io/dns-over-https')
async function run() { let r1 = await doh.query({ name: 'google.com', method: 'GET', hostname: 'dns.google.com', path: '/dns-query', port: 443, userAgent: '@sagi.io/dns-over-https', type: 'A', klass: 'IN', useHttps: true, }).catch(err => { console.log(err)})
console.log(rl) }
run()
That explodes with:
C:\Users\Cam\projects\playground\base64url>node bug.js
internal/buffer.js:77
throw new ERR_OUT_OF_RANGE(type || 'offset',
^
RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 785. Received 858
[90m at boundsError (internal/buffer.js:77:9)[39m
[90m at Buffer.readUInt16BE (internal/buffer.js:323:5)[39m
at Object.question.decode (C:\Users\Cam\projects\playground\base64url\node_modules\[4mdns-packet[24m\index.js:1417:31)
at decodeList (C:\Users\Cam\projects\playground\base64url\node_modules\[4mdns-packet[24m\index.js:1537:19)
at Object.exports.decode (C:\Users\Cam\projects\playground\base64url\node_modules\[4mdns-packet[24m\index.js:1477:12)
at IncomingMessage.<anonymous> (C:\Users\Cam\projects\playground\base64url\node_modules\[4m@sagi.io[24m\dns-over-https\index.js:78:31)
[90m at IncomingMessage.emit (events.js:321:20)[39m
[90m at IncomingMessage.Readable.read (_stream_readable.js:508:10)[39m
[90m at flow (_stream_readable.js:979:34)[39m
[90m at resume_ (_stream_readable.js:960:3)[39m {
code: [32m'ERR_OUT_OF_RANGE'[39m
}
Just realized it must be a bug with how @sagi.io/dns-over-https
is using it. Opened a bug on their repo (https://github.com/sagi/dns-over-https-node/issues/2).
I get this whenever I attempt to use Google's DoH endpoint. I don't get it from cloudflare. Any ideas?