pending-dns 1.2.1 → 1.2.3

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.
package/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Andris Reinman
3
+ Copyright (c) 2020-2023 Andris Reinman
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -341,10 +341,11 @@ const dnsHandler = async request => {
341
341
 
342
342
  await Promise.all(
343
343
  request.questions.map(question => {
344
- logger.info({
344
+ logger.debug({
345
345
  id: request._id,
346
346
  msg: 'DNS query',
347
- type: request.source.type,
347
+ action: 'dns_query',
348
+ proto: request.source.type,
348
349
  port: request.source.port,
349
350
  address: request.source.address,
350
351
  question: question.name,
@@ -354,9 +355,10 @@ const dnsHandler = async request => {
354
355
  })
355
356
  );
356
357
 
357
- logger.info({
358
- msg: 'DNS response',
358
+ logger.debug({
359
359
  id: request._id,
360
+ msg: 'DNS response',
361
+ action: 'dns_response',
360
362
  dnsTime: Date.now() - startTime,
361
363
  questions: request.questions,
362
364
  answers: response.answers
package/lib/dns-server.js CHANGED
@@ -59,7 +59,11 @@ const init = async () => {
59
59
  logger.info({ msg: 'DNS server listening', protocol: 'tcp', host: config.dns.host, port: config.dns.port });
60
60
  })
61
61
  .on('error', err => {
62
- logger.error({ msg: 'DNS server error', protocol: 'tcp', err });
62
+ let method = 'error';
63
+ if (err && ['ECONNRESET'].includes(err.code)) {
64
+ method = 'trace';
65
+ }
66
+ logger[method]({ msg: 'DNS server error', protocol: 'tcp', err });
63
67
  });
64
68
  };
65
69
 
@@ -40,15 +40,17 @@ class DNSTcpServer extends EventEmitter {
40
40
  try {
41
41
  request = Packet.parse(buffer.slice(2));
42
42
  } catch (err) {
43
- logger.error({ msg: 'Failed to parse DNS package', type: 'tcp', err, buffer, port: socket.remotePort, address: socket.remoteAddress });
43
+ logger.trace({ msg: 'Failed to parse DNS package', proto: 'tcp', err, buffer, port: socket.remotePort, address: socket.remoteAddress });
44
44
  try {
45
45
  socket.end();
46
46
  } catch (err) {
47
47
  // ignore
48
48
  }
49
+ return;
49
50
  }
51
+
50
52
  request.source = {
51
- type: 'tcp',
53
+ proto: 'tcp',
52
54
  port: socket.remotePort,
53
55
  address: socket.remoteAddress
54
56
  };
@@ -93,10 +95,16 @@ class DNSTcpServer extends EventEmitter {
93
95
  try {
94
96
  let len = Buffer.alloc(2);
95
97
  len.writeUInt16BE(message.length);
96
- socket.end(Buffer.concat([len, message]));
98
+
99
+ if (['open', 'writeOnly'].includes(socket.readyState)) {
100
+ socket.end(Buffer.concat([len, message]));
101
+ } else {
102
+ socket.end();
103
+ }
97
104
  } catch (err) {
98
105
  // ignore
99
106
  }
107
+
100
108
  resolve(message);
101
109
  });
102
110
  }
@@ -26,13 +26,16 @@ class DNSUdpServer extends EventEmitter {
26
26
  try {
27
27
  request = Packet.parse(buffer);
28
28
  } catch (err) {
29
- logger.error({ msg: 'Failed to parse DNS package', type: 'udp', err, buffer, port: rinfo.port, address: rinfo.address });
29
+ logger.trace({ msg: 'Failed to parse DNS package', proto: 'udp', err, buffer, port: rinfo.port, address: rinfo.address });
30
+ return;
30
31
  }
32
+
31
33
  request.source = {
32
- type: 'udp',
34
+ proto: 'udp',
33
35
  port: rinfo.port,
34
36
  address: rinfo.address
35
37
  };
38
+
36
39
  this.emit('request', request, this.send.bind(this, rinfo), rinfo);
37
40
  }
38
41
  send(rinfo, message) {
@@ -263,7 +263,17 @@ const setupHttps = () =>
263
263
 
264
264
  logger.error({ msg: 'Failed to serve redirect page', err, hostname });
265
265
 
266
- const url = new URL(req.url || req.headers[':path'], `https://${hostname}/`);
266
+ let url;
267
+ try {
268
+ url = new URL(req.url || req.headers[':path'], `https://${hostname}/`);
269
+ } catch (err) {
270
+ try {
271
+ url = new URL(req.headers[':path'], `https://${hostname}/`);
272
+ } catch (err) {
273
+ url = `https://${hostname}/`;
274
+ }
275
+ }
276
+
267
277
  const route = url.pathname;
268
278
 
269
279
  res.send(
@@ -332,8 +342,17 @@ const setupHttp = () =>
332
342
  const hostname = getHostname(req).replace(/^www\./, '');
333
343
 
334
344
  logger.error({ msg: 'Failed to serve redirect page', err, hostname });
345
+ let url;
346
+ try {
347
+ url = new URL(req.url || req.headers[':path'], `https://${hostname}/`);
348
+ } catch (err) {
349
+ try {
350
+ url = new URL(req.headers[':path'], `https://${hostname}/`);
351
+ } catch (err) {
352
+ url = `https://${hostname}/`;
353
+ }
354
+ }
335
355
 
336
- const url = new URL(req.url || req.headers[':path'], `https://${hostname}/`);
337
356
  const route = url.pathname;
338
357
 
339
358
  res.send(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pending-dns",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "Lightweight API driven DNS server",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -28,26 +28,26 @@
28
28
  },
29
29
  "homepage": "https://github.com/postalsys/pending-dns#readme",
30
30
  "devDependencies": {
31
- "eslint": "8.45.0",
31
+ "eslint": "8.47.0",
32
32
  "eslint-config-nodemailer": "1.2.0",
33
- "eslint-config-prettier": "8.8.0",
33
+ "eslint-config-prettier": "9.0.0",
34
34
  "grunt": "1.6.1",
35
35
  "grunt-cli": "1.4.3",
36
36
  "grunt-eslint": "24.3.0",
37
37
  "license-report": "6.4.0"
38
38
  },
39
39
  "dependencies": {
40
- "@bugsnag/js": "^7.20.2",
40
+ "@bugsnag/js": "7.21.0",
41
41
  "@fidm/x509": "1.2.1",
42
42
  "@hapi/boom": "10.0.1",
43
43
  "@hapi/hapi": "21.3.2",
44
44
  "@hapi/inert": "7.1.0",
45
45
  "@hapi/joi": "17.1.1",
46
- "@hapi/vision": "7.0.2",
46
+ "@hapi/vision": "7.0.3",
47
47
  "@root/acme": "3.1.0",
48
48
  "@root/csr": "0.8.1",
49
49
  "dns2": "2.1.0",
50
- "handlebars": "4.7.7",
50
+ "handlebars": "4.7.8",
51
51
  "hapi-pino": "12.1.0",
52
52
  "hapi-swagger": "17.1.0",
53
53
  "http-proxy": "1.18.1",
@@ -57,7 +57,7 @@
57
57
  "minimist": "1.2.8",
58
58
  "node-rsa": "1.1.1",
59
59
  "pem-jwk": "2.0.0",
60
- "pino": "8.14.1",
60
+ "pino": "8.15.0",
61
61
  "punycode": "2.3.0",
62
62
  "shortid": "2.2.16",
63
63
  "uuid": "9.0.0",
@@ -73,9 +73,10 @@
73
73
  "help.txt"
74
74
  ],
75
75
  "targets": [
76
- "node16-linux-x64",
77
- "node16-macos-x64",
78
- "node16-win-x64"
76
+ "node18-linux-x64",
77
+ "node18-macos-x64",
78
+ "node18-macos-arm64",
79
+ "node18-win-x64"
79
80
  ],
80
81
  "outputPath": "ee-dist"
81
82
  }