@tryghost/domain-validator 3.0.0 → 4.0.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/caa.js +10 -6
- package/lib/validate.js +9 -7
- package/package.json +3 -3
package/lib/caa.js
CHANGED
|
@@ -2,17 +2,20 @@ const dns = require('@tryghost/dns');
|
|
|
2
2
|
const debug = require('@tryghost/debug')('dv:caa');
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Check
|
|
5
|
+
* Check whether the domain's CAA records allow any of the given issuers.
|
|
6
6
|
*
|
|
7
7
|
* @param {string} customdomain
|
|
8
|
-
* @param {string}
|
|
9
|
-
* @returns {Promise<{isCaaValid: boolean, caaSource: string|null, caaAllowedIssuers: string[], caaError: string|null}>}
|
|
8
|
+
* @param {string[]} issuers - CA identities in preference order (e.g. ['certainly.com', 'letsencrypt.org'])
|
|
9
|
+
* @returns {Promise<{isCaaValid: boolean, caaChosenIssuer: string|null, caaSource: string|null, caaAllowedIssuers: string[], caaError: string|null}>}
|
|
10
10
|
*/
|
|
11
|
-
module.exports.validate = (customdomain,
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
module.exports.validate = (customdomain, issuers) => {
|
|
12
|
+
// Tolerate a missing issuers arg here so we still enter the .catch below
|
|
13
|
+
// and fail open. dns.caa will throw a clear ValidationError on bad input.
|
|
14
|
+
debug('Checking CAA for ' + customdomain + ' against ' + (issuers || []).join(', '));
|
|
15
|
+
return dns.caa(customdomain, {issuers}).then((result) => {
|
|
14
16
|
return {
|
|
15
17
|
isCaaValid: result.allowed,
|
|
18
|
+
caaChosenIssuer: result.matchedIssuer,
|
|
16
19
|
caaSource: result.source,
|
|
17
20
|
caaAllowedIssuers: result.allowedIssuers,
|
|
18
21
|
caaError: result.error
|
|
@@ -29,6 +32,7 @@ module.exports.validate = (customdomain, issuer) => {
|
|
|
29
32
|
debug('Unexpected CAA error: ' + message);
|
|
30
33
|
return {
|
|
31
34
|
isCaaValid: true,
|
|
35
|
+
caaChosenIssuer: issuers && issuers[0] ? issuers[0] : null,
|
|
32
36
|
caaSource: null,
|
|
33
37
|
caaAllowedIssuers: [],
|
|
34
38
|
caaError: message
|
package/lib/validate.js
CHANGED
|
@@ -24,13 +24,14 @@ const validityReportObject = {
|
|
|
24
24
|
isDnsValidForSSL: false,
|
|
25
25
|
sslRating: null,
|
|
26
26
|
isCaaValid: true,
|
|
27
|
+
caaChosenIssuer: null,
|
|
27
28
|
caaSource: null,
|
|
28
29
|
caaAllowedIssuers: [],
|
|
29
30
|
caaError: null,
|
|
30
31
|
message: ''
|
|
31
32
|
};
|
|
32
33
|
|
|
33
|
-
_private.doChecks = (subdomain, customdomain, subdirectory, prodomain,
|
|
34
|
+
_private.doChecks = (subdomain, customdomain, subdirectory, prodomain, caaIssuers) => {
|
|
34
35
|
const checkResult = {};
|
|
35
36
|
debug('starting pro');
|
|
36
37
|
return pro.validate('https', subdomain, customdomain, subdirectory, prodomain)
|
|
@@ -39,7 +40,7 @@ _private.doChecks = (subdomain, customdomain, subdirectory, prodomain, caaIssuer
|
|
|
39
40
|
debug('got pro, starting dns');
|
|
40
41
|
return Promise.all([
|
|
41
42
|
dns.validate(subdomain, customdomain, checkResult.pro.isGhostPro, prodomain),
|
|
42
|
-
|
|
43
|
+
(caaIssuers && caaIssuers.length > 0) ? caa.validate(customdomain, caaIssuers) : Promise.resolve(null)
|
|
43
44
|
]);
|
|
44
45
|
})
|
|
45
46
|
.then(([dnsResult, caaResult]) => {
|
|
@@ -60,11 +61,12 @@ _private.doChecks = (subdomain, customdomain, subdirectory, prodomain, caaIssuer
|
|
|
60
61
|
* @param {string} customdomain
|
|
61
62
|
* @param {string} subdirectory
|
|
62
63
|
* @param {string} [prodomain=ghost.io]
|
|
63
|
-
* @param {string} [
|
|
64
|
-
*
|
|
64
|
+
* @param {string[]} [caaIssuers] - CA identities to check CAA records against, in preference order
|
|
65
|
+
* (e.g. ['certainly.com', 'letsencrypt.org']). When omitted or
|
|
66
|
+
* empty, CAA is not checked and isCaaValid defaults to true.
|
|
65
67
|
*/
|
|
66
|
-
module.exports.validate = (subdomain, customdomain, subdirectory, prodomain = 'ghost.io',
|
|
67
|
-
.doChecks(subdomain, customdomain, subdirectory, prodomain,
|
|
68
|
+
module.exports.validate = (subdomain, customdomain, subdirectory, prodomain = 'ghost.io', caaIssuers) => _private
|
|
69
|
+
.doChecks(subdomain, customdomain, subdirectory, prodomain, caaIssuers)
|
|
68
70
|
.then(function (result) {
|
|
69
71
|
// Deep clone so nested mutable fields (input, caaAllowedIssuers)
|
|
70
72
|
// can't leak across validation calls via the shared template.
|
|
@@ -88,7 +90,7 @@ module.exports.validate = (subdomain, customdomain, subdirectory, prodomain = 'g
|
|
|
88
90
|
if (!validityReport.isCaaValid) {
|
|
89
91
|
validityReport.isDnsValidForSSL = false;
|
|
90
92
|
validityReport.sslRating = 'D';
|
|
91
|
-
validityReport.message = 'CAA record does not allow ' +
|
|
93
|
+
validityReport.message = 'CAA record does not allow any of ' + caaIssuers.join(', ')
|
|
92
94
|
+ ' (allowed: ' + (validityReport.caaAllowedIssuers.join(', ') || 'none')
|
|
93
95
|
+ ', source: ' + validityReport.caaSource + ')';
|
|
94
96
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/domain-validator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "ssh://git@github.com/TryGhost/Pro",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@tryghost/debug": "2.0.3",
|
|
34
|
-
"@tryghost/dns": "^0.
|
|
34
|
+
"@tryghost/dns": "^0.8.0",
|
|
35
35
|
"@tryghost/errors": "3.0.3",
|
|
36
36
|
"@tryghost/pretty-cli": "3.0.3",
|
|
37
37
|
"bluebird": "3.7.2",
|
|
38
38
|
"got": "11.8.6",
|
|
39
39
|
"lodash": "4.17.23"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "258ac0821f5b06978db14cc5c1879efdf33b927c"
|
|
42
42
|
}
|