pending-dns 1.2.3 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -66,6 +66,14 @@ retry = 600
66
66
  expiration = 604800
67
67
  minimum = 60
68
68
 
69
+ # Text to return for chaos requests
70
+ # Disabled by default
71
+ [chaos]
72
+ #"version.bind" = "PendingDNS"
73
+ #"hostname.bind" = "forbidden.lan"
74
+ #"id.server" = "forbidden.lan"
75
+ #"authors.bind" = ["Andris Reinman"]
76
+
69
77
  # Resolver for external DNS queries, set ns=false to use system default
70
78
  # Mostly used for ANAME resolving
71
79
  [resolver]
package/lib/api-server.js CHANGED
@@ -125,7 +125,7 @@ const recordScheme = Joi.object({
125
125
  allowQuerySquareBrackets: false
126
126
  })
127
127
  .default(false)
128
- .required()
128
+ .optional()
129
129
  })
130
130
  .when('type', {
131
131
  is: 'AAAA',
@@ -138,7 +138,7 @@ const recordScheme = Joi.object({
138
138
  allowQuerySquareBrackets: false
139
139
  })
140
140
  .default(false)
141
- .required()
141
+ .optional()
142
142
  })
143
143
  .description('Health check URI for A/AAAA')
144
144
  .label('HealthCheck'),
@@ -62,6 +62,7 @@ const processQuestion = async (response, question, domain, depth) => {
62
62
  domain = normalizeDomain(domain || question.name);
63
63
 
64
64
  let questionTypeStr = reversedTypes.has(question.type) ? reversedTypes.get(question.type) : false;
65
+
65
66
  if (!questionTypeStr) {
66
67
  // nothing to do here
67
68
  return;
@@ -163,6 +164,31 @@ const processQuestion = async (response, question, domain, depth) => {
163
164
  response.answers.push(entry);
164
165
  }
165
166
 
167
+ // Chaos responses
168
+ if (
169
+ question.class === dns2.Packet.CLASS.CH &&
170
+ questionTypeStr === 'TXT' &&
171
+ question.class === dns2.Packet.CLASS.CH &&
172
+ config.chaos &&
173
+ domain in config.chaos
174
+ ) {
175
+ for (let entry of [].concat(config.chaos[domain] || [])) {
176
+ response.answers.push({
177
+ name: domain,
178
+ type: 'TXT',
179
+ data: formatTXTData(entry),
180
+ ttl: 0,
181
+ class: dns2.Packet.CLASS.CH
182
+ });
183
+ }
184
+ response.authorities.push({
185
+ name: domain,
186
+ type: 'NS',
187
+ ns: domain,
188
+ ttl: 0,
189
+ class: dns2.Packet.CLASS.CH
190
+ });
191
+ }
166
192
  return;
167
193
  }
168
194
 
@@ -365,12 +391,14 @@ const dnsHandler = async request => {
365
391
  });
366
392
 
367
393
  // normalize answers for the DNS library
368
- response.answers.forEach(answer => {
369
- answer.type = dns2.Packet.TYPE[answer.type];
370
- answer.class = dns2.Packet.CLASS.IN;
371
- answer.name = punycode.toASCII(answer.name);
372
- answer.ttl = config.dns.ttl;
373
- });
394
+ for (let responseType of [response.answers, response.authorities]) {
395
+ responseType.forEach(answer => {
396
+ answer.type = dns2.Packet.TYPE[answer.type];
397
+ answer.class = typeof answer.class === 'number' ? answer.class : dns2.Packet.CLASS.IN;
398
+ answer.name = punycode.toASCII(answer.name);
399
+ answer.ttl = typeof answer.ttl === 'number' && answer.ttl >= 0 ? answer.ttl : config.dns.ttl;
400
+ });
401
+ }
374
402
 
375
403
  return response;
376
404
  };
package/lib/dns-server.js CHANGED
@@ -7,10 +7,14 @@ const logger = require('./logger').child({ component: 'dns-server' });
7
7
  const { createDNSTcpServer } = require('./dns-tcp-server');
8
8
  const { createDNSUdpServer } = require('./dns-udp-server');
9
9
 
10
+ const SUSPENDED_TYPES = new Set([
11
+ 0x29 // EDNS is supported by the dns module
12
+ ]);
13
+
10
14
  const SUPPORTED_TYPES = new Set(
11
15
  Object.keys(dns2.Packet.TYPE)
12
16
  .map(key => dns2.Packet.TYPE[key])
13
- .filter(val => typeof val === 'number')
17
+ .filter(val => typeof val === 'number' && !SUSPENDED_TYPES.has(val))
14
18
  );
15
19
 
16
20
  const init = async () => {
@@ -39,7 +39,9 @@ class DNSUdpServer extends EventEmitter {
39
39
  this.emit('request', request, this.send.bind(this, rinfo), rinfo);
40
40
  }
41
41
  send(rinfo, message) {
42
- if (message instanceof Packet) message = message.toBuffer();
42
+ if (message instanceof Packet) {
43
+ message = message.toBuffer();
44
+ }
43
45
  return new Promise((resolve, reject) => {
44
46
  this.socket.send(message, rinfo.port, rinfo.address, err => {
45
47
  if (err) return reject(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pending-dns",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Lightweight API driven DNS server",
5
5
  "main": "index.js",
6
6
  "scripts": {