@tryghost/nodemailer 2.3.16 → 2.3.18

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/README.md CHANGED
@@ -23,6 +23,11 @@ Provides pre-configured transport options for common transport services.
23
23
 
24
24
  4. `ses` - [Send via AWS SES](https://ghost.org/docs/config/#amazon-ses).
25
25
 
26
+ - Set `region` explicitly (preferred), or use a legacy `ServiceUrl` containing an
27
+ `email`, `email-smtp`, `email-fips`, or `email-smtp-fips` hostname in the form
28
+ `<service>.<region>.amazonaws.com`, with or without an HTTP(S) URL scheme.
29
+ - Defaults to `us-east-1` when no region is set and `ServiceUrl` is missing or invalid.
30
+
26
31
  5. `direct` - Attempt to connect directly to remote SMTP servers. This is the default and requires no configuration, but is more likely to be blocked by remote mail services.
27
32
 
28
33
  6. `stub` - For testing and development. Doesn't actually send mail.
package/lib/nodemailer.js CHANGED
@@ -8,6 +8,28 @@ const messages = {
8
8
  unknownTransport: `Unknown mail transport: {transport}`,
9
9
  };
10
10
 
11
+ function regionFromServiceUrl(serviceUrl) {
12
+ if (typeof serviceUrl !== 'string') {
13
+ return;
14
+ }
15
+
16
+ let url;
17
+ try {
18
+ const value = serviceUrl.trim();
19
+ const hasScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(value);
20
+ url = new URL(hasScheme ? value : `https://${value}`);
21
+ } catch {
22
+ return;
23
+ }
24
+
25
+ if (url.protocol !== 'https:' && url.protocol !== 'http:') {
26
+ return;
27
+ }
28
+
29
+ const result = /^email(?:-smtp)?(?:-fips)?\.([a-z0-9-]+)\.amazonaws\.com$/.exec(url.hostname);
30
+ return result && result[1];
31
+ }
32
+
11
33
  /**
12
34
  * @param {String} transport
13
35
  * @param {Object} options
@@ -54,13 +76,9 @@ module.exports = function (transport, options = {}) {
54
76
  case 'ses':
55
77
  const { SESv2Client, SendEmailCommand } = require('@aws-sdk/client-sesv2');
56
78
 
57
- // This keeps the legacy Ghost SES ServiceUrl parser compatible with
58
- // existing config shapes; explicit `region` remains the preferred path.
59
- // codeql[js/incomplete-hostname-regexp]
60
- const pattern = /(.*)email(.*)\.(.*).amazonaws.com/i;
61
- // codeql[js/polynomial-redos]
62
- const result = pattern.exec(options.ServiceUrl);
63
- const region = options.region || (result && result[3]) || 'us-east-1';
79
+ // Parse legacy ServiceUrl config without matching arbitrary URL contents.
80
+ const region =
81
+ options.region || regionFromServiceUrl(options.ServiceUrl) || 'us-east-1';
64
82
 
65
83
  const accessKeyId = options.accessKeyId || options.AWSAccessKeyID;
66
84
  const secretAccessKey = options.secretAccessKey || options.AWSSecretKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/nodemailer",
3
- "version": "2.3.16",
3
+ "version": "2.3.18",
4
4
  "license": "MIT",
5
5
  "author": "Ghost Foundation",
6
6
  "repository": {
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@aws-sdk/client-sesv2": "^3.1122.0",
21
- "@tryghost/errors": "^3.4.1",
22
- "@tryghost/tpl": "^2.3.16",
21
+ "@tryghost/errors": "^3.4.3",
22
+ "@tryghost/tpl": "^2.3.17",
23
23
  "nodemailer": "^10.0.0",
24
24
  "nodemailer-mailgun-transport": "^2.1.5",
25
25
  "nodemailer-stub-transport": "^1.1.0"
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "scripts": {
31
31
  "dev": "echo \"Implement me!\"",
32
- "test": "NODE_ENV=testing vitest run --coverage",
32
+ "test": "NODE_ENV=testing vitest run --config ../../vitest.config.ts --root . --coverage",
33
33
  "lint": "oxlint -c ../../.oxlintrc.json .",
34
34
  "posttest": "pnpm run lint"
35
35
  }