@tryghost/domain-validator 1.3.0 → 1.5.0

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/lib/pro.js CHANGED
@@ -106,6 +106,12 @@ _private.buildResponse = (result, proto, subdomain, customdomain, subdirectory,
106
106
  if (result.length > 1) {
107
107
  response.hasRedirect = true;
108
108
  response.redirect = result.slice(0, -1);
109
+
110
+ const validRedirectDomains = [customdomain];
111
+ if (subdomain && prodomain) {
112
+ validRedirectDomains.push(`${subdomain}.${prodomain}`);
113
+ }
114
+ response.isGhostProRedirect = response.redirect.every(redirect => validRedirectDomains.includes(new URL(redirect.headers.location).hostname));
109
115
  }
110
116
 
111
117
  // If we find the x-ghost-cache-status header, we're seeing Ghost(Pro)
@@ -116,6 +122,9 @@ _private.buildResponse = (result, proto, subdomain, customdomain, subdirectory,
116
122
  }
117
123
  }
118
124
 
125
+ // Ensure that we only set isGhostPro to true if the redirect only uses valid domains
126
+ response.isGhostPro = response.isGhostPro && (!response.hasRedirect || response.isGhostProRedirect);
127
+
119
128
  response.isProxy = _private.detectProxy(headers, proto);
120
129
 
121
130
  // Generate a proxy report
package/lib/request.js CHANGED
@@ -4,7 +4,31 @@ const Promise = require('bluebird');
4
4
  const errors = require('@tryghost/errors');
5
5
  const debug = require('@tryghost/debug')('dv:request');
6
6
 
7
+ // Use 3rd party DNS resolver
8
+ const http = require('http');
9
+ const https = require('https');
10
+ const {Resolver} = require('dns').promises;
11
+ const resolver = new Resolver();
12
+ resolver.setServers(['1.1.1.1', '1.0.0.1']);
13
+
14
+ const staticLookup = () => async (hostname, _options, callback) => {
15
+ try {
16
+ const ips = await resolver.resolve(hostname);
17
+
18
+ if (ips.length === 0) {
19
+ return callback(new Error(`Unable to resolve ${hostname}`));
20
+ }
21
+
22
+ callback(null, ips[0], 4);
23
+ } catch (err) {
24
+ return callback(err);
25
+ }
26
+ };
27
+
7
28
  module.exports.domain = (url) => {
29
+ const httpModule = new URL(url).protocol === 'https:' ? https : http;
30
+ const httpAgent = new httpModule.Agent({lookup: staticLookup()});
31
+
8
32
  const options = {
9
33
  // We want to capture details of different hops
10
34
  followRedirect: false,
@@ -14,7 +38,8 @@ module.exports.domain = (url) => {
14
38
  retries: 1,
15
39
  headers: {
16
40
  'X-Ghost-Proxy': true
17
- }
41
+ },
42
+ agent: httpAgent
18
43
  };
19
44
 
20
45
  const responses = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/domain-validator",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "ssh://git@github.com/TryGhost/Pro",
@@ -38,5 +38,5 @@
38
38
  "got": "8.3.2",
39
39
  "lodash": "4.17.21"
40
40
  },
41
- "gitHead": "06061de9669e92d852dde89d038dfed50dc3e806"
41
+ "gitHead": "7a23ec04b7a660ee582defdf8bcabcc7268a2cd5"
42
42
  }