Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const question = (requestPacket.questions && requestPacket.questions.length === 1) ? requestPacket.questions[0] : null
if (question === null ||
(question.type !== 'A' && question.type !== 'AAAA') ||
!question.name.endsWith('.' + conf.newTld)) return deferToDnsFallback(request, requestBody)
log('Responding to query for new TLD')
// If we ask for our TLD on localhost, we'll just send back the fixed local
// IPs. However, if our host is something else, we defer to the fallback and
// just change the answer names so we get SOAs, NSs, As, CNAMEs, etc.
let responsePacket: dnsPacket.Packet
if (conf.proxyDnsTo === 'localhost') {
log('Sending back localhost IPs')
responsePacket = {
id: requestPacket.id,
type: 'response',
flags: dnsPacket.RECURSION_DESIRED | dnsPacket.RECURSION_AVAILABLE,
questions: requestPacket.questions,
answers: [{
type: question.type,
class: 'IN',
name: question.name,
data: question.type === 'A' ? '127.0.0.1' : '::1',
ttl: 600
}]
}
} else {
// Update the request packet to do a different host
log('Proxying requested DNS name to: ', conf.proxyDnsTo)
const origName = question.name
requestPacket.questions.forEach(q => q.name = conf.proxyDnsTo)
// Send it off
const proxiedResponse = await deferToDnsFallback(request, dnsPacket.encode(requestPacket).buffer)
}
function onlistening () {
self._interval = setInterval(ontimeoutCheck, self.timeoutChecks)
self.emit('listening')
}
function onclose () {
self.emit('close')
}
}
util.inherits(DNS, events.EventEmitter)
DNS.RECURSION_DESIRED = DNS.prototype.RECURSION_DESIRED = packet.RECURSION_DESIRED
DNS.RECURSION_AVAILABLE = DNS.prototype.RECURSION_AVAILABLE = packet.RECURSION_AVAILABLE
DNS.TRUNCATED_RESPONSE = DNS.prototype.TRUNCATED_RESPONSE = packet.TRUNCATED_RESPONSE
DNS.AUTHORITATIVE_ANSWER = DNS.prototype.AUTHORITATIVE_ANSWER = packet.AUTHORITATIVE_ANSWER
DNS.AUTHENTIC_DATA = DNS.prototype.AUTHENTIC_DATA = packet.AUTHENTIC_DATA
DNS.CHECKING_DISABLED = DNS.prototype.CHECKING_DISABLED = packet.CHECKING_DISABLED
DNS.prototype.address = function () {
return this.socket.address()
}
DNS.prototype.bind = function (...args) {
const onlistening = args.length > 0 && args[args.length - 1]
if (typeof onlistening === 'function') {
this.once('listening', onlistening)
this.socket.bind(...args.slice(0, -1))
} else {
this.socket.bind(...args)
}
function onlistening () {
self._interval = setInterval(ontimeoutCheck, self.timeoutChecks)
self.emit('listening')
}
function onclose () {
self.emit('close')
}
}
util.inherits(DNS, events.EventEmitter)
DNS.RECURSION_DESIRED = DNS.prototype.RECURSION_DESIRED = packet.RECURSION_DESIRED
DNS.RECURSION_AVAILABLE = DNS.prototype.RECURSION_AVAILABLE = packet.RECURSION_AVAILABLE
DNS.TRUNCATED_RESPONSE = DNS.prototype.TRUNCATED_RESPONSE = packet.TRUNCATED_RESPONSE
DNS.AUTHORITATIVE_ANSWER = DNS.prototype.AUTHORITATIVE_ANSWER = packet.AUTHORITATIVE_ANSWER
DNS.AUTHENTIC_DATA = DNS.prototype.AUTHENTIC_DATA = packet.AUTHENTIC_DATA
DNS.CHECKING_DISABLED = DNS.prototype.CHECKING_DISABLED = packet.CHECKING_DISABLED
DNS.prototype.address = function () {
return this.socket.address()
}
DNS.prototype.bind = function (...args) {
const onlistening = args.length > 0 && args[args.length - 1]
if (typeof onlistening === 'function') {
this.once('listening', onlistening)
this.socket.bind(...args.slice(0, -1))
} else {
this.socket.bind(...args)