emailengine-app 2.79.0 → 2.79.1

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.
Files changed (50) hide show
  1. package/.release-please-manifest.json +1 -1
  2. package/CHANGELOG.md +39 -0
  3. package/lib/account.js +43 -2
  4. package/lib/api-routes/permission-map.js +4 -0
  5. package/lib/api-routes/route-helpers.js +71 -0
  6. package/lib/api-routes/settings-routes.js +37 -14
  7. package/lib/api-routes/token-routes.js +290 -122
  8. package/lib/arf-detect.js +17 -4
  9. package/lib/bounce-detect.js +28 -17
  10. package/lib/consts.js +6 -0
  11. package/lib/db.js +6 -0
  12. package/lib/email-client/gmail-client.js +4 -7
  13. package/lib/email-client/imap/mailbox.js +35 -35
  14. package/lib/email-client/imap-client.js +49 -2
  15. package/lib/email-client/outlook-client.js +3 -10
  16. package/lib/lua/h-set-new-mark.lua +36 -0
  17. package/lib/message-port-stream.js +84 -1
  18. package/lib/oauth2-apps.js +84 -15
  19. package/lib/openapi/build-document.js +5 -1
  20. package/lib/schemas.js +2 -2
  21. package/lib/settings.js +23 -9
  22. package/lib/token-audit-log.js +32 -9
  23. package/lib/tokens.js +163 -66
  24. package/lib/ui-routes/account-routes.js +13 -6
  25. package/lib/ui-routes/admin-entities-routes.js +52 -17
  26. package/lib/ui-routes/oauth-config-routes.js +7 -7
  27. package/lib/ui-routes/route-helpers.js +28 -1
  28. package/lib/ui-routes/suppression-list-routes.js +14 -9
  29. package/lib/utils/decode-headers.js +42 -0
  30. package/lib/utils/header-map.js +48 -0
  31. package/lib/utils/unsafe-key.js +59 -0
  32. package/lib/webhook-routing.js +6 -2
  33. package/lib/webhooks.js +28 -0
  34. package/package.json +1 -1
  35. package/server.js +39 -17
  36. package/views/accounts/account.hbs +8 -8
  37. package/views/accounts/browse.hbs +1 -1
  38. package/views/accounts/edit.hbs +2 -2
  39. package/views/gateways/edit.hbs +1 -1
  40. package/views/gateways/gateway.hbs +2 -2
  41. package/views/gateways/index.hbs +7 -7
  42. package/views/partials/accounts_table.hbs +7 -7
  43. package/views/suppression-lists/list.hbs +1 -1
  44. package/views/templates/index.hbs +2 -2
  45. package/views/templates/template.hbs +1 -1
  46. package/views/tokens/index.hbs +22 -2
  47. package/views/tokens/new.hbs +10 -3
  48. package/workers/api.js +41 -47
  49. package/workers/imap.js +65 -72
  50. package/workers/webhooks.js +21 -1
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "2.79.0"
2
+ ".": "2.79.1"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.79.1](https://github.com/postalsys/emailengine/compare/v2.79.0...v2.79.1) (2026-08-19)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **admin:** flag webhook routes that can never deliver on the account page ([416f612](https://github.com/postalsys/emailengine/commit/416f612b616380371f825d673c0b80ad0f975924))
9
+ * **admin:** percent-encode an account or gateway ID interpolated into a link ([522d267](https://github.com/postalsys/emailengine/commit/522d2673eeb33c2f9cc85e7faf78550b99afe361))
10
+ * **admin:** percent-encode every ID a redirect interpolates ([d21c2ab](https://github.com/postalsys/emailengine/commit/d21c2ab5d5892fb94e85a2962a2a252fc865a03d))
11
+ * **admin:** probe a listing's accounts in one round trip ([a9a4c8a](https://github.com/postalsys/emailengine/commit/a9a4c8aeeb30b16b09f22e62847bb93671e8e46d))
12
+ * **admin:** stop reporting a suppression-list read failure as a missing list ([bd414a9](https://github.com/postalsys/emailengine/commit/bd414a94e7ff51f3c6cd68241ff3b94c8996ed2d))
13
+ * **downloads:** end a cross-thread transfer when the peer closes the channel ([8875e79](https://github.com/postalsys/emailengine/commit/8875e799b7d2d365822f3666160450e137130673))
14
+ * **downloads:** notice a consumer that closed the channel before the transfer began ([ce295e6](https://github.com/postalsys/emailengine/commit/ce295e6060c556a0223bbc7bce11078513cbd0ae))
15
+ * **downloads:** stop an aborted attachment download from killing the IMAP worker ([f937993](https://github.com/postalsys/emailengine/commit/f937993b47c518683da3137eebcc7188c8bd9f3e))
16
+ * **gmail:** keep prototype-shaped header names from breaking message formatting ([a494f13](https://github.com/postalsys/emailengine/commit/a494f1308f04fd24dc1ce9bceb27a46ca326fa71))
17
+ * **headers:** drop a __proto__ field name when parsing a header block ([fae64fd](https://github.com/postalsys/emailengine/commit/fae64fd5754f8236b51c26f6095df5c81f299a90))
18
+ * **headers:** drop a constructor field name too, and guard the bounced-message map ([b5fcf32](https://github.com/postalsys/emailengine/commit/b5fcf32003d99254e8288ad2c7d330d14d138637))
19
+ * **headers:** drop a prototype-shaped field name the camelCase step re-creates ([77a3beb](https://github.com/postalsys/emailengine/commit/77a3bebaff9ca61de2ebff875cd50cd9648533c6))
20
+ * **imap:** keep a prototype-shaped content subtype from breaking a text fetch ([d90e013](https://github.com/postalsys/emailengine/commit/d90e0131f236a085bf10537f567b267de0a25481))
21
+ * **imap:** release the mailbox lock when a download resolves without a stream ([8513432](https://github.com/postalsys/emailengine/commit/8513432f9968061eb01fef8e90654904ebdce3cf))
22
+ * **imap:** return the connection to its mailbox after a download or text fetch ([33db6a2](https://github.com/postalsys/emailengine/commit/33db6a20ed64112d9f5c446f89abb82fb9f33101))
23
+ * **imap:** return the connection to its mailbox after deleting one ([0cac841](https://github.com/postalsys/emailengine/commit/0cac8418a296b0bea41c646bcaa539b2862eed69))
24
+ * **imap:** return the connection to its mailbox after renaming one ([6014093](https://github.com/postalsys/emailengine/commit/601409377c19f7f16eb9d8d60d88b5b906ecf1b1))
25
+ * **imap:** stop a secondary connection's task from re-selecting the primary mailbox ([d12a046](https://github.com/postalsys/emailengine/commit/d12a046eaa5d9ef584bc8c88778fcfedc3e3d533))
26
+ * **metrics:** derive the Prometheus queue gauges from BullMQ itself ([7968678](https://github.com/postalsys/emailengine/commit/796867886a2d8ba9ad0e8fee8e9d53dea1af5b3d))
27
+ * **oauth2:** harden the legacy app migration and restore the auth-failure alert ([50710be](https://github.com/postalsys/emailengine/commit/50710bebe5b4c108313add39beabe74e6c0dd0f8))
28
+ * **reference:** leave the deprecated token aliases out of the published document ([1ff4697](https://github.com/postalsys/emailengine/commit/1ff46975d47f130289d2cb2702d11cedbf16a6b6))
29
+ * **reports:** drop every prototype-shaped name a camelCased report can carry ([77abf0e](https://github.com/postalsys/emailengine/commit/77abf0ee7b3266de92885e66ae48824598dc822f))
30
+ * **settings:** refuse masked credential values posted back to the settings API ([7e51155](https://github.com/postalsys/emailengine/commit/7e51155641b72f2622d0d6f7c31d94e2b01ef9fa))
31
+ * **settings:** seed the trial Sentry default atomically ([1e276f8](https://github.com/postalsys/emailengine/commit/1e276f8ef0dac49a6c4fe3470fff572f57cfab94))
32
+ * **startup:** name the prepared-settings keys that get ignored ([9e23ceb](https://github.com/postalsys/emailengine/commit/9e23ceb9d20dff5f7c64690f71f307bf427bac59))
33
+ * **tokens:** bind an access token to an account from the create form ([6f4fc93](https://github.com/postalsys/emailengine/commit/6f4fc936ef254710b7bc99582776c6d1700d7195))
34
+ * **tokens:** keep the audit log page size default inside its own range ([c688756](https://github.com/postalsys/emailengine/commit/c6887564e0ef20e9e5c2b4ec4a5560d3eec3fc8d))
35
+ * **tokens:** raise the audit log retention cap and bound the account it stores ([6c8039a](https://github.com/postalsys/emailengine/commit/6c8039a1fb2bc5325a8b815a79b51d4f318a059f))
36
+ * **tokens:** register the pre-2.79 token endpoints as deprecated aliases ([5cb2887](https://github.com/postalsys/emailengine/commit/5cb2887c6c6c94e7b3dd9686f5223ae6b7dafb29))
37
+ * **tokens:** revoke an account's access tokens when the account is deleted ([61c9a17](https://github.com/postalsys/emailengine/commit/61c9a178c8a55b4f869fc8d204755519f48a3e48))
38
+ * **tokens:** show account-bound tokens on the Access Tokens page ([716ca0d](https://github.com/postalsys/emailengine/commit/716ca0dc5a56a9d853c5064f4c059fbefd8b0551))
39
+ * **tokens:** stop a whitespace-only search from reading every record ([eb1f398](https://github.com/postalsys/emailengine/commit/eb1f398f5a99c613e4fe30d5e91a93cd80399603))
40
+ * **webhooks:** log the reason a delivery is skipped ([c34df7d](https://github.com/postalsys/emailengine/commit/c34df7d0fbe1724e2bea8baa1d66ce3e7a3e3f40))
41
+
3
42
  ## [2.79.0](https://github.com/postalsys/emailengine/compare/v2.78.0...v2.79.0) (2026-08-18)
4
43
 
5
44
 
package/lib/account.js CHANGED
@@ -25,7 +25,9 @@ const settings = require('./settings');
25
25
  const { buildRetentionPolicy } = require('./queue-retention');
26
26
  const { isDocumentStoreEnabled, documentStoreFeatureEnabled } = require('./document-store');
27
27
  const redisScanDelete = require('./redis-scan-delete');
28
+ const { extractMultiValues } = require('./redis-operations');
28
29
  const outbox = require('./outbox');
30
+ const tokens = require('./tokens');
29
31
  const { customAlphabet } = require('nanoid');
30
32
  const Lock = require('ioredfour');
31
33
  const { redis } = require('./db');
@@ -1249,7 +1251,6 @@ class Account {
1249
1251
  .unlink(`${REDIS_PREFIX}iar:b:${this.account}`) // bounce list
1250
1252
  .unlink(`${REDIS_PREFIX}iar:s:${this.account}`) // seen messages list
1251
1253
  .unlink(`${REDIS_PREFIX}iaq:${this.account}`) // delayed message queue
1252
- .unlink(`${REDIS_PREFIX}iat:${this.account}`) // access tokens
1253
1254
  .unlink(`${REDIS_PREFIX}iac:${this.account}`) // cache hash
1254
1255
  .unlink(`${REDIS_PREFIX}iap:${this.account}`) // external event notification queue
1255
1256
 
@@ -1268,6 +1269,18 @@ class Account {
1268
1269
 
1269
1270
  let result = await pipeline.exec();
1270
1271
 
1272
+ // The account's access tokens go with it - see tokens.deleteForAccount(), which owns the
1273
+ // account's token index too. Deliberately on this side of the transaction: while the account
1274
+ // record exists a token can still be minted against it, and both mint paths check that
1275
+ // record first, so revoking once it is unlinked closes all but a vanishing window. Best
1276
+ // effort, like the queued messages below - the account still has to go, and anything left
1277
+ // behind stays on the access token listing, marked as bound to a deleted account.
1278
+ try {
1279
+ await tokens.deleteForAccount(this.account);
1280
+ } catch (err) {
1281
+ this.logger.error({ msg: 'Failed to delete the access tokens of an account', account: this.account, err });
1282
+ }
1283
+
1271
1284
  // Results are positional: [0] is the outbox HKEYS, [1] the account key UNLINK. Both indexes
1272
1285
  // move if a command is inserted ahead of them.
1273
1286
  let queuedMessageIds = (result && result[0] && result[0][1]) || [];
@@ -3001,4 +3014,32 @@ async function accountExists(redis, account) {
3001
3014
  return (await redis.hexists(`${REDIS_PREFIX}iad:${account}`, 'account')) === 1;
3002
3015
  }
3003
3016
 
3004
- module.exports = { Account, accountExists };
3017
+ /**
3018
+ * Same question as accountExists(), asked about a list of accounts in one round trip.
3019
+ *
3020
+ * lib/db.js enables no auto-pipelining, so probing a listing page's accounts one at a time is a
3021
+ * socket write each - up to 250 on the admin listings that call this.
3022
+ *
3023
+ * @param {Object} redis - Redis client
3024
+ * @param {Array} accounts - Account IDs to probe
3025
+ * @returns {Promise<Map<String, Boolean>>} keyed by account ID, in the order given
3026
+ */
3027
+ async function accountsExist(redis, accounts) {
3028
+ if (!accounts || !accounts.length) {
3029
+ return new Map();
3030
+ }
3031
+
3032
+ let pipeline = redis.pipeline();
3033
+ for (let account of accounts) {
3034
+ pipeline = pipeline.hexists(`${REDIS_PREFIX}iad:${account}`, 'account');
3035
+ }
3036
+
3037
+ // A pipeline reports a per-command failure in its results rather than rejecting, and
3038
+ // extractMultiValues() reads such an entry as undefined - an account that could not be probed is
3039
+ // not an account that is known to exist
3040
+ let values = extractMultiValues(await pipeline.exec());
3041
+
3042
+ return new Map(accounts.map((account, i) => [account, values[i] === 1]));
3043
+ }
3044
+
3045
+ module.exports = { Account, accountExists, accountsExist };
@@ -293,6 +293,10 @@ const GROUP_ROUTES = {
293
293
  // as the requests in it, and a narrowed token has no business reading its own audit record.
294
294
  'GET /v1/tokens/{token}',
295
295
  'GET /v1/tokens/{token}/log',
296
+ // Deprecated pre-2.79 aliases of the three above (see lib/api-routes/token-routes.js)
297
+ 'POST /v1/token',
298
+ 'DELETE /v1/token/{token}',
299
+ 'GET /v1/tokens/account/{account}',
296
300
 
297
301
  // Returns a live OAuth2 access token for the account: a mail credential in its own right,
298
302
  // which outlives any narrowing on the token that fetched it
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const Boom = require('@hapi/boom');
4
+ const { isDeepStrictEqual } = require('node:util');
4
5
  const tokenPermissions = require('../token-permissions');
5
6
 
6
7
  // Shared helpers for the extracted API route modules under lib/api-routes/.
@@ -226,6 +227,74 @@ function maskSecrets(entry) {
226
227
  return entry;
227
228
  }
228
229
 
230
+ // Compares header lists on the two fields a client round-trips, so an echo check is not thrown
231
+ // off by incidental extra properties on either side
232
+ function normalizedHeaderList(headers) {
233
+ return [].concat(headers || []).map(header => ({ key: (header && header.key) || '', value: (header && header.value) || '' }));
234
+ }
235
+
236
+ /**
237
+ * Whether an incoming value carries the mask maskSecrets() writes into responses where a
238
+ * credential should be.
239
+ *
240
+ * A write-side guard for the masking convention: a masked value passes the joi schemas (it is a
241
+ * well-formed URL / header list), so without this check a read-modify-write client silently
242
+ * replaces the stored credential with the literal mask. Keys outside the two secret lists are
243
+ * never masked on the way out, so they report false.
244
+ *
245
+ * Currently wired into POST /v1/settings only. The account and gateway update routes share the
246
+ * read-side masking but still follow the documented MASK_NOTE contract on writes ("leave the
247
+ * field out of an update rather than writing it back") - closing them the same way is an open
248
+ * follow-up, and needs a shape this helper does not cover yet (the gateway password is a bare
249
+ * masked string, not a URL or header list).
250
+ *
251
+ * @param {String} key - the setting/field name
252
+ * @param {*} value - the incoming value
253
+ * @returns {Boolean} true when the value carries the mask placeholder
254
+ */
255
+ function containsMaskedSecret(key, value) {
256
+ if (URL_SECRET_KEYS.includes(key)) {
257
+ if (!value || typeof value !== 'string') {
258
+ return false;
259
+ }
260
+ let parsed;
261
+ try {
262
+ parsed = new URL(value);
263
+ } catch (err) {
264
+ return false;
265
+ }
266
+ return parsed.username === MASKED || parsed.password === MASKED;
267
+ }
268
+
269
+ if (HEADER_SECRET_KEYS.includes(key)) {
270
+ return Array.isArray(value) && value.some(header => header && typeof header === 'object' && header.value === MASKED);
271
+ }
272
+
273
+ return false;
274
+ }
275
+
276
+ /**
277
+ * Whether an incoming masked value is exactly what a read of the stored value returns - i.e. a
278
+ * read-modify-write client posting back what GET handed it, with this key untouched. Such an echo
279
+ * is not an update at all, so the caller can skip the write instead of refusing it.
280
+ *
281
+ * @param {String} key - the setting/field name
282
+ * @param {*} incoming - the incoming value
283
+ * @param {*} stored - the currently stored value
284
+ * @returns {Boolean} true when the incoming value is the masked echo of the stored one
285
+ */
286
+ function isMaskedRoundTrip(key, incoming, stored) {
287
+ if (URL_SECRET_KEYS.includes(key)) {
288
+ return !!stored && typeof incoming === 'string' && maskUrlPassword(stored) === incoming;
289
+ }
290
+
291
+ if (HEADER_SECRET_KEYS.includes(key)) {
292
+ return Array.isArray(incoming) && isDeepStrictEqual(normalizedHeaderList(maskCustomHeaders(stored)), normalizedHeaderList(incoming));
293
+ }
294
+
295
+ return false;
296
+ }
297
+
229
298
  /**
230
299
  * Refuses a submission that redirects the connection, when the credential making it is narrowed.
231
300
  *
@@ -275,6 +344,8 @@ module.exports = {
275
344
  maskCustomHeaders,
276
345
  maskUrlPassword,
277
346
  maskSecrets,
347
+ containsMaskedSecret,
348
+ isMaskedRoundTrip,
278
349
  assertNoNetworkOverride,
279
350
  MASKED,
280
351
  MASK_NOTE
@@ -6,7 +6,8 @@ const settings = require('../settings');
6
6
  const consts = require('../consts');
7
7
  const { failAction } = require('../tools');
8
8
  const { queueStats } = require('../queue-stats');
9
- const { handleError, maskSecrets } = require('./route-helpers');
9
+ const Boom = require('@hapi/boom');
10
+ const { handleError, maskSecrets, containsMaskedSecret, isMaskedRoundTrip, MASKED } = require('./route-helpers');
10
11
  const { settingsSchema, settingsQuerySchema, apiResponses, ENUM_DESCRIPTIONS } = require('../schemas');
11
12
 
12
13
  // Response variant of the settings schema. Secret values are masked and returned as booleans,
@@ -72,7 +73,7 @@ async function init(args) {
72
73
  },
73
74
  options: {
74
75
  description: 'List specific settings',
75
- notes: 'List setting values for specific keys',
76
+ notes: `List setting values for specific keys. Credentials are masked: the credentials in any proxy or webhook URL and the values of custom webhook headers read back as "${MASKED}", and encrypted secrets are returned as booleans. A masked value is not the stored one - POST /v1/settings skips it when it matches the stored value and refuses it otherwise.`,
76
77
  tags: ['api', 'Settings'],
77
78
 
78
79
  plugins: {
@@ -110,25 +111,47 @@ async function init(args) {
110
111
  path: '/v1/settings',
111
112
 
112
113
  async handler(request) {
113
- let updated = [];
114
- for (let key of Object.keys(request.payload)) {
115
- if (key === 'webhooksEnabled' && !request.payload.webhooksEnabled) {
116
- // clear error message (if exists)
117
- await settings.clear('webhookErrorFlag');
118
- }
114
+ let applied = {};
115
+ try {
116
+ for (let key of Object.keys(request.payload)) {
117
+ let value = request.payload[key];
118
+
119
+ // GET /v1/settings masks stored credentials ("******"), and the masked values
120
+ // pass the schemas here - they are well-formed URLs and header lists - so a
121
+ // read-modify-write client would silently replace the stored credential with
122
+ // the literal mask. The unchanged masked echo of the stored value is skipped
123
+ // as "not an update"; a mask anywhere else is refused, because the credential
124
+ // it stands for cannot be reconstructed.
125
+ if (containsMaskedSecret(key, value)) {
126
+ if (isMaskedRoundTrip(key, value, await settings.get(key))) {
127
+ continue;
128
+ }
129
+ throw Boom.badRequest(
130
+ `The value for "${key}" carries the masked placeholder "${MASKED}" instead of a credential. Send the real value, or leave the key out to keep the stored one`
131
+ );
132
+ }
119
133
 
120
- await settings.set(key, request.payload[key]);
121
- updated.push(key);
134
+ if (key === 'webhooksEnabled' && !value) {
135
+ // clear error message (if exists)
136
+ await settings.clear('webhookErrorFlag');
137
+ }
138
+
139
+ await settings.set(key, value);
140
+ applied[key] = value;
141
+ }
142
+ } catch (err) {
143
+ handleError(request, err);
122
144
  }
123
145
 
124
146
  // Broadcast to all workers (including this one); each reloads its HTTP proxy agent via
125
- // the 'settings' message handler, so no inline reload is needed here.
126
- notify('settings', request.payload);
127
- return { updated };
147
+ // the 'settings' message handler, so no inline reload is needed here. Only the keys
148
+ // that were actually written: a skipped masked echo must not trigger reloads either.
149
+ notify('settings', applied);
150
+ return { updated: Object.keys(applied) };
128
151
  },
129
152
  options: {
130
153
  description: 'Set setting values',
131
- notes: 'Set setting values for specific keys',
154
+ notes: `Set setting values for specific keys. Masked credential values ("${MASKED}") read from GET /v1/settings are not accepted: a masked value that matches the stored one is skipped as unchanged, any other value carrying the mask is refused. Send the real credential, or leave the key out to keep the stored value.`,
132
155
  tags: ['api', 'Settings'],
133
156
 
134
157
  plugins: {