@tryghost/domain-validator 4.0.9 → 4.2.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 +12 -12
- package/lib/redirect.js +56 -0
- package/lib/validate.js +8 -1
- package/package.json +6 -6
package/lib/pro.js
CHANGED
|
@@ -16,18 +16,19 @@ const responseObject = {
|
|
|
16
16
|
raw: null,
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
// The origin echoes X-Forwarded-Proto back as x-ghost-forwarded-proto, using "-" when
|
|
20
|
+
// it received no X-Forwarded-Proto header at all, so "-" is the same as the header being absent
|
|
21
|
+
_private.hasForwardedProto = (headers) =>
|
|
22
|
+
_.has(headers, 'x-ghost-forwarded-proto') && headers['x-ghost-forwarded-proto'] !== '-';
|
|
23
|
+
|
|
19
24
|
// Attempt to detect if the results look like a proxy
|
|
20
|
-
_private.detectProxy = (headers
|
|
25
|
+
_private.detectProxy = (headers) => {
|
|
21
26
|
if (
|
|
22
27
|
// If x-forwarded-host was originally set, this is a proxy. "- [Invalid]" means original value was empty
|
|
23
28
|
(_.has(headers, 'x-ghost-forwarded-host') &&
|
|
24
29
|
headers['x-ghost-forwarded-host'] !== '- [Invalid]') ||
|
|
25
30
|
// If x-amz-cf-id is set, then this is cloudfront and therefore is a proxy
|
|
26
|
-
_.has(headers, 'x-amz-cf-id')
|
|
27
|
-
// If we are making an https request and get http back, this must be a proxy
|
|
28
|
-
(proto === 'https' &&
|
|
29
|
-
_.has(headers, 'x-ghost-forwarded-proto') &&
|
|
30
|
-
headers['x-ghost-forwarded-proto'] !== proto)
|
|
31
|
+
_.has(headers, 'x-amz-cf-id')
|
|
31
32
|
) {
|
|
32
33
|
return true;
|
|
33
34
|
}
|
|
@@ -55,11 +56,10 @@ _private.validateProxy = (headers, subdomain, customdomain, subdirectory, prodom
|
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
// Proto must be https
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
) {
|
|
59
|
+
// Proto must be https when the header is present. An absent header ("-") is not
|
|
60
|
+
// evidence of a bad proxy: Fastly sets X-Forwarded-Proto itself and can lose it
|
|
61
|
+
// on the hop between its own nodes, so only fail on a positive wrong value
|
|
62
|
+
if (_private.hasForwardedProto(headers) && headers['x-ghost-forwarded-proto'] !== 'https') {
|
|
63
63
|
proxyResult.isValid = false;
|
|
64
64
|
proxyResult.errors.push({
|
|
65
65
|
'x-forwarded-proto': {
|
|
@@ -137,7 +137,7 @@ _private.buildResponse = (result, proto, subdomain, customdomain, subdirectory,
|
|
|
137
137
|
response.isGhostPro =
|
|
138
138
|
response.isGhostPro && (!response.hasRedirect || response.isGhostProRedirect);
|
|
139
139
|
|
|
140
|
-
response.isProxy = _private.detectProxy(headers
|
|
140
|
+
response.isProxy = _private.detectProxy(headers);
|
|
141
141
|
|
|
142
142
|
// Generate a proxy report
|
|
143
143
|
const proxyResult = _private.validateProxy(
|
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.2.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.14",
|
|
25
|
+
"@tryghost/errors": "3.3.14",
|
|
26
|
+
"@tryghost/pretty-cli": "3.3.14",
|
|
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.11"
|
|
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"
|