emailengine-app 2.79.8 → 2.80.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 (182) hide show
  1. package/.github/dependabot.yml +22 -0
  2. package/.github/workflows/test.yml +39 -0
  3. package/.release-please-manifest.json +1 -1
  4. package/CHANGELOG.md +69 -0
  5. package/DOCKER_DEPLOYMENT.md +6 -7
  6. package/Dockerfile +35 -11
  7. package/config/default.toml +7 -2
  8. package/copy-static-files.sh +23 -5
  9. package/data/google-crawlers.json +1 -1
  10. package/encrypt.js +43 -0
  11. package/lib/account/account-state.js +62 -0
  12. package/lib/account.js +60 -3
  13. package/lib/api-routes/account-routes.js +20 -0
  14. package/lib/api-routes/bull-board-routes.js +3 -2
  15. package/lib/api-routes/index.js +1 -1
  16. package/lib/api-routes/route-helpers.js +8 -0
  17. package/lib/api-routes/settings-routes.js +17 -2
  18. package/lib/auth-token.js +73 -2
  19. package/lib/autodetect-imap-settings.js +379 -69
  20. package/lib/cert-handler.js +62 -0
  21. package/lib/consts.js +58 -7
  22. package/lib/db.js +12 -0
  23. package/lib/egress-fetch.js +145 -0
  24. package/lib/email-client/base-client.js +234 -66
  25. package/lib/email-client/credential-errors.js +118 -0
  26. package/lib/email-client/gmail/gmail-api.js +2 -1
  27. package/lib/email-client/gmail-client.js +70 -64
  28. package/lib/email-client/imap/connection-errors.js +52 -0
  29. package/lib/email-client/imap/listing-diff.js +47 -6
  30. package/lib/email-client/imap/mailbox.js +457 -379
  31. package/lib/email-client/imap/subconnection.js +15 -11
  32. package/lib/email-client/imap/sync-operations.js +46 -59
  33. package/lib/email-client/imap-client.js +136 -95
  34. package/lib/email-client/message-builder.js +11 -11
  35. package/lib/email-client/outlook/graph-api.js +2 -1
  36. package/lib/email-client/outlook-client.js +219 -106
  37. package/lib/export.js +35 -2
  38. package/lib/handlebars-helpers.js +129 -0
  39. package/lib/imap-proxy-auth.js +96 -21
  40. package/lib/imapproxy/imap-core/README.md +1 -0
  41. package/lib/imapproxy/imap-core/lib/tls-options.js +5 -46
  42. package/lib/imapproxy/imap-server.js +56 -66
  43. package/lib/lua/h-del-if-equals.lua +39 -0
  44. package/lib/lua/h-set-if-equals.lua +39 -0
  45. package/lib/openapi/index.js +3 -0
  46. package/lib/outbox.js +28 -3
  47. package/lib/rate-limit.js +23 -4
  48. package/lib/routes-ui.js +4 -34
  49. package/lib/schemas.js +42 -3
  50. package/lib/security-headers.js +411 -0
  51. package/lib/sentry.js +36 -4
  52. package/lib/smtp-auth.js +86 -7
  53. package/lib/tls/context.js +376 -0
  54. package/lib/tls/der.js +223 -0
  55. package/lib/tls/provision.js +555 -0
  56. package/lib/tls/self-signed.js +282 -0
  57. package/lib/tls/status.js +431 -0
  58. package/lib/tls/store.js +666 -0
  59. package/lib/tools.js +337 -147
  60. package/lib/ui-routes/account-routes.js +47 -33
  61. package/lib/ui-routes/admin-config-routes.js +22 -1
  62. package/lib/ui-routes/auth-routes.js +16 -1
  63. package/lib/ui-routes/export-routes.js +4 -0
  64. package/lib/ui-routes/internals-routes.js +3 -5
  65. package/lib/ui-routes/mcp-consent-routes.js +7 -0
  66. package/lib/ui-routes/network-config-routes.js +58 -48
  67. package/lib/ui-routes/route-helpers.js +24 -8
  68. package/lib/ui-routes/smtp-test-routes.js +7 -0
  69. package/lib/ui-routes/tls-config-routes.js +581 -0
  70. package/lib/utils/mailbox-path.js +51 -0
  71. package/lib/utils/severity.js +31 -0
  72. package/lib/webhook-egress.js +5 -0
  73. package/package.json +21 -24
  74. package/sbom.json +1 -1
  75. package/server.js +53 -36
  76. package/static/css/flyonui.css +1 -1
  77. package/static/css/src/app.tailwind.css +11 -0
  78. package/static/js/ace/css/ace.css +1462 -0
  79. package/static/js/ace/css/kuroir-1.png +0 -0
  80. package/static/js/ace/css/kuroir-2.png +0 -0
  81. package/static/js/ace/css/main-1.png +0 -0
  82. package/static/js/ace/css/main-10.svg +4 -0
  83. package/static/js/ace/css/main-11.svg +5 -0
  84. package/static/js/ace/css/main-12.svg +4 -0
  85. package/static/js/ace/css/main-13.png +0 -0
  86. package/static/js/ace/css/main-14.png +0 -0
  87. package/static/js/ace/css/main-15.png +0 -0
  88. package/static/js/ace/css/main-16.png +0 -0
  89. package/static/js/ace/css/main-17.png +0 -0
  90. package/static/js/ace/css/main-18.png +0 -0
  91. package/static/js/ace/css/main-19.png +0 -0
  92. package/static/js/ace/css/main-2.png +0 -0
  93. package/static/js/ace/css/main-20.png +0 -0
  94. package/static/js/ace/css/main-21.png +0 -0
  95. package/static/js/ace/css/main-22.png +0 -0
  96. package/static/js/ace/css/main-23.png +0 -0
  97. package/static/js/ace/css/main-24.png +0 -0
  98. package/static/js/ace/css/main-25.svg +1 -0
  99. package/static/js/ace/css/main-26.png +0 -0
  100. package/static/js/ace/css/main-3.png +0 -0
  101. package/static/js/ace/css/main-4.png +0 -0
  102. package/static/js/ace/css/main-5.svg +7 -0
  103. package/static/js/ace/css/main-6.svg +9 -0
  104. package/static/js/ace/css/main-7.svg +7 -0
  105. package/static/js/ace/css/main-8.svg +9 -0
  106. package/static/js/ace/css/main-9.svg +6 -0
  107. package/static/js/ace/css/theme/kuroir.css +78 -0
  108. package/static/js/ace/css/theme/tomorrow_night.css +128 -0
  109. package/static/js/ace/css/theme/tomorrow_night_eighties.css +128 -0
  110. package/static/js/ace/css/theme/xcode.css +106 -0
  111. package/static/js/ace/css/tomorrow_night-1.png +0 -0
  112. package/static/js/ace/css/tomorrow_night-2.png +0 -0
  113. package/static/js/ace/css/tomorrow_night_eighties-1.png +0 -0
  114. package/static/js/ace/css/tomorrow_night_eighties-2.png +0 -0
  115. package/static/js/ace/css/xcode-1.png +0 -0
  116. package/static/js/ace/css/xcode-2.png +0 -0
  117. package/static/js/app.js +34 -0
  118. package/static/js/ee-client.js +256 -102
  119. package/static/js/public.js +13 -2
  120. package/static/js/ui.js +40 -25
  121. package/static/licenses.html +393 -1282
  122. package/static/vendor/simplewebauthn/browser.min.js +2 -2
  123. package/translations/messages.pot +203 -157
  124. package/views/account/login-redirect.hbs +22 -0
  125. package/views/accounts/account.hbs +15 -37
  126. package/views/accounts/browse.hbs +3 -1
  127. package/views/accounts/edit.hbs +1 -1
  128. package/views/accounts/register/imap-server.hbs +1 -1
  129. package/views/config/ai.hbs +1 -1
  130. package/views/config/branding.hbs +2 -2
  131. package/views/config/document-store/chat.hbs +1 -1
  132. package/views/config/document-store/index.hbs +1 -1
  133. package/views/config/imap-proxy.hbs +1 -4
  134. package/views/config/license.hbs +1 -1
  135. package/views/config/mcp.hbs +1 -1
  136. package/views/config/network.hbs +14 -16
  137. package/views/config/oauth/app.hbs +2 -2
  138. package/views/config/service.hbs +1 -1
  139. package/views/config/smtp.hbs +1 -4
  140. package/views/config/tls-upload.hbs +81 -0
  141. package/views/config/tls.hbs +492 -0
  142. package/views/config/webhooks.hbs +2 -2
  143. package/views/error.hbs +4 -2
  144. package/views/internals/index.hbs +1 -1
  145. package/views/layout/app.hbs +3 -11
  146. package/views/mcp/authorize.hbs +1 -1
  147. package/views/partials/ace_assets.hbs +13 -0
  148. package/views/partials/add_account_modal.hbs +1 -1
  149. package/views/partials/address_list.hbs +4 -4
  150. package/views/partials/filter_editor_js.hbs +2 -2
  151. package/views/partials/gateway_js.hbs +1 -1
  152. package/views/partials/oauth_form.hbs +1 -1
  153. package/views/partials/public_theme_init.hbs +1 -1
  154. package/views/partials/side_menu.hbs +1 -0
  155. package/views/partials/template_form.hbs +2 -2
  156. package/views/partials/test_send.hbs +7 -4
  157. package/views/partials/theme_init.hbs +1 -1
  158. package/views/partials/tls_security_card.hbs +25 -53
  159. package/views/partials/ui/alert-banner.hbs +3 -2
  160. package/views/partials/ui/badge.hbs +6 -2
  161. package/views/partials/ui/btn.hbs +5 -2
  162. package/views/partials/ui/details.hbs +2 -2
  163. package/views/partials/webhooks_editor_functions.hbs +1 -1
  164. package/views/reference/redirect.hbs +1 -1
  165. package/views/templates/template.hbs +2 -2
  166. package/views/tokens/new.hbs +1 -1
  167. package/views/unsubscribe.hbs +1 -1
  168. package/views/webhooks/webhook.hbs +2 -2
  169. package/workers/api.js +131 -242
  170. package/workers/export.js +1 -5
  171. package/workers/imap-proxy.js +4 -1
  172. package/workers/imap.js +1 -3
  173. package/workers/smtp.js +59 -83
  174. package/workers/submit.js +6 -12
  175. package/workers/webhooks.js +6 -17
  176. package/static/front/EmailEngine_logo_horiz.png +0 -0
  177. package/static/front/EmailEngine_logo_vert.png +0 -0
  178. package/static/front/index.html +0 -57
  179. package/static/front/logo.png +0 -0
  180. package/static/vendor/handlebars/handlebars.min-v4.7.9.js +0 -29
  181. package/views/partials/tls_security_js.hbs +0 -64
  182. package/views/partials/tls_security_modal.hbs +0 -22
@@ -224,6 +224,14 @@ function maskSecrets(entry) {
224
224
  }
225
225
  }
226
226
 
227
+ // A failed delivery records the target it was aimed at on the webhook route, the account or
228
+ // the settings. The worker stores it with the credentials already stripped, but a flag written
229
+ // by an older release still carries the raw URL - the same one field over from the masked
230
+ // `targetUrl` / `webhooks` beside it, readable by any token that can list webhook routes.
231
+ if (entry.webhookErrorFlag && typeof entry.webhookErrorFlag === 'object' && entry.webhookErrorFlag.url) {
232
+ entry.webhookErrorFlag.url = maskUrlPassword(entry.webhookErrorFlag.url);
233
+ }
234
+
227
235
  return entry;
228
236
  }
229
237
 
@@ -4,7 +4,8 @@ const Joi = require('joi');
4
4
  const { QUEUES_BY_NAME } = require('../db');
5
5
  const settings = require('../settings');
6
6
  const consts = require('../consts');
7
- const { failAction } = require('../tools');
7
+ const { failAction, maybeReloadTlsCertificates, TLS_MATERIAL_SETTINGS } = require('../tools');
8
+ const { tlsSettingChanged } = require('../tls/store');
8
9
  const { queueStats } = require('../queue-stats');
9
10
  const Boom = require('@hapi/boom');
10
11
  const { handleError, maskSecrets, containsMaskedSecret, isMaskedRoundTrip, MASKED } = require('./route-helpers');
@@ -32,7 +33,7 @@ settingsOutputSchema.eventTypes = Joi.array()
32
33
  .label('EventTypesList');
33
34
 
34
35
  async function init(args) {
35
- const { server, notify, CORS_CONFIG } = args;
36
+ const { server, call, notify, CORS_CONFIG } = args;
36
37
 
37
38
  server.route({
38
39
  method: 'GET',
@@ -117,6 +118,8 @@ async function init(args) {
117
118
 
118
119
  async handler(request) {
119
120
  let applied = {};
121
+ // Only the keys whose value actually changed, unlike `applied` - see tlsSettingChanged()
122
+ let tlsChanged = [];
120
123
  try {
121
124
  for (let key of Object.keys(request.payload)) {
122
125
  let value = request.payload[key];
@@ -141,6 +144,10 @@ async function init(args) {
141
144
  await settings.clear('webhookErrorFlag');
142
145
  }
143
146
 
147
+ if (TLS_MATERIAL_SETTINGS.includes(key) && tlsSettingChanged(key, await settings.get(key), value)) {
148
+ tlsChanged.push(key);
149
+ }
150
+
144
151
  await settings.set(key, value);
145
152
  applied[key] = value;
146
153
  }
@@ -154,6 +161,14 @@ async function init(args) {
154
161
  // key fails, the earlier ones are already stored and the other workers still have
155
162
  // to reload for them, or they keep running on settings Redis no longer holds.
156
163
  notify('settings', applied);
164
+
165
+ // What a listener serves is not carried by that broadcast, and no worker acts on
166
+ // it. Until this was here, an instance switched to "self-signed only" through the
167
+ // API went on offering its Let's Encrypt certificate, and a name added to
168
+ // tlsHostnames was answered with the certificate that predates it, until something
169
+ // restarted the workers. Each command reports its own failure, so this cannot mask
170
+ // the error being thrown out of the catch.
171
+ await maybeReloadTlsCertificates(call, request.logger, tlsChanged, { action: 'settings' });
157
172
  }
158
173
 
159
174
  return { updated: Object.keys(applied) };
package/lib/auth-token.js CHANGED
@@ -12,6 +12,7 @@ const tokenPermissions = require('./token-permissions');
12
12
  const tokenAuditLog = require('./token-audit-log');
13
13
  const { SURFACE_GRANTS } = require('./api-routes/permission-map');
14
14
  const { matchIp } = require('./utils/network');
15
+ const { checkRateLimit, peekRateLimit } = require('./rate-limit');
15
16
 
16
17
  // Reason-specific denial messages, shared verbatim by both auth handlers. The
17
18
  // generic "failed to authenticate" fallback and any protocol-specific error
@@ -20,9 +21,72 @@ const REASON_MESSAGES = {
20
21
  username: 'Access denied, invalid username',
21
22
  scope: 'Access denied, invalid scope',
22
23
  ip: 'Access denied, traffic not accepted from this IP',
23
- permissions: 'Access denied, token permissions do not allow this'
24
+ permissions: 'Access denied, token permissions do not allow this',
25
+ limited: 'Too many failed authentication attempts, try again later'
24
26
  };
25
27
 
28
+ // Failed logins a client address may accumulate against one username before the surface stops
29
+ // answering that pair for the rest of the window. The guard exists for the shared server
30
+ // password, which is operator-chosen with no entropy requirement and was guessable at the full
31
+ // speed of a Redis lookup; the 64-hex API tokens are not guessable at any rate this allows.
32
+ //
33
+ // Keyed on address AND username on purpose. The submission surfaces are typically driven by one
34
+ // application host sending for many accounts, and a single stale credential in that host's
35
+ // configuration must not lock its other accounts out. The username buys an attacker nothing:
36
+ // a guess needs a real account id either way, and each id they know only adds one more budget.
37
+ //
38
+ // Only failures count. A busy sender authenticating on every connection would exhaust an
39
+ // attempt-based budget by itself.
40
+ const AUTH_FAILURE_LIMIT = 20;
41
+ const AUTH_FAILURE_WINDOW = 5 * 60; // seconds
42
+
43
+ const authFailureKey = (remoteAddress, account) => `auth:fail:${remoteAddress || 'unknown'}:${account || ''}`;
44
+
45
+ /**
46
+ * Runs a credential check under the client's failed-login budget.
47
+ *
48
+ * Looks before the attempt (a peek, so an accepted login spends nothing) and records only a
49
+ * refusal. Everything `attempt` throws counts as one: the caller decides what belongs inside
50
+ * the budget by what it puts in the function, so a refusal that is about the account rather
51
+ * than the credential (an API-only account on the IMAP proxy) is left outside it.
52
+ *
53
+ * @param {Object} client
54
+ * @param {String} client.remoteAddress - client IP
55
+ * @param {String} client.account - username the client is authenticating as
56
+ * @param {Function} attempt - async () => result; the credential check
57
+ * @param {Function} limitedError - () => Error; the protocol-specific refusal for a spent budget
58
+ * @returns {Promise<*>} whatever `attempt` resolves with
59
+ */
60
+ async function withAuthFailureBudget({ remoteAddress, account }, attempt, limitedError) {
61
+ const key = authFailureKey(remoteAddress, account);
62
+
63
+ let limit = await peekRateLimit(key, AUTH_FAILURE_LIMIT, AUTH_FAILURE_WINDOW);
64
+ if (!limit.success) {
65
+ logger.warn({
66
+ msg: 'Refusing authentication attempt, failure limit reached',
67
+ remoteAddress,
68
+ account,
69
+ count: limit.count,
70
+ allowed: limit.allowed,
71
+ ttlReset: limit.ttlReset
72
+ });
73
+ throw limitedError();
74
+ }
75
+
76
+ try {
77
+ return await attempt();
78
+ } catch (err) {
79
+ // Never masks the refusal: a counter that could not be written is logged, and the
80
+ // client still gets the error the attempt raised
81
+ try {
82
+ await checkRateLimit(key, 1, AUTH_FAILURE_LIMIT, AUTH_FAILURE_WINDOW);
83
+ } catch (recordErr) {
84
+ logger.error({ msg: 'Failed to record authentication failure', remoteAddress, account, err: recordErr });
85
+ }
86
+ throw err;
87
+ }
88
+ }
89
+
26
90
  /**
27
91
  * Validates a 64-char hex API token supplied as a server password.
28
92
  *
@@ -152,4 +216,11 @@ async function validateAuthToken({ password, account, requiredScope, remoteAddre
152
216
  return { authenticated: true, reason: null };
153
217
  }
154
218
 
155
- module.exports = { validateAuthToken, REASON_MESSAGES };
219
+ module.exports = {
220
+ validateAuthToken,
221
+ withAuthFailureBudget,
222
+ authFailureKey,
223
+ AUTH_FAILURE_LIMIT,
224
+ AUTH_FAILURE_WINDOW,
225
+ REASON_MESSAGES
226
+ };