emailengine-app 2.77.0 → 2.79.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.
Files changed (189) hide show
  1. package/.github/workflows/test.yml +80 -0
  2. package/.ncurc.js +23 -13
  3. package/.release-please-manifest.json +1 -1
  4. package/CHANGELOG.md +60 -0
  5. package/bin/emailengine.js +1 -1
  6. package/config/e2e.toml +2 -1
  7. package/config/test.toml +2 -1
  8. package/data/google-crawlers.json +1 -1
  9. package/encrypt.js +1 -1
  10. package/lib/account/expected-identity.js +88 -0
  11. package/lib/account.js +145 -61
  12. package/lib/api-reference/format.js +105 -4
  13. package/lib/api-reference/index.js +24 -7
  14. package/lib/api-reference/model.js +148 -21
  15. package/lib/api-reference/schema-tree.js +282 -28
  16. package/lib/api-routes/account-routes.js +99 -36
  17. package/lib/api-routes/behavior-notes.js +3 -0
  18. package/lib/api-routes/blocklist-routes.js +21 -47
  19. package/lib/api-routes/chat-routes.js +10 -12
  20. package/lib/api-routes/delivery-test-routes.js +6 -26
  21. package/lib/api-routes/export-routes.js +2 -0
  22. package/lib/api-routes/gateway-routes.js +52 -11
  23. package/lib/api-routes/license-routes.js +2 -0
  24. package/lib/api-routes/mailbox-routes.js +29 -26
  25. package/lib/api-routes/message-routes.js +27 -21
  26. package/lib/api-routes/oauth2-app-routes.js +11 -29
  27. package/lib/api-routes/operation-impact.js +80 -0
  28. package/lib/api-routes/outbox-routes.js +15 -5
  29. package/lib/api-routes/permission-map.js +397 -0
  30. package/lib/api-routes/route-helpers.js +223 -9
  31. package/lib/api-routes/route-metadata.js +28 -0
  32. package/lib/api-routes/settings-routes.js +30 -25
  33. package/lib/api-routes/stats-routes.js +2 -2
  34. package/lib/api-routes/submit-routes.js +53 -31
  35. package/lib/api-routes/template-routes.js +3 -0
  36. package/lib/api-routes/token-routes.js +319 -33
  37. package/lib/api-routes/webhook-route-routes.js +14 -4
  38. package/lib/append-list.js +3 -14
  39. package/lib/arf-detect.js +23 -1
  40. package/lib/auth-token.js +80 -8
  41. package/lib/autodetect-imap-settings.js +40 -16
  42. package/lib/base32.js +30 -0
  43. package/lib/bounce-detect.js +182 -62
  44. package/lib/consts.js +10 -0
  45. package/lib/db.js +20 -2
  46. package/lib/delivery-error.js +30 -1
  47. package/lib/egress-filter.js +89 -8
  48. package/lib/email-client/base-client.js +35 -113
  49. package/lib/email-client/gmail-client.js +22 -13
  50. package/lib/email-client/imap/listing-diff.js +3 -3
  51. package/lib/email-client/imap/mailbox.js +28 -93
  52. package/lib/email-client/imap/subconnection.js +10 -7
  53. package/lib/email-client/imap/sync-operations.js +46 -46
  54. package/lib/email-client/imap-client.js +39 -28
  55. package/lib/email-client/message-builder.js +15 -15
  56. package/lib/email-client/notification-handler.js +1 -1
  57. package/lib/email-client/outlook/graph-api.js +10 -4
  58. package/lib/email-client/outlook-client.js +54 -55
  59. package/lib/email-client/smtp-pool-manager.js +1 -1
  60. package/lib/enum-descriptions.js +92 -2
  61. package/lib/export.js +2 -2
  62. package/lib/field-usage.js +133 -0
  63. package/lib/gateway.js +2 -2
  64. package/lib/get-raw-email.js +1 -1
  65. package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +3 -3
  66. package/lib/imapproxy/imap-core/lib/commands/id.js +2 -13
  67. package/lib/imapproxy/imap-core/lib/commands/starttls.js +1 -1
  68. package/lib/imapproxy/imap-core/lib/imap-command.js +21 -5
  69. package/lib/imapproxy/imap-core/lib/imap-connection.js +17 -7
  70. package/lib/imapproxy/imap-core/lib/imap-server.js +2 -2
  71. package/lib/imapproxy/imap-server.js +40 -10
  72. package/lib/license-beacon.js +5 -10
  73. package/lib/lists.js +49 -1
  74. package/lib/llm-pre-process.js +6 -6
  75. package/lib/logger.js +5 -1
  76. package/lib/metrics-collector.js +2 -2
  77. package/lib/msgpack.js +62 -0
  78. package/lib/oauth/decode-jwt-payload.js +39 -0
  79. package/lib/oauth/gmail.js +9 -12
  80. package/lib/oauth/mail-ru.js +5 -7
  81. package/lib/oauth/outlook-identity.js +61 -0
  82. package/lib/oauth/outlook.js +9 -9
  83. package/lib/oauth/pubsub/google.js +25 -10
  84. package/lib/oauth/retry-setup.js +38 -0
  85. package/lib/oauth/scope-checker.js +1 -1
  86. package/lib/oauth2-apps.js +224 -295
  87. package/lib/openapi/build-document.js +15 -7
  88. package/lib/openapi/joi-schema.js +20 -0
  89. package/lib/outbox.js +145 -14
  90. package/lib/pre-process.js +9 -9
  91. package/lib/queue-stats.js +49 -0
  92. package/lib/read-env-value.js +37 -0
  93. package/lib/reconnection-manager.js +2 -2
  94. package/lib/rewrite-text-nodes.js +4 -3
  95. package/lib/routes-ui.js +4 -0
  96. package/lib/schemas.js +223 -155
  97. package/lib/settings.js +84 -5
  98. package/lib/sub-script.js +2 -1
  99. package/lib/swagger-options.js +2 -1
  100. package/lib/templates.js +5 -5
  101. package/lib/threads.js +2 -2
  102. package/lib/token-audit-log.js +208 -0
  103. package/lib/token-permission-view.js +219 -0
  104. package/lib/token-permissions.js +172 -0
  105. package/lib/tokens.js +100 -16
  106. package/lib/tools.js +259 -85
  107. package/lib/totp.js +67 -0
  108. package/lib/ui-routes/account-routes.js +122 -26
  109. package/lib/ui-routes/admin-config-routes.js +20 -17
  110. package/lib/ui-routes/admin-entities-routes.js +66 -22
  111. package/lib/ui-routes/auth-routes.js +36 -48
  112. package/lib/ui-routes/export-routes.js +10 -4
  113. package/lib/ui-routes/oauth-config-routes.js +5 -5
  114. package/lib/ui-routes/reference-routes.js +11 -8
  115. package/lib/ui-routes/route-helpers.js +79 -2
  116. package/lib/ui-routes/settings-page.js +1 -1
  117. package/lib/ui-routes/smtp-test-routes.js +1 -1
  118. package/lib/ui-routes/suppression-list-routes.js +294 -0
  119. package/lib/ui-routes/unsubscribe-routes.js +19 -29
  120. package/lib/utils/is-email.js +34 -0
  121. package/lib/utils/network.js +2 -2
  122. package/lib/utils/to-camel-case.js +17 -0
  123. package/lib/web-safe-html.js +1 -1
  124. package/lib/webhook-egress.js +37 -0
  125. package/lib/webhook-routing.js +80 -0
  126. package/lib/webhooks.js +21 -15
  127. package/package.json +26 -27
  128. package/sbom.json +1 -0
  129. package/server.js +81 -42
  130. package/static/css/flyonui.css +1 -1
  131. package/static/css/public.css +3 -0
  132. package/static/css/src/app.tailwind.css +159 -9
  133. package/static/js/app.js +69 -0
  134. package/static/js/reference.js +741 -10
  135. package/static/js/ui.js +43 -0
  136. package/static/licenses.html +698 -1590
  137. package/translations/README.md +64 -0
  138. package/translations/de.mo +0 -0
  139. package/translations/de.po +164 -120
  140. package/translations/en.po +200 -161
  141. package/translations/et.mo +0 -0
  142. package/translations/et.po +163 -120
  143. package/translations/fr.mo +0 -0
  144. package/translations/fr.po +163 -120
  145. package/translations/ja.mo +0 -0
  146. package/translations/ja.po +163 -120
  147. package/translations/messages.pot +94 -64
  148. package/translations/nl.mo +0 -0
  149. package/translations/nl.po +164 -120
  150. package/translations/pl.mo +0 -0
  151. package/translations/pl.po +163 -120
  152. package/views/account-identity-error.hbs +34 -0
  153. package/views/accounts/account.hbs +69 -7
  154. package/views/accounts/browse.hbs +18 -35
  155. package/views/accounts/edit.hbs +1 -0
  156. package/views/accounts/register/imap.hbs +12 -2
  157. package/views/config/logging.hbs +6 -0
  158. package/views/config/oauth/app.hbs +0 -2
  159. package/views/config/security.hbs +13 -0
  160. package/views/layout/app.hbs +29 -5
  161. package/views/oauth-scope-error.hbs +1 -1
  162. package/views/partials/oauth_form.hbs +0 -15
  163. package/views/partials/reference/disclosure.hbs +8 -2
  164. package/views/partials/reference/nav.hbs +36 -9
  165. package/views/partials/reference/operation.hbs +48 -14
  166. package/views/partials/reference/params.hbs +17 -1
  167. package/views/partials/reference/schema-node.hbs +112 -54
  168. package/views/partials/reference/schema-tools.hbs +25 -0
  169. package/views/partials/reference/token-alert.hbs +35 -10
  170. package/views/partials/reference/try-it.hbs +84 -11
  171. package/views/partials/side_menu.hbs +1 -0
  172. package/views/partials/ui/checkbox.hbs +2 -2
  173. package/views/partials/ui/tabs.hbs +7 -1
  174. package/views/reference/index.hbs +1 -1
  175. package/views/reference/token.hbs +4 -0
  176. package/views/suppression-lists/index.hbs +85 -0
  177. package/views/suppression-lists/list.hbs +87 -0
  178. package/views/templates/index.hbs +8 -2
  179. package/views/tokens/index.hbs +31 -4
  180. package/views/tokens/new.hbs +324 -2
  181. package/workers/api.js +299 -140
  182. package/workers/documents.js +46 -26
  183. package/workers/export.js +20 -8
  184. package/workers/imap-proxy.js +2 -2
  185. package/workers/imap.js +13 -7
  186. package/workers/smtp.js +13 -7
  187. package/workers/submit.js +41 -31
  188. package/workers/webhooks.js +60 -37
  189. package/lib/feature-flags.js +0 -48
@@ -34,8 +34,18 @@ const {
34
34
  readEnvValue,
35
35
  failAction
36
36
  } = require('../tools');
37
- const { settingsSchema, accountIdSchema, defaultAccountTypeSchema, ACCOUNT_DISPLAY_STATES, signedFormBlobFields: signedBlobFields } = require('../schemas');
38
- const { formatAccountData, cachedTemplates, ACCOUNT_STATE_DISPLAY } = require('./route-helpers');
37
+ const {
38
+ settingsSchema,
39
+ accountSchemas,
40
+ accountIdSchema,
41
+ defaultAccountTypeSchema,
42
+ ACCOUNT_DISPLAY_STATES,
43
+ signedFormBlobFields: signedBlobFields
44
+ } = require('../schemas');
45
+ const { formatAccountData, cachedTemplates, identityErrorView, ACCOUNT_STATE_DISPLAY } = require('./route-helpers');
46
+ const { webhooks: Webhooks } = require('../webhooks');
47
+ const { describeEffectiveRouting } = require('../webhook-routing');
48
+ const { matchesExpectedIdentity, resolveExpectedIdentity } = require('../account/expected-identity');
39
49
 
40
50
  const { REDIS_PREFIX, DEFAULT_PAGE_SIZE, NONCE_BYTES, MAX_FORM_TTL, MAX_FORM_PROBE_ATTEMPTS } = consts;
41
51
 
@@ -319,7 +329,7 @@ function init(args) {
319
329
  }
320
330
 
321
331
  await request.flash({ type: 'danger', message: `Failed to set up account${errors.account ? `: ${errors.account}` : ''}` });
322
- request.logger.error({ msg: 'Failed to update configuration', err });
332
+ request.logger.debug({ msg: 'Failed to update configuration', err });
323
333
 
324
334
  return h.redirect('/admin/accounts').takeover();
325
335
  },
@@ -358,7 +368,7 @@ function init(args) {
358
368
 
359
369
  accountData.notifyFrom = data.notifyFrom || new Date().toISOString();
360
370
 
361
- for (let key of ['redirectUrl', 'n', 't']) {
371
+ for (let key of ['redirectUrl', 'expectedEmail', 'n', 't']) {
362
372
  if (!accountData._meta) {
363
373
  accountData._meta = {};
364
374
  }
@@ -408,6 +418,8 @@ function init(args) {
408
418
  return h.redirect(authorizeUrl);
409
419
  }
410
420
 
421
+ const expectedEmail = await resolveFormExpectation(data);
422
+
411
423
  return h.view(
412
424
  'accounts/register/imap',
413
425
  {
@@ -416,7 +428,10 @@ function init(args) {
416
428
  data: request.payload.data,
417
429
  sig: request.payload.sig,
418
430
 
419
- email: data.email,
431
+ // A pinned link fixes the address, so prefill from the expectation rather than from the
432
+ // editable hint and mark it read-only. Cosmetic - the endpoints below enforce it.
433
+ email: expectedEmail || data.email,
434
+ emailPinned: !!expectedEmail,
420
435
  name: data.name
421
436
  }
422
437
  },
@@ -476,7 +491,7 @@ function init(args) {
476
491
  },
477
492
 
478
493
  async failAction(request, h, err) {
479
- request.logger.error({ msg: 'Failed to validate request arguments', err });
494
+ request.logger.debug({ msg: 'Failed to validate request arguments', err });
480
495
  let error = Boom.boomify(new Error(request.app.gt.gettext('Invalid request. Check your input and try again.')), { statusCode: 400 });
481
496
  if (err.code) {
482
497
  error.output.payload.code = err.code;
@@ -508,7 +523,7 @@ function init(args) {
508
523
  },
509
524
 
510
525
  async failAction(request, h, err) {
511
- request.logger.error({ msg: 'Failed to validate request arguments', err });
526
+ request.logger.debug({ msg: 'Failed to validate request arguments', err });
512
527
  let error = Boom.boomify(new Error(request.app.gt.gettext('Invalid request. Check your input and try again.')), { statusCode: 400 });
513
528
  if (err.code) {
514
529
  error.output.payload.code = err.code;
@@ -656,6 +671,54 @@ function init(args) {
656
671
  return data;
657
672
  };
658
673
 
674
+ // The expectation that applies to a parsed form blob (lib/account/expected-identity.js owns the
675
+ // precedence and the lazy Redis fallback).
676
+ const resolveFormExpectation = data => resolveExpectedIdentity(redis, { account: data.account, blobExpectation: data.expectedEmail });
677
+
678
+ // Expected identity gate for the IMAP arm, mirroring the one the OAuth callback applies in
679
+ // workers/api.js.
680
+ //
681
+ // The evidence here is only the address typed into the form. Working credentials do not prove that
682
+ // the address belongs to the mailbox behind them, so this enforces "the account is registered under
683
+ // the expected address" and nothing stronger - which is exactly what the field documents. Without it
684
+ // the constraint would be trivially sidestepped by choosing the IMAP tab on a form that also offers
685
+ // OAuth2.
686
+ //
687
+ // Returns { expectedEmail, matched } rather than throwing so the caller can name the address that was
688
+ // actually used when it reports the rejection.
689
+ const checkExpectedIdentity = async (data, submittedEmail) => {
690
+ const expectedEmail = await resolveFormExpectation(data);
691
+ return { expectedEmail, matched: !expectedEmail || matchesExpectedIdentity(expectedEmail, [submittedEmail]) };
692
+ };
693
+
694
+ // Stop the flow with a way back rather than a redirect to the calling application: entering the wrong
695
+ // address is correctable, and the hosted form only ever redirects on success. The OAuth arm renders
696
+ // the same view (workers/api.js), differing only in where "try again" points.
697
+ //
698
+ // type=imap keeps the user on the arm they already chose: without it /accounts/new re-asks the
699
+ // provider question and offers OAuth apps they passed over. The signed blob is still unspent (the
700
+ // nonce is claimed only on success), so the link works, and the form it returns to prefills the
701
+ // pinned address read-only.
702
+ const renderIdentityError = (request, h, expectedEmail, actualEmail) =>
703
+ identityErrorView(request, h, {
704
+ expectedEmail,
705
+ actualEmail,
706
+ retryUrl: `/accounts/new?data=${encodeURIComponent(request.payload.data)}&sig=${encodeURIComponent(request.payload.sig)}&type=imap`
707
+ });
708
+
709
+ // have to use HTML redirect, otherwise samesite=strict cookies are not passed on
710
+ const renderRedirect = (request, h, httpRedirectUrl) =>
711
+ h.view(
712
+ 'redirect',
713
+ {
714
+ pageTitleFull: request.app.gt.gettext('Email Account Setup'),
715
+ httpRedirectUrl
716
+ },
717
+ {
718
+ layout: 'public'
719
+ }
720
+ );
721
+
659
722
  server.route({
660
723
  method: 'POST',
661
724
  path: '/accounts/new/imap',
@@ -663,13 +726,20 @@ function init(args) {
663
726
  async handler(request, h) {
664
727
  // Bound outbound autodiscovery per issued blob (shared cap with the connection tester) so a
665
728
  // leaked signed link cannot drive unlimited outbound probes to arbitrary domains.
666
- await authorizeSignedProbe(request.payload, request.app.gt, request.logger);
729
+ const data = await authorizeSignedProbe(request.payload, request.app.gt, request.logger);
730
+
731
+ // Reject a pinned link early, before autodiscovery runs against the submitted domain, so the
732
+ // user finds out before typing a password. The create endpoint below is the authoritative check.
733
+ const { expectedEmail, matched } = await checkExpectedIdentity(data, request.payload.email);
734
+ if (!matched) {
735
+ return renderIdentityError(request, h, expectedEmail, request.payload.email);
736
+ }
667
737
 
668
738
  let serverSettings;
669
739
  try {
670
740
  serverSettings = await autodetectImapSettings(request.payload.email, request.app.gt);
671
741
  } catch (err) {
672
- request.logger.error({ msg: 'Failed to resolve email server settings', email: request.payload.email, err });
742
+ request.logger.debug({ msg: 'Failed to resolve email server settings', email: request.payload.email, err });
673
743
  }
674
744
 
675
745
  let values = Object.assign(
@@ -733,7 +803,7 @@ function init(args) {
733
803
  }
734
804
 
735
805
  await request.flash({ type: 'danger', message: request.app.gt.gettext("Couldn't set up account. Try again.") });
736
- request.logger.error({ msg: 'Failed to process account', err });
806
+ request.logger.debug({ msg: 'Failed to process account', err });
737
807
 
738
808
  // Repopulate the form (crucially the signed data/sig blob) from what was submitted;
739
809
  // without it the hidden inputs render empty and the corrected re-submit fails the
@@ -909,6 +979,13 @@ function init(args) {
909
979
  async handler(request, h) {
910
980
  const data = await parseSignedFormData(redis, request.payload, request.app.gt, { requireNonce: true });
911
981
 
982
+ // Before the nonce claim below, so a rejected attempt does not consume the setup link and the
983
+ // "try again" link on the error page still works.
984
+ const { expectedEmail, matched } = await checkExpectedIdentity(data, request.payload.email);
985
+ if (!matched) {
986
+ return renderIdentityError(request, h, expectedEmail, request.payload.email);
987
+ }
988
+
912
989
  const accountData = {
913
990
  account: data.account || null,
914
991
  name: request.payload.name || data.name,
@@ -946,6 +1023,11 @@ function init(args) {
946
1023
  accountData.subconnections = data.subconnections;
947
1024
  }
948
1025
 
1026
+ if (expectedEmail) {
1027
+ // Pin the account so later setups are checked even from a link that carries no expectation.
1028
+ accountData.expectedEmail = expectedEmail;
1029
+ }
1030
+
949
1031
  const accountObject = new Account({ redis, call, secret: await getSecret() });
950
1032
 
951
1033
  // Claim the single-use nonce BEFORE creating the account so a concurrent double-submit or
@@ -1000,16 +1082,7 @@ function init(args) {
1000
1082
  httpRedirectUrl = `/admin/accounts/${result.account}`;
1001
1083
  }
1002
1084
 
1003
- return h.view(
1004
- 'redirect',
1005
- {
1006
- pageTitleFull: request.app.gt.gettext('Email Account Setup'),
1007
- httpRedirectUrl
1008
- },
1009
- {
1010
- layout: 'public'
1011
- }
1012
- );
1085
+ return renderRedirect(request, h, httpRedirectUrl);
1013
1086
  },
1014
1087
  options: {
1015
1088
  auth: false,
@@ -1033,7 +1106,7 @@ function init(args) {
1033
1106
  }
1034
1107
 
1035
1108
  await request.flash({ type: 'danger', message: request.app.gt.gettext("Couldn't set up account. Try again.") });
1036
- request.logger.error({ msg: 'Failed to process account', err });
1109
+ request.logger.debug({ msg: 'Failed to process account', err });
1037
1110
 
1038
1111
  // Rebuild the re-render values from the SAME schema that just validated the submission
1039
1112
  // (coerces the tri-state checkboxes, strips unknown/prototype keys, drops both plaintext
@@ -1081,7 +1154,7 @@ function init(args) {
1081
1154
  // lookup failure must never break the error re-render (failAction must not throw).
1082
1155
  // Do NOT cache on failure - an exhausted probe cap or transient DNS error should
1083
1156
  // not poison the hint for the whole TTL.
1084
- request.logger.error({ msg: 'Failed to resolve app-password hint for form re-render', err });
1157
+ request.logger.debug({ msg: 'Failed to resolve app-password hint for form re-render', err });
1085
1158
  }
1086
1159
  }
1087
1160
  }
@@ -1290,6 +1363,22 @@ function init(args) {
1290
1363
  };
1291
1364
  }
1292
1365
 
1366
+ const [webhookSettings, webhookRoutesList] = await Promise.all([
1367
+ settings.getMulti('webhooksEnabled', 'webhooks', 'webhookEvents', 'inboxNewOnly', 'webhooksCustomHeaders'),
1368
+ Webhooks.list(0, 1000)
1369
+ ]);
1370
+
1371
+ const webhookRouting = describeEffectiveRouting({
1372
+ webhooksEnabled: webhookSettings.webhooksEnabled,
1373
+ globalWebhooks: webhookSettings.webhooks,
1374
+ accountWebhooks: accountData.webhooks,
1375
+ webhookEvents: webhookSettings.webhookEvents,
1376
+ inboxNewOnly: webhookSettings.inboxNewOnly,
1377
+ globalCustomHeaders: webhookSettings.webhooksCustomHeaders,
1378
+ accountCustomHeaders: accountData.webhooksCustomHeaders,
1379
+ routes: webhookRoutesList.webhooks
1380
+ });
1381
+
1293
1382
  return h.view(
1294
1383
  'accounts/account',
1295
1384
  {
@@ -1336,7 +1425,9 @@ function init(args) {
1336
1425
  t: Date.now()
1337
1426
  }),
1338
1427
 
1339
- showAdvanced: accountData.proxy || accountData.webhooks,
1428
+ showAdvanced: accountData.proxy || accountData.path,
1429
+
1430
+ webhookRouting,
1340
1431
 
1341
1432
  subConnectionInfo,
1342
1433
 
@@ -1386,7 +1477,7 @@ function init(args) {
1386
1477
  return h.redirect('/admin/accounts');
1387
1478
  } catch (err) {
1388
1479
  await request.flash({ type: 'danger', message: `Couldn't delete account. Try again.` });
1389
- request.logger.error({ msg: 'Failed to delete the account', err, account: request.payload.account, remoteAddress: request.app.ip });
1480
+ request.logger.error({ msg: 'Failed to delete the account', err, account: request.params.account, remoteAddress: request.app.ip });
1390
1481
  return h.redirect(`/admin/accounts/${request.params.account}`);
1391
1482
  }
1392
1483
  },
@@ -1418,7 +1509,7 @@ function init(args) {
1418
1509
  async handler(request) {
1419
1510
  let account = request.params.account;
1420
1511
  try {
1421
- request.logger.info({ msg: 'Request reconnect for logging', account });
1512
+ request.logger.info({ msg: 'Requesting account reconnect', account });
1422
1513
  try {
1423
1514
  await call({ cmd: 'reconnect', account });
1424
1515
  } catch (err) {
@@ -1766,6 +1857,9 @@ function init(args) {
1766
1857
  account: request.params.account,
1767
1858
  name: request.payload.name || '',
1768
1859
  email: request.payload.email,
1860
+ // Empty clears the pin (Account.update hdel's it), which is the only way an operator
1861
+ // can unblock a legitimate mailbox migration on a pinned account.
1862
+ expectedEmail: request.payload.expectedEmail || null,
1769
1863
  proxy: request.payload.proxy,
1770
1864
  smtpEhloName: request.payload.smtpEhloName,
1771
1865
  webhooks: request.payload.webhooks
@@ -1921,7 +2015,7 @@ function init(args) {
1921
2015
  }
1922
2016
 
1923
2017
  await request.flash({ type: 'danger', message: `Couldn't save settings. Try again.` });
1924
- request.logger.error({ msg: 'Failed to update configuration', err });
2018
+ request.logger.debug({ msg: 'Failed to update configuration', err });
1925
2019
 
1926
2020
  let accountObject = new Account({ redis, account: request.params.account, call, secret: await getSecret() });
1927
2021
  let accountData = await accountObject.loadAccountData();
@@ -1967,6 +2061,8 @@ function init(args) {
1967
2061
  name: Joi.string().empty('').max(256).example('John Smith').description('Account Name'),
1968
2062
  email: Joi.string().email().required().example('user@example.com').label('Email').description('Your account email'),
1969
2063
 
2064
+ expectedEmail: accountSchemas.expectedEmail,
2065
+
1970
2066
  proxy: settingsSchema.proxyUrl,
1971
2067
  smtpEhloName: settingsSchema.smtpEhloName,
1972
2068
 
@@ -22,7 +22,7 @@ const getSecret = require('../get-secret');
22
22
  const timezonesList = require('timezones-list').default;
23
23
  const { redis, submitQueue, notifyQueue, documentsQueue } = require('../db');
24
24
  const { getByteSize, formatByteSize, getDuration, failAction, readEnvValue, readEnvList, httpAgent } = require('../tools');
25
- const { assertAllowedUrl, normalizePolicy, POLICY_OFF } = require('../egress-filter');
25
+ const { validateWebhookTarget } = require('../webhook-egress');
26
26
  const { sendWebhookRequest } = require('../webhook-request');
27
27
  const { llmPreProcess } = require('../llm-pre-process');
28
28
  const { documentStoreFeatureEnabled } = require('../document-store');
@@ -55,11 +55,6 @@ const MAX_PAYLOAD_TIMEOUT = getDuration(readEnvValue('EENGINE_MAX_PAYLOAD_TIMEOU
55
55
 
56
56
  const ADMIN_ACCESS_ADDRESSES = readEnvList('EENGINE_ADMIN_ACCESS_ADDRESSES');
57
57
 
58
- // Must match the policy the webhooks worker enforces on real deliveries, including the null that
59
- // tells sendWebhookRequest to keep following redirects when the policy is off
60
- const WEBHOOK_EGRESS_POLICY = normalizePolicy(readEnvValue('EENGINE_WEBHOOK_EGRESS_POLICY'));
61
- const validateWebhookTarget = WEBHOOK_EGRESS_POLICY === POLICY_OFF ? null : target => assertAllowedUrl(target, { policy: WEBHOOK_EGRESS_POLICY });
62
-
63
58
  const IMAP_INDEXERS = [
64
59
  {
65
60
  id: 'full',
@@ -386,6 +381,7 @@ function init(args) {
386
381
  schema: {
387
382
  serviceSecret: settingsSchema.serviceSecret,
388
383
  ignoreMailCertErrors: settingsSchema.ignoreMailCertErrors.default(false),
384
+ tokenAuditLog: settingsSchema.tokenAuditLog.default(false),
389
385
 
390
386
  // Following options can only be changed via the UI
391
387
  enableOAuthTokensApi: Joi.boolean()
@@ -397,13 +393,14 @@ function init(args) {
397
393
  },
398
394
 
399
395
  async loadValues() {
400
- const storedValues = await settings.getMulti('serviceSecret', 'disableTokens', 'enableOAuthTokensApi', 'ignoreMailCertErrors');
396
+ const storedValues = await settings.getMulti('serviceSecret', 'disableTokens', 'enableOAuthTokensApi', 'ignoreMailCertErrors', 'tokenAuditLog');
401
397
 
402
398
  return {
403
399
  serviceSecret: storedValues.serviceSecret || null,
404
400
  enableTokens: !storedValues.disableTokens,
405
401
  enableOAuthTokensApi: storedValues.enableOAuthTokensApi || false,
406
- ignoreMailCertErrors: storedValues.ignoreMailCertErrors || false
402
+ ignoreMailCertErrors: storedValues.ignoreMailCertErrors || false,
403
+ tokenAuditLog: storedValues.tokenAuditLog || false
407
404
  };
408
405
  },
409
406
 
@@ -418,7 +415,8 @@ function init(args) {
418
415
  let data = {
419
416
  disableTokens: !request.payload.enableTokens,
420
417
  enableOAuthTokensApi: request.payload.enableOAuthTokensApi,
421
- ignoreMailCertErrors: request.payload.ignoreMailCertErrors
418
+ ignoreMailCertErrors: request.payload.ignoreMailCertErrors,
419
+ tokenAuditLog: request.payload.tokenAuditLog
422
420
  };
423
421
 
424
422
  // Only overwrite the service secret when a non-empty value is provided: an empty
@@ -772,7 +770,7 @@ return true;`
772
770
 
773
771
  return { success: true, models };
774
772
  } catch (err) {
775
- request.logger.error({ msg: 'Failed reloading OpenAI models', err });
773
+ request.logger.warn({ msg: 'Failed to reload OpenAI models', err });
776
774
  return {
777
775
  success: false,
778
776
  error: err.message
@@ -822,7 +820,7 @@ return true;`
822
820
  },
823
821
 
824
822
  async failAction(request, h, err) {
825
- request.logger.error({ msg: 'Failed to process preview', err });
823
+ request.logger.debug({ msg: 'Failed to process preview', err });
826
824
  return h.redirect('/admin').takeover();
827
825
  },
828
826
 
@@ -937,7 +935,10 @@ return true;`
937
935
  // checkbox must render as checked regardless of the stored setting - also on
938
936
  // error re-renders, where the disabled (unsubmitted) field is absent from
939
937
  // the payload
940
- sentryChecked: sentryEnvManaged || !!values.sentryEnabled
938
+ sentryChecked: sentryEnvManaged || !!values.sentryEnabled,
939
+ // reporting was turned on by trial activation, not by the operator; disclosed
940
+ // on the page because saving the form converts it into an explicit choice
941
+ sentryTrialManaged: !sentryEnvManaged && !!(await settings.get('sentryAutoEnabled'))
941
942
  };
942
943
  },
943
944
 
@@ -1088,7 +1089,7 @@ return true;`
1088
1089
  }
1089
1090
  }),
1090
1091
  headers,
1091
- dispatcher: httpAgent.retry,
1092
+ dispatcher: httpAgent.webhook,
1092
1093
  validateTarget: validateWebhookTarget
1093
1094
  });
1094
1095
  duration = Date.now() - start;
@@ -1105,7 +1106,9 @@ return true;`
1105
1106
  duration
1106
1107
  };
1107
1108
  } catch (err) {
1108
- request.logger.error({ msg: 'Failed posting webhook', webhooks, event: 'test', err });
1109
+ // log the parsed URL, not the raw payload value, so embedded basic-auth credentials
1110
+ // stay out of the log
1111
+ request.logger.warn({ msg: 'Failed to post test webhook', webhooks: parsed.toString(), event: 'test', err });
1109
1112
  return {
1110
1113
  success: false,
1111
1114
  target: webhooks,
@@ -1212,7 +1215,7 @@ return true;`
1212
1215
  return h.redirect('/admin/config/license');
1213
1216
  } catch (err) {
1214
1217
  await request.flash({ type: 'danger', message: `Couldn't register license. Check the key and try again.` });
1215
- request.logger.error({ msg: 'Failed to register license key', err });
1218
+ request.logger.warn({ msg: 'Failed to register license key', err });
1216
1219
 
1217
1220
  return h.view(
1218
1221
  'config/license',
@@ -1254,7 +1257,7 @@ return true;`
1254
1257
  }
1255
1258
 
1256
1259
  await request.flash({ type: 'danger', message: `Couldn't register license. Check the key and try again.` });
1257
- request.logger.error({ msg: 'Failed to register license key', err });
1260
+ request.logger.warn({ msg: 'Failed to register license key', err });
1258
1261
 
1259
1262
  return h
1260
1263
  .view(
@@ -1307,7 +1310,7 @@ return true;`
1307
1310
  return h.redirect('/admin/config/license');
1308
1311
  } catch (err) {
1309
1312
  await request.flash({ type: 'danger', message: `Couldn't remove license. Try again.` });
1310
- request.logger.error({ msg: 'Failed to unregister license key', err, token: request.payload.token, remoteAddress: request.app.ip });
1313
+ request.logger.error({ msg: 'Failed to unregister license key', err, remoteAddress: request.app.ip });
1311
1314
  return h.redirect('/admin/config/license');
1312
1315
  }
1313
1316
  },