@tryghost/domain-validator 4.0.9 → 4.1.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/redirect.js +56 -0
- package/lib/validate.js +8 -1
- package/package.json +6 -6
package/lib/redirect.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const dns = require('@tryghost/dns');
|
|
2
|
+
const domain = require('@tryghost/dns/lib/domain');
|
|
3
|
+
const debug = require('@tryghost/debug')('dv:redirect');
|
|
4
|
+
|
|
5
|
+
const REDIRECT_SERVER_IP = '178.128.137.126';
|
|
6
|
+
|
|
7
|
+
const skipped = { hasRedirectRecord: null, redirectDomain: null };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Check whether the counterpart of an apex/www domain has an A record set to
|
|
11
|
+
* the redirect server.
|
|
12
|
+
*
|
|
13
|
+
* For an apex domain we check www.<domain>, for a www domain we check the
|
|
14
|
+
* apex. Any other subdomain has no redirect counterpart, so the check is
|
|
15
|
+
* skipped and hasRedirectRecord stays null. Informational only — this never
|
|
16
|
+
* affects ratings or whether the domain can be activated.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} customdomain
|
|
19
|
+
* @returns {Promise<{hasRedirectRecord: boolean|null, redirectDomain: string|null}>}
|
|
20
|
+
*/
|
|
21
|
+
module.exports.validate = (customdomain) => {
|
|
22
|
+
let parsed;
|
|
23
|
+
try {
|
|
24
|
+
parsed = domain.normalize(customdomain);
|
|
25
|
+
} catch {
|
|
26
|
+
return Promise.resolve(skipped);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!parsed.domain) {
|
|
30
|
+
return Promise.resolve(skipped);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let redirectDomain;
|
|
34
|
+
if (!parsed.subdomain) {
|
|
35
|
+
// Apex domain: the redirect record lives on www
|
|
36
|
+
redirectDomain = 'www.' + parsed.domain;
|
|
37
|
+
} else if (parsed.subdomain === 'www') {
|
|
38
|
+
// www domain: the redirect record lives on the apex
|
|
39
|
+
redirectDomain = parsed.domain;
|
|
40
|
+
} else {
|
|
41
|
+
return Promise.resolve(skipped);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
debug('Checking redirect record for ' + redirectDomain);
|
|
45
|
+
return dns
|
|
46
|
+
.aRecordMatches(redirectDomain, REDIRECT_SERVER_IP)
|
|
47
|
+
.then((matches) => ({ hasRedirectRecord: matches, redirectDomain }))
|
|
48
|
+
.catch((err) => {
|
|
49
|
+
// Fail open: this check is informational, so it can never take
|
|
50
|
+
// down the rest of the validity report. null = "unknown".
|
|
51
|
+
const message =
|
|
52
|
+
err && typeof err.message === 'string' ? err.message : String(err || 'UNKNOWN');
|
|
53
|
+
debug('Unexpected redirect record error: ' + message);
|
|
54
|
+
return { hasRedirectRecord: null, redirectDomain };
|
|
55
|
+
});
|
|
56
|
+
};
|
package/lib/validate.js
CHANGED
|
@@ -2,6 +2,7 @@ const _ = require('lodash');
|
|
|
2
2
|
const dns = require('./dns');
|
|
3
3
|
const pro = require('./pro');
|
|
4
4
|
const caa = require('./caa');
|
|
5
|
+
const redirect = require('./redirect');
|
|
5
6
|
const debug = require('@tryghost/debug')('dv:validate');
|
|
6
7
|
|
|
7
8
|
const _private = {};
|
|
@@ -28,6 +29,8 @@ const validityReportObject = {
|
|
|
28
29
|
caaSource: null,
|
|
29
30
|
caaAllowedIssuers: [],
|
|
30
31
|
caaError: null,
|
|
32
|
+
hasRedirectRecord: null,
|
|
33
|
+
redirectDomain: null,
|
|
31
34
|
message: '',
|
|
32
35
|
};
|
|
33
36
|
|
|
@@ -44,11 +47,13 @@ _private.doChecks = (subdomain, customdomain, subdirectory, prodomain, caaIssuer
|
|
|
44
47
|
caaIssuers && caaIssuers.length > 0
|
|
45
48
|
? caa.validate(customdomain, caaIssuers)
|
|
46
49
|
: Promise.resolve(null),
|
|
50
|
+
redirect.validate(customdomain),
|
|
47
51
|
]);
|
|
48
52
|
})
|
|
49
|
-
.then(([dnsResult, caaResult]) => {
|
|
53
|
+
.then(([dnsResult, caaResult, redirectResult]) => {
|
|
50
54
|
checkResult.dns = dnsResult;
|
|
51
55
|
checkResult.caa = caaResult;
|
|
56
|
+
checkResult.redirect = redirectResult;
|
|
52
57
|
debug('got dns, returning');
|
|
53
58
|
return checkResult;
|
|
54
59
|
});
|
|
@@ -91,6 +96,8 @@ module.exports.validate = (
|
|
|
91
96
|
_.merge(validityReport, _.omit(result.pro, 'raw'));
|
|
92
97
|
// Do a few last DNS-related checks, and then output validity values
|
|
93
98
|
_.merge(validityReport, _.omit(result.dns, 'raw'));
|
|
99
|
+
// Redirect record info is informational only and never affects ratings
|
|
100
|
+
_.merge(validityReport, result.redirect);
|
|
94
101
|
|
|
95
102
|
if (result.caa) {
|
|
96
103
|
_.merge(validityReport, result.caa);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/domain-validator",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"repository": {
|
|
@@ -21,17 +21,17 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@tryghost/debug": "2.3.
|
|
25
|
-
"@tryghost/errors": "3.3.
|
|
26
|
-
"@tryghost/pretty-cli": "3.3.
|
|
24
|
+
"@tryghost/debug": "2.3.8",
|
|
25
|
+
"@tryghost/errors": "3.3.8",
|
|
26
|
+
"@tryghost/pretty-cli": "3.3.8",
|
|
27
27
|
"got": "11.8.6",
|
|
28
28
|
"lodash": "4.18.1",
|
|
29
29
|
"semver": "7.8.5",
|
|
30
|
-
"@tryghost/dns": "^0.8.
|
|
30
|
+
"@tryghost/dns": "^0.8.10"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"should": "13.2.3",
|
|
34
|
-
"sinon": "22.
|
|
34
|
+
"sinon": "22.1.0"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=20.20.0"
|