@tryghost/domain-validator 4.1.0 → 5.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/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, proto) => {
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
- if (
60
- !_.has(headers, 'x-ghost-forwarded-proto') ||
61
- headers['x-ghost-forwarded-proto'] !== 'https'
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, proto);
140
+ response.isProxy = _private.detectProxy(headers);
141
141
 
142
142
  // Generate a proxy report
143
143
  const proxyResult = _private.validateProxy(
package/lib/request.js CHANGED
@@ -1,4 +1,5 @@
1
- const got = require('got');
1
+ // got 12+ is ESM-only; Node 22.12+ can require() it and exposes the export as `.default`
2
+ const got = require('got').default;
2
3
  const _ = require('lodash');
3
4
  const errors = require('@tryghost/errors');
4
5
  const debug = require('@tryghost/debug')('dv:request');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/domain-validator",
3
- "version": "4.1.0",
3
+ "version": "5.0.0",
4
4
  "license": "MIT",
5
5
  "author": "Ghost Foundation",
6
6
  "repository": {
@@ -21,20 +21,20 @@
21
21
  "access": "public"
22
22
  },
23
23
  "dependencies": {
24
- "@tryghost/debug": "2.3.8",
25
- "@tryghost/errors": "3.3.8",
26
- "@tryghost/pretty-cli": "3.3.8",
27
- "got": "11.8.6",
24
+ "@tryghost/debug": "2.3.19",
25
+ "@tryghost/errors": "3.4.5",
26
+ "@tryghost/pretty-cli": "3.4.1",
27
+ "got": "16.2.0",
28
28
  "lodash": "4.18.1",
29
29
  "semver": "7.8.5",
30
- "@tryghost/dns": "^0.8.10"
30
+ "@tryghost/dns": "^0.9.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "should": "13.2.3",
34
34
  "sinon": "22.1.0"
35
35
  },
36
36
  "engines": {
37
- "node": ">=20.20.0"
37
+ "node": ">=22.12.0"
38
38
  },
39
39
  "scripts": {
40
40
  "dv": "node bin/dv.js",