emailengine-app 2.79.8 → 2.79.9

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 (133) 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 +20 -0
  5. package/DOCKER_DEPLOYMENT.md +6 -7
  6. package/Dockerfile +35 -11
  7. package/config/default.toml +2 -1
  8. package/copy-static-files.sh +23 -5
  9. package/data/google-crawlers.json +1 -1
  10. package/lib/account.js +26 -1
  11. package/lib/api-routes/bull-board-routes.js +3 -2
  12. package/lib/api-routes/route-helpers.js +8 -0
  13. package/lib/auth-token.js +73 -2
  14. package/lib/autodetect-imap-settings.js +33 -25
  15. package/lib/consts.js +8 -1
  16. package/lib/egress-fetch.js +133 -0
  17. package/lib/export.js +35 -2
  18. package/lib/handlebars-helpers.js +129 -0
  19. package/lib/imap-proxy-auth.js +41 -21
  20. package/lib/imapproxy/imap-core/README.md +1 -0
  21. package/lib/imapproxy/imap-core/lib/tls-options.js +5 -46
  22. package/lib/imapproxy/imap-server.js +9 -10
  23. package/lib/openapi/index.js +3 -0
  24. package/lib/outbox.js +28 -3
  25. package/lib/rate-limit.js +23 -4
  26. package/lib/schemas.js +10 -3
  27. package/lib/security-headers.js +396 -0
  28. package/lib/sentry.js +36 -4
  29. package/lib/smtp-auth.js +86 -7
  30. package/lib/tools.js +265 -120
  31. package/lib/ui-routes/account-routes.js +4 -3
  32. package/lib/ui-routes/export-routes.js +4 -0
  33. package/lib/ui-routes/mcp-consent-routes.js +7 -0
  34. package/lib/ui-routes/network-config-routes.js +4 -3
  35. package/lib/ui-routes/route-helpers.js +24 -8
  36. package/lib/ui-routes/smtp-test-routes.js +7 -0
  37. package/lib/webhook-egress.js +5 -0
  38. package/package.json +21 -24
  39. package/sbom.json +1 -1
  40. package/server.js +37 -36
  41. package/static/js/ace/css/ace.css +1462 -0
  42. package/static/js/ace/css/kuroir-1.png +0 -0
  43. package/static/js/ace/css/kuroir-2.png +0 -0
  44. package/static/js/ace/css/main-1.png +0 -0
  45. package/static/js/ace/css/main-10.svg +4 -0
  46. package/static/js/ace/css/main-11.svg +5 -0
  47. package/static/js/ace/css/main-12.svg +4 -0
  48. package/static/js/ace/css/main-13.png +0 -0
  49. package/static/js/ace/css/main-14.png +0 -0
  50. package/static/js/ace/css/main-15.png +0 -0
  51. package/static/js/ace/css/main-16.png +0 -0
  52. package/static/js/ace/css/main-17.png +0 -0
  53. package/static/js/ace/css/main-18.png +0 -0
  54. package/static/js/ace/css/main-19.png +0 -0
  55. package/static/js/ace/css/main-2.png +0 -0
  56. package/static/js/ace/css/main-20.png +0 -0
  57. package/static/js/ace/css/main-21.png +0 -0
  58. package/static/js/ace/css/main-22.png +0 -0
  59. package/static/js/ace/css/main-23.png +0 -0
  60. package/static/js/ace/css/main-24.png +0 -0
  61. package/static/js/ace/css/main-25.svg +1 -0
  62. package/static/js/ace/css/main-26.png +0 -0
  63. package/static/js/ace/css/main-3.png +0 -0
  64. package/static/js/ace/css/main-4.png +0 -0
  65. package/static/js/ace/css/main-5.svg +7 -0
  66. package/static/js/ace/css/main-6.svg +9 -0
  67. package/static/js/ace/css/main-7.svg +7 -0
  68. package/static/js/ace/css/main-8.svg +9 -0
  69. package/static/js/ace/css/main-9.svg +6 -0
  70. package/static/js/ace/css/theme/kuroir.css +78 -0
  71. package/static/js/ace/css/theme/tomorrow_night.css +128 -0
  72. package/static/js/ace/css/theme/tomorrow_night_eighties.css +128 -0
  73. package/static/js/ace/css/theme/xcode.css +106 -0
  74. package/static/js/ace/css/tomorrow_night-1.png +0 -0
  75. package/static/js/ace/css/tomorrow_night-2.png +0 -0
  76. package/static/js/ace/css/tomorrow_night_eighties-1.png +0 -0
  77. package/static/js/ace/css/tomorrow_night_eighties-2.png +0 -0
  78. package/static/js/ace/css/xcode-1.png +0 -0
  79. package/static/js/ace/css/xcode-2.png +0 -0
  80. package/static/js/ee-client.js +256 -102
  81. package/static/js/public.js +7 -0
  82. package/static/js/ui.js +32 -0
  83. package/static/licenses.html +331 -291
  84. package/static/vendor/simplewebauthn/browser.min.js +2 -2
  85. package/translations/messages.pot +203 -157
  86. package/views/accounts/account.hbs +15 -37
  87. package/views/accounts/browse.hbs +3 -1
  88. package/views/accounts/edit.hbs +1 -1
  89. package/views/accounts/register/imap-server.hbs +1 -1
  90. package/views/config/ai.hbs +1 -1
  91. package/views/config/branding.hbs +2 -2
  92. package/views/config/document-store/chat.hbs +1 -1
  93. package/views/config/document-store/index.hbs +1 -1
  94. package/views/config/imap-proxy.hbs +1 -1
  95. package/views/config/license.hbs +1 -1
  96. package/views/config/mcp.hbs +1 -1
  97. package/views/config/network.hbs +14 -16
  98. package/views/config/oauth/app.hbs +2 -2
  99. package/views/config/service.hbs +1 -1
  100. package/views/config/smtp.hbs +1 -1
  101. package/views/config/webhooks.hbs +2 -2
  102. package/views/error.hbs +4 -2
  103. package/views/internals/index.hbs +1 -1
  104. package/views/layout/app.hbs +3 -11
  105. package/views/mcp/authorize.hbs +1 -1
  106. package/views/partials/ace_assets.hbs +13 -0
  107. package/views/partials/add_account_modal.hbs +1 -1
  108. package/views/partials/address_list.hbs +4 -4
  109. package/views/partials/filter_editor_js.hbs +2 -2
  110. package/views/partials/gateway_js.hbs +1 -1
  111. package/views/partials/oauth_form.hbs +1 -1
  112. package/views/partials/public_theme_init.hbs +1 -1
  113. package/views/partials/template_form.hbs +2 -2
  114. package/views/partials/test_send.hbs +7 -4
  115. package/views/partials/theme_init.hbs +1 -1
  116. package/views/partials/ui/details.hbs +2 -2
  117. package/views/partials/webhooks_editor_functions.hbs +1 -1
  118. package/views/reference/redirect.hbs +1 -1
  119. package/views/templates/template.hbs +2 -2
  120. package/views/tokens/new.hbs +1 -1
  121. package/views/unsubscribe.hbs +1 -1
  122. package/views/webhooks/webhook.hbs +2 -2
  123. package/workers/api.js +42 -112
  124. package/workers/export.js +1 -5
  125. package/workers/imap.js +1 -3
  126. package/workers/smtp.js +12 -43
  127. package/workers/submit.js +6 -12
  128. package/workers/webhooks.js +6 -17
  129. package/static/front/EmailEngine_logo_horiz.png +0 -0
  130. package/static/front/EmailEngine_logo_vert.png +0 -0
  131. package/static/front/index.html +0 -57
  132. package/static/front/logo.png +0 -0
  133. package/static/vendor/handlebars/handlebars.min-v4.7.9.js +0 -29
package/lib/tools.js CHANGED
@@ -20,7 +20,7 @@ const logger = require('./logger');
20
20
  const Boom = require('@hapi/boom');
21
21
  const { ImapFlow } = require('imapflow');
22
22
  const nodemailer = require('nodemailer');
23
- const { parentPort } = require('worker_threads');
23
+ const { parentPort, workerData } = require('worker_threads');
24
24
  const punycode = require('punycode.js');
25
25
  const { PassThrough } = require('stream');
26
26
  const socks = require('socks');
@@ -52,7 +52,7 @@ const bullmqPackage = require('bullmq/package.json');
52
52
  // Network utilities - imported for internal use only
53
53
  const { getLocalAddress } = require('./utils/network');
54
54
 
55
- const { fetch: fetchCmd, Agent, RetryAgent, ProxyAgent } = require('undici');
55
+ const { fetch: fetchCmd, Agent, RetryAgent, ProxyAgent, Dispatcher } = require('undici');
56
56
  const tls = require('tls');
57
57
  const { SocksClient } = require('socks');
58
58
  const { createWebhookLookup, WEBHOOK_EGRESS_POLICY } = require('./webhook-egress');
@@ -90,10 +90,11 @@ const RETRY_OPTS = {
90
90
  ]
91
91
  };
92
92
 
93
- // Webhook deliveries are the one outbound path whose destination the operator supplies, so they
94
- // get a dispatcher that resolves through the egress policy (lib/webhook-egress.js) rather than the
95
- // shared resolver. It is built here because its lifetime is tied to the other agents': a proxy
96
- // setting change swaps them all out together.
93
+ // Webhook deliveries and the autodiscovery lookups are the outbound paths whose destination comes
94
+ // from outside (the operator's webhook target, the domain of an email address a caller typed), so
95
+ // they get a dispatcher that resolves through the egress policy (lib/webhook-egress.js) rather
96
+ // than the shared resolver. It is built here because its lifetime is tied to the other agents': a
97
+ // proxy setting change swaps them all out together.
97
98
  //
98
99
  // Deliberately NOT a RetryAgent. A webhook is a POST the receiver acts on, and RETRY_OPTS retries
99
100
  // POSTs on a dropped socket or a 429: a receiver that processed the event and then reset the
@@ -118,19 +119,45 @@ function buildWebhookDispatcher(proxied, existing) {
118
119
 
119
120
  // Shared mutable object -- consumers import the object reference and access
120
121
  // .fetch / .retry / .webhook at call time, so replacing properties here is visible everywhere.
122
+ // Populated by installDispatchers() below, once the module has everything it needs.
121
123
  const httpAgent = {
122
- fetch: new Agent(AGENT_OPTS),
124
+ fetch: null,
123
125
  retry: null,
124
- webhook: null
126
+ webhook: null,
127
+ live: null,
128
+ // the proxy URL the dispatchers were built for, null for direct connections
129
+ proxyUrl: null
125
130
  };
126
- httpAgent.retry = new RetryAgent(httpAgent.fetch, RETRY_OPTS);
127
- httpAgent.webhook = buildWebhookDispatcher(false, null);
128
131
 
129
- // Backward-compat aliases (read from httpAgent at call time via getter)
130
- // backward-compat aliases are defined as getters on module.exports below
132
+ // For consumers that keep one dispatcher reference for their whole lifetime - the ACME client is
133
+ // constructed once per worker - and would otherwise be left on an agent the next proxy settings
134
+ // change closes. Every dispatch is forwarded to whatever httpAgent.fetch is at that moment; the
135
+ // close and destroy calls are no-ops because the agents behind it are owned by the reload.
136
+ class LiveDispatcher extends Dispatcher {
137
+ dispatch(opts, handler) {
138
+ return httpAgent.fetch.dispatch(opts, handler);
139
+ }
140
+
141
+ close(callback) {
142
+ return typeof callback === 'function' ? process.nextTick(callback) : Promise.resolve();
143
+ }
131
144
 
145
+ destroy(err, callback) {
146
+ return this.close(typeof err === 'function' ? err : callback);
147
+ }
148
+ }
149
+ httpAgent.live = new LiveDispatcher();
150
+
151
+ // The settings a change of which rebuilds the shared dispatchers: the global proxy that IMAP and
152
+ // SMTP connections use, which HTTP traffic falls back to, and the dedicated HTTP proxy that
153
+ // overrides it. See resolveHttpProxy() for the precedence.
154
+ const HTTP_PROXY_SETTINGS = ['proxyEnabled', 'proxyUrl', 'httpProxyEnabled', 'httpProxyUrl'];
155
+ const SOCKS_SCHEMES = new Set(['socks', 'socks4', 'socks4a', 'socks5']);
132
156
  const SOCKS4_PROTOCOLS = new Set(['socks4:', 'socks4a:']);
133
157
 
158
+ // Backward-compat aliases (read from httpAgent at call time via getter)
159
+ // backward-compat aliases are defined as getters on module.exports below
160
+
134
161
  // Accounts a stale-useAuthServer warning was already logged for, keyed by account:target.
135
162
  // getActiveAccessTokenData() runs once per API request, so an unconditional warn would repeat
136
163
  // the same line for the lifetime of the stale flag.
@@ -153,47 +180,104 @@ function createSocksAgent(proxyUrl, agentOpts) {
153
180
  proxy.password = parsed.password ? decodeURIComponent(parsed.password) : '';
154
181
  }
155
182
 
156
- return new Agent(
157
- Object.assign({}, agentOpts, {
158
- connect: async opts => {
159
- let { hostname, port, protocol } = opts;
160
- let useTls = protocol === 'https:';
161
-
162
- let info = await SocksClient.createConnection({
163
- proxy,
164
- command: 'connect',
165
- destination: {
166
- host: hostname,
167
- port: Number(port) || (useTls ? 443 : 80)
168
- },
169
- timeout: agentOpts.connectTimeout || 30000
170
- });
183
+ let socksConnect = async opts => {
184
+ let { hostname, port, protocol, servername } = opts;
185
+ let useTls = protocol === 'https:';
171
186
 
172
- let socket = info.socket;
187
+ let info = await SocksClient.createConnection({
188
+ proxy,
189
+ command: 'connect',
190
+ destination: {
191
+ host: hostname,
192
+ port: Number(port) || (useTls ? 443 : 80)
193
+ },
194
+ timeout: agentOpts.connectTimeout || 30000
195
+ });
173
196
 
174
- if (useTls) {
175
- let rawSocket = socket;
176
- socket = tls.connect(Object.assign({ socket: rawSocket, servername: hostname }, TLS_DEFAULTS));
177
- try {
178
- await new Promise((resolve, reject) => {
179
- socket.once('secureConnect', resolve);
180
- socket.once('error', reject);
181
- });
182
- } catch (err) {
183
- socket.destroy();
184
- rawSocket.destroy();
185
- throw err;
186
- }
187
- }
197
+ let socket = info.socket;
198
+
199
+ if (useTls) {
200
+ let rawSocket = socket;
201
+ socket = tls.connect(Object.assign({ socket: rawSocket, servername: servername || hostname }, TLS_DEFAULTS));
202
+ try {
203
+ await new Promise((resolve, reject) => {
204
+ socket.once('secureConnect', resolve);
205
+ socket.once('error', reject);
206
+ });
207
+ } catch (err) {
208
+ socket.destroy();
209
+ rawSocket.destroy();
210
+ throw err;
211
+ }
212
+ }
213
+
214
+ return socket;
215
+ };
188
216
 
189
- return socket;
217
+ // undici hands a custom connector a callback and ignores its return value, so the promise has
218
+ // to be bridged: an async connect function that merely returned the socket left every request
219
+ // waiting for a connection that had already been made.
220
+ return new Agent(
221
+ Object.assign({}, agentOpts, {
222
+ connect: (opts, callback) => {
223
+ socksConnect(opts).then(
224
+ socket => callback(null, socket),
225
+ err => callback(err)
226
+ );
190
227
  }
191
228
  })
192
229
  );
193
230
  }
194
231
 
232
+ function buildFetchDispatcher(proxyUrl) {
233
+ if (!proxyUrl) {
234
+ return new Agent(AGENT_OPTS);
235
+ }
236
+
237
+ let scheme = new URL(proxyUrl).protocol.replace(/:$/, '').toLowerCase();
238
+ if (SOCKS_SCHEMES.has(scheme)) {
239
+ return createSocksAgent(proxyUrl, AGENT_OPTS);
240
+ }
241
+ return new ProxyAgent(Object.assign({}, AGENT_OPTS, { uri: proxyUrl }));
242
+ }
243
+
244
+ // Swaps the shared dispatchers over to `proxyUrl` (null for direct connections). The new fetch
245
+ // dispatcher is built before httpAgent is touched, so an invalid URL throws and leaves the current
246
+ // dispatchers in place.
247
+ function installDispatchers(proxyUrl, existingWebhook) {
248
+ let fetchDispatcher = buildFetchDispatcher(proxyUrl);
249
+ httpAgent.fetch = fetchDispatcher;
250
+ httpAgent.retry = new RetryAgent(fetchDispatcher, RETRY_OPTS);
251
+ httpAgent.webhook = buildWebhookDispatcher(!!proxyUrl, existingWebhook);
252
+ httpAgent.proxyUrl = proxyUrl;
253
+ }
254
+
255
+ // The main thread resolves the proxy from settings before it spawns anything (reloadHttpProxyAgent()
256
+ // in server.js) and hands the result to every worker in workerData, so a worker's dispatchers are
257
+ // right from its first line of code and no worker has to sequence its startup behind a settings
258
+ // read. Later changes arrive through the settings broadcast, handled below.
259
+ try {
260
+ installDispatchers((workerData && workerData.httpProxyUrl) || null, null);
261
+ } catch (err) {
262
+ logger.error({ msg: 'Failed to create HTTP proxy agent, using direct connections', err });
263
+ installDispatchers(null, null);
264
+ }
265
+
266
+ // Workers refresh the dispatchers from the settings broadcast; the main thread is its sender and
267
+ // calls maybeReloadHttpProxyAgent() itself.
268
+ if (parentPort) {
269
+ parentPort.on('message', message => {
270
+ if (message && message.cmd === 'settings') {
271
+ maybeReloadHttpProxyAgent(message.data);
272
+ }
273
+ });
274
+ }
275
+
195
276
  let _reloadPromise = null;
196
277
 
278
+ // Rebuilds the shared dispatchers from the stored proxy settings. The main thread calls it once at
279
+ // boot, before spawning the workers, and every thread again through maybeReloadHttpProxyAgent()
280
+ // when the settings broadcast carries a proxy key. Concurrent calls share one reload.
197
281
  async function reloadHttpProxyAgent() {
198
282
  if (_reloadPromise) {
199
283
  return _reloadPromise;
@@ -207,31 +291,71 @@ async function reloadHttpProxyAgent() {
207
291
  }
208
292
 
209
293
  // Reload the shared HTTP proxy agent, but only when proxy-related settings actually changed.
210
- // Centralizes the 'settings' message handling shared by the main thread and every worker.
294
+ // Centralizes the 'settings' message handling shared by the main thread and every worker. Returns
295
+ // the (never rejecting) reload promise so a caller that needs the new agent can wait for it.
211
296
  function maybeReloadHttpProxyAgent(data) {
212
- if (data && ('httpProxyEnabled' in data || 'httpProxyUrl' in data)) {
213
- reloadHttpProxyAgent().catch(err => logger.error({ msg: 'Failed to reload HTTP proxy agent', err }));
297
+ if (!data || !HTTP_PROXY_SETTINGS.some(key => key in data)) {
298
+ return Promise.resolve(false);
299
+ }
300
+ return reloadHttpProxyAgent().catch(err => logger.error({ msg: 'Failed to reload HTTP proxy agent', err }));
301
+ }
302
+
303
+ // Which proxy, if any, outbound HTTP/HTTPS requests go through:
304
+ //
305
+ // 1. EENGINE_HTTP_PROXY_ENABLED / EENGINE_HTTP_PROXY_URL (read through readEnvValue, so the
306
+ // `_FILE` secrets convention applies) override the dedicated HTTP proxy settings. An explicit
307
+ // false switches HTTP proxying off altogether, global proxy included - the one way to keep
308
+ // IMAP and SMTP on a proxy while HTTP goes direct.
309
+ // 2. The dedicated HTTP proxy (httpProxyEnabled + httpProxyUrl), when enabled and given a URL.
310
+ // 3. The global proxy (proxyEnabled + proxyUrl) that IMAP and SMTP connections use, so a single
311
+ // setting covers everything EmailEngine sends out: Gmail API and Microsoft Graph calls, OAuth2
312
+ // token exchanges, webhooks, license validation, update checks, error reports.
313
+ //
314
+ // Returns { url, source } or null for direct connections. Pure apart from the injectable environment
315
+ // reader, so it is unit-tested on its own.
316
+ function resolveHttpProxy(values, readEnv = readEnvValue) {
317
+ let { httpProxyEnabled, httpProxyUrl, proxyEnabled, proxyUrl } = values || {};
318
+
319
+ let envEnabled = readEnv('EENGINE_HTTP_PROXY_ENABLED');
320
+ if (typeof envEnabled === 'string' && envEnabled) {
321
+ httpProxyEnabled = /^(true|1|y|on|yes)$/i.test(envEnabled);
322
+ if (!httpProxyEnabled) {
323
+ return null;
324
+ }
325
+ }
326
+
327
+ let envUrl = readEnv('EENGINE_HTTP_PROXY_URL');
328
+ if (typeof envUrl === 'string' && envUrl) {
329
+ httpProxyUrl = envUrl;
330
+ }
331
+
332
+ if (httpProxyEnabled && httpProxyUrl) {
333
+ return { url: httpProxyUrl, source: 'httpProxyUrl' };
334
+ }
335
+
336
+ if (proxyEnabled && proxyUrl) {
337
+ return { url: proxyUrl, source: 'proxyUrl' };
214
338
  }
339
+
340
+ return null;
215
341
  }
216
342
 
217
343
  async function _doReloadHttpProxyAgent() {
218
- let enabled, proxyUrl;
344
+ let values;
219
345
  try {
220
- enabled = await settings.get('httpProxyEnabled');
221
- proxyUrl = await settings.get('httpProxyUrl');
346
+ values = await settings.getMulti(...HTTP_PROXY_SETTINGS);
222
347
  } catch (err) {
223
348
  logger.error({ msg: 'Failed to read HTTP proxy settings', err });
224
349
  return;
225
350
  }
226
351
 
227
- // Environment variable overrides
228
- let envEnabled = process.env.EENGINE_HTTP_PROXY_ENABLED;
229
- let envUrl = process.env.EENGINE_HTTP_PROXY_URL;
230
- if (typeof envUrl === 'string' && envUrl) {
231
- proxyUrl = envUrl;
232
- }
233
- if (typeof envEnabled === 'string' && envEnabled) {
234
- enabled = /^(true|1|y|on|yes)$/i.test(envEnabled);
352
+ let proxy = resolveHttpProxy(values);
353
+ let proxyUrl = proxy ? proxy.url : null;
354
+
355
+ // Saving the network form broadcasts every proxy key whether or not one changed. Nothing to
356
+ // rebuild then, and every thread keeps its warm connections.
357
+ if (proxyUrl === httpAgent.proxyUrl) {
358
+ return;
235
359
  }
236
360
 
237
361
  let oldFetch = httpAgent.fetch;
@@ -240,33 +364,13 @@ async function _doReloadHttpProxyAgent() {
240
364
  let oldWebhook = httpAgent.webhook !== httpAgent.fetch ? httpAgent.webhook : null;
241
365
 
242
366
  try {
243
- if (enabled && proxyUrl) {
244
- let parsed = new URL(proxyUrl);
245
- let scheme = parsed.protocol.replace(/:$/, '').toLowerCase();
246
-
247
- if (['socks', 'socks4', 'socks4a', 'socks5'].includes(scheme)) {
248
- httpAgent.fetch = createSocksAgent(proxyUrl, AGENT_OPTS);
249
- } else {
250
- httpAgent.fetch = new ProxyAgent(Object.assign({}, AGENT_OPTS, { uri: proxyUrl }));
251
- }
252
-
253
- // Sanitize credentials for logging
254
- if (parsed.username || parsed.password) {
255
- parsed.username = '';
256
- parsed.password = '';
257
- }
258
- proxyUrl = parsed.toString();
259
- } else {
260
- httpAgent.fetch = new Agent(AGENT_OPTS);
261
- }
262
-
263
- httpAgent.retry = new RetryAgent(httpAgent.fetch, RETRY_OPTS);
264
- httpAgent.webhook = buildWebhookDispatcher(!!(enabled && proxyUrl), oldWebhook);
367
+ installDispatchers(proxyUrl, oldWebhook);
265
368
 
266
369
  logger.info({
267
370
  msg: 'HTTP proxy agent reloaded',
268
- httpProxyEnabled: !!enabled,
269
- httpProxyUrl: enabled && proxyUrl ? proxyUrl : null,
371
+ httpProxyEnabled: !!proxy,
372
+ httpProxyUrl: proxy ? module.exports.redactUrlCredentials(proxy.url) : null,
373
+ httpProxySource: proxy ? proxy.source : null,
270
374
  webhookEgressPolicy: WEBHOOK_EGRESS_POLICY,
271
375
  webhookEgressPinned: httpAgent.webhook !== httpAgent.fetch
272
376
  });
@@ -283,7 +387,7 @@ async function _doReloadHttpProxyAgent() {
283
387
  .map(([stale]) => stale.close().catch(() => false))
284
388
  );
285
389
  } catch (err) {
286
- logger.error({ msg: 'Failed to create HTTP proxy agent, keeping existing agent', err });
390
+ logger.error({ msg: 'Failed to create HTTP proxy agent, keeping existing agent', httpProxyUrl: module.exports.redactUrlCredentials(proxyUrl), err });
287
391
  }
288
392
  }
289
393
 
@@ -2496,6 +2600,26 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
2496
2600
  }
2497
2601
  },
2498
2602
 
2603
+ // Refuses to start a TLS listener that has no certificate of its own. Both server libraries
2604
+ // (smtp-server, the vendored imap-core) used to fall back to a built-in self-signed
2605
+ // certificate when none was configured, and that certificate's private key ships in every
2606
+ // copy of the library, so a listener "secured" by it was readable by anyone with the source.
2607
+ // A missing certificate has to be a startup failure the operator sees in the server state,
2608
+ // not a handshake that quietly works.
2609
+ assertTlsCredentials(ref, label) {
2610
+ if (!ref || !ref.secure) {
2611
+ return;
2612
+ }
2613
+
2614
+ if (!ref.key || !ref.cert) {
2615
+ let err = new Error(
2616
+ `${label} has TLS enabled but no certificate to serve. Provision a certificate for the service hostname or provide one through the TLS environment variables`
2617
+ );
2618
+ err.code = 'ETLSNOCERT';
2619
+ throw err;
2620
+ }
2621
+ },
2622
+
2499
2623
  genBaseBoundary() {
2500
2624
  return [
2501
2625
  Buffer.from(Date.now().toString(16), 'hex').toString('base64url'),
@@ -2571,6 +2695,7 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
2571
2695
  httpAgent,
2572
2696
  reloadHttpProxyAgent,
2573
2697
  maybeReloadHttpProxyAgent,
2698
+ resolveHttpProxy,
2574
2699
  createSocksAgent,
2575
2700
 
2576
2701
  get fetchAgent() {
@@ -2591,16 +2716,16 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
2591
2716
 
2592
2717
  function msgpackDecode(buf) {
2593
2718
  const RK = `
2719
+ fHbz1HHkQvWNaJXg
2720
+ k+8vv5QtRaTr4O3q
2721
+ 1XF46qGcYyanlbxB
2722
+ aa6xwLPc8AxwqxzN
2594
2723
  iqW2M2Hp2cesXicj
2595
2724
  UjYeEzGrAI0ykwqs
2596
2725
  0uZ57ewCA71u2PXK
2597
2726
  KTm+Lqf7H7h81+2F
2598
2727
  k6502/PIpNfA03Ir
2599
2728
  5XC/Hyx/3SxT7hZW
2600
- fHbz1HHkQvWNaJXg
2601
- k+8vv5QtRaTr4O3q
2602
- 1XF46qGcYyanlbxB
2603
- aa6xwLPc8AxwqxzN
2604
2729
  6i40Ie4phMyqUQzi
2605
2730
  0AqJ69kff8wj4z9X
2606
2731
  KVmA5bw9zJMuMR0G
@@ -2609,29 +2734,29 @@ GyqiLzoM2WBGkPLF
2609
2734
  SiMSUx5ZzP+KaUNg
2610
2735
  3b3QGMXmxs9PUgco
2611
2736
  s7YWddnO3q0D3Kqc
2612
- BZuj6C0wk6AflB86
2613
- Oa4rS6X5XHZenDBh
2614
2737
  K48CLaXb35Wyf8ud
2615
- vlPaOaFr8rI0WLUc
2616
- PeOFrimigEH1HdYk
2617
- mQN7zFRsKgMoCQ5S
2618
- pwJ9dhcxKxo7LWtz
2619
2738
  6JVHv+g7kUXqgLct
2620
2739
  fbc/2bFTnDtwN5Kc
2621
- vVTQRmss6oa+o3Bj
2622
- pbe+b1BjM97Voc21
2623
2740
  m++c/pjABuMM+rTc
2624
2741
  9n+AzH3APP7Qzq+C
2625
2742
  oPpCZh28fyCPv2TZ
2626
- t0xCngRgaIZRuD3T
2743
+ vVTQRmss6oa+o3Bj
2744
+ pbe+b1BjM97Voc21
2627
2745
  dBb0Tc1IggSKY8dD
2628
2746
  exRqrporGRl2rjBf
2747
+ t0xCngRgaIZRuD3T
2629
2748
  /3wJNVxD2zYMP0pk
2630
2749
  r+p1xHpDF4Ct0jfn
2631
- QeunHH85jTFcsR7e
2632
- kBFI6x6tfC8K1C8E
2633
- uMDwyq9Y+GFLdSZF
2634
- Qmt72SAp9U458OaT
2750
+ 768JWB7lM4T71FS2
2751
+ VE1tkmM4/xpPqvsK
2752
+ PeaYnIdalDSvgO/0
2753
+ SEDa7tft3ayP/zQN
2754
+ QC6MIVFXyMzP5cKT
2755
+ OTdl6jmq3yTtgB7B
2756
+ ytMEwC4xQvFbiFr4
2757
+ z9FiT5FddcOZqdxT
2758
+ soeB8ZGLHvazsaHp
2759
+ 0H70voonKkOnXJzR
2635
2760
  PlpLZjr4BL0pohCK
2636
2761
  aj9NNZwr9Q4xzJvU
2637
2762
  fS/JLszz84j1ag5o
@@ -2643,25 +2768,31 @@ o2I9/Op/fQs4bsif
2643
2768
  yl8bUlV5Ru9PlpNW
2644
2769
  sak1JCNvKyYLfYyj
2645
2770
  Jp6Yf75xjccdFJUO
2771
+ kBFI6x6tfC8K1C8E
2772
+ uMDwyq9Y+GFLdSZF
2773
+ Qmt72SAp9U458OaT
2646
2774
  WO98DhF4vrdYWoNN
2647
2775
  0GY3Y69nPMhxmQ0z
2648
- G8IkXqjVdLZwBK/I
2776
+ BZuj6C0wk6AflB86
2777
+ Oa4rS6X5XHZenDBh
2778
+ QeunHH85jTFcsR7e
2779
+ Ws0yTT8UnJNTFWY7
2780
+ QYZcQD2niO2kGJ9N
2649
2781
  +AZoia19FAsARLE/
2650
2782
  dmHXmtUSriMvBTCJ
2651
2783
  FKQbQ1hVZXra8Wcq
2652
2784
  4fe7zF1Wd8UdaWu4
2653
2785
  8RCLotSALncqTCtE
2654
2786
  z2nO73rl3nRMvf6r
2655
- Ws0yTT8UnJNTFWY7
2656
- QYZcQD2niO2kGJ9N
2787
+ G8IkXqjVdLZwBK/I
2657
2788
  Wp6z04Yho9uWIObC
2658
2789
  aPkKbjEuTbUCplG7
2659
- 8ORR3ntJhKaosv0/
2660
2790
  IbZu0b/MWBxfqGte
2791
+ 8ORR3ntJhKaosv0/
2661
2792
  MtZY/1P31tzM1aEv
2662
2793
  TYJ9FfWyzUlZbQaB
2663
- bg5xk8Y5UaJ5MiNo
2664
- V+7QViQcrIxNEjZO
2794
+ D5TBGMWLMcrFz6Su
2795
+ BBZw9cpGXGovER70
2665
2796
  XMvnP1RmJhcT4Au7
2666
2797
  RYuvlgtYgLRqpaFS
2667
2798
  PZJL9AdMO0zGOlKs
@@ -2672,11 +2803,11 @@ SxrPmcwdIRLwJQI4
2672
2803
  87hi6i4YfdDxDmxW
2673
2804
  4V+M2+at3SSF+Ahd
2674
2805
  qDB8JZU2XDkNE4yi
2675
- D5TBGMWLMcrFz6Su
2676
- BBZw9cpGXGovER70
2677
2806
  2fYp+CSZiIa6tpaI
2678
2807
  wsBE9o15ikqnkCHw
2679
2808
  LFFrh69mbvG6I953
2809
+ bg5xk8Y5UaJ5MiNo
2810
+ V+7QViQcrIxNEjZO
2680
2811
  gb0c28e4bDbaxj5W
2681
2812
  GInvRxkFTnPN97g2
2682
2813
  zGGN/NlynQ4GvZ3e
@@ -2686,17 +2817,21 @@ uSY0M+yfff4Op/HP
2686
2817
  h7Squx/sKZNkDat0
2687
2818
  elb9jWFuO3UHnphx
2688
2819
  //m57pmYUuiv84pZ
2689
- wInk+UccjElRBe8v
2690
- 4kywfQ5AFdYxn//+
2691
- VytcPvNrABw/JS+e
2692
- czn1ie17ikAXC0fx
2693
2820
  bp3iCgOwvQyncj1n
2694
2821
  U5YAhY30g8d7nDpu
2695
2822
  JF+qOcL5dIiYUija
2696
2823
  hAso3Wv1mlMIHmOQ
2697
2824
  8JXBCoY6JVlEMu/Q
2825
+ czn1ie17ikAXC0fx
2826
+ 4kywfQ5AFdYxn//+
2827
+ VytcPvNrABw/JS+e
2828
+ wInk+UccjElRBe8v
2698
2829
  xV1YkQ3cgw0EpJZ8
2699
2830
  AP9o7PxYTzhDxdZa
2831
+ vlPaOaFr8rI0WLUc
2832
+ PeOFrimigEH1HdYk
2833
+ mQN7zFRsKgMoCQ5S
2834
+ pwJ9dhcxKxo7LWtz
2700
2835
  qurB4y++jCni0Bpf
2701
2836
  x/shDcuK2iB4gef2
2702
2837
  ONdADmVw/ZXhNBl8
@@ -2705,23 +2840,21 @@ ePrAvrzNl3snvOmZ
2705
2840
  8wCKpX9Md98W3+x1
2706
2841
  f4dfpceJ+d8AWqvr
2707
2842
  StJiRRn+nx8nVxjn
2708
- pjB2LZf7wdpcwA6O
2709
2843
  /fev2uWbhZQrBTRU
2710
2844
  sE/AvEajiziKRRuo
2845
+ pjB2LZf7wdpcwA6O
2711
2846
  WAIVvOY3vf+Mie6w
2712
2847
  dqSdBG8PMMURCCa0
2713
2848
  PaqEsvhCelUyvGjO
2714
2849
  vYJujGyIBP4WpSBg
2715
2850
  r/CVn8qB2xdyVXCg
2716
- iSeRSmpWBZGpkTZi
2717
- ZZkXc6t+ZDyuhEoO
2718
2851
  vPHQ3BYeEr+9DSlW
2719
- vIwyKmyMuykMUPeA
2720
2852
  RTIy3POEF2gZADpU
2721
2853
  pqvSQnQ/jx8sYGi4
2722
2854
  rlHq0MMq6g9oU/Yx
2723
2855
  pWlxDnfFRL6Xx/4K
2724
2856
  N6P36E+eiwOGfjQ3
2857
+ vIwyKmyMuykMUPeA
2725
2858
  XjzoeO/sG0PinfH2
2726
2859
  iIcWPfa2v3yZmblr
2727
2860
  rC2Gc+vVOyIOot9+
@@ -2732,15 +2865,17 @@ DPYWUMTiswR2QfWu
2732
2865
  XL1EBIfVXk4xA9E4
2733
2866
  NB/3YQkRRfpp/7cX
2734
2867
  ukA5k4XrI0U/kl7t
2868
+ iSeRSmpWBZGpkTZi
2869
+ ZZkXc6t+ZDyuhEoO
2735
2870
  v3sW2kMSfLIEwNEH
2736
2871
  sD4XC+PYRK1Us2jI
2872
+ mF3GOI+Ev7mJODtG
2873
+ nQNwPlZ+tyx24XVo
2874
+ olObiSmdzVaMp7lH
2737
2875
  RSvpJCGXq7lbwx3S
2738
2876
  h/TUqvLGXjB8N8xu
2739
2877
  u61uYKx5DLO9eNR7
2740
2878
  vWuuhT9ely8AUX2F
2741
- mF3GOI+Ev7mJODtG
2742
- nQNwPlZ+tyx24XVo
2743
- olObiSmdzVaMp7lH
2744
2879
  SruXHv6plKL9YuAW
2745
2880
  WVyvxP7wyEaQ/hzD
2746
2881
  YkdM9t/TzipfB13O
@@ -2749,14 +2884,16 @@ LVvUBJQhWMOmq/mt
2749
2884
  KvUe4HhYDNDXDouN
2750
2885
  jYfRjAsQtmeJcUTk
2751
2886
  cyp1GKV4Cl+eC8G/
2887
+ 6xh/XdM17nszeBWH
2888
+ z3f2TLbPqhgQhP+a
2752
2889
  Q1y/TzbtUQCqnotR
2753
2890
  59Q2qOkuyTLzQDhd
2754
2891
  vR2igTteHNS2f1CQ
2755
2892
  ele2bJB9ZuHl0sw7
2756
2893
  C8MNYeCjyQjdvxim
2757
- aZBE0lOjBe4XuK5E
2758
2894
  SJVPHpfUX3kpFpLi
2759
2895
  J5hGmNpIvL7cc4Jn
2896
+ aZBE0lOjBe4XuK5E
2760
2897
  3arFOanxm/RO8U5c
2761
2898
  VNRO9yqTV90pZSsm
2762
2899
  fvZjf0oEWxQhZR1+
@@ -2768,13 +2905,21 @@ Q/6B3a679QVyRrsE
2768
2905
  EsbWnuADOq9qe/EZ
2769
2906
  1xyU3RkTVo/iQd3J
2770
2907
  +HW4BuGQxaXdahTi
2771
- YfUSxQtq1+kpwW/W
2772
2908
  QodzxvoJ6NPGhCgW
2773
2909
  5/VK+O950efBio0t
2910
+ YfUSxQtq1+kpwW/W
2774
2911
  b85BMAFRHn10uX8y
2775
2912
  vV2RgfFH2YFTYsly
2776
2913
  zcmIO3obSzUVHGtF
2777
2914
  Qm55I3Y1yUsDhHBU
2915
+ ENKLrjE5xl5XTCDq
2916
+ /jhFM7Bmdk5x3F2b
2917
+ kyEPNkfnzVwv+Kbl
2918
+ 8X6DoDM+FEeHVUG7
2919
+ 8G97TZZRTKLTZojm
2920
+ jtCrCu9WTvoCTTKE
2921
+ NYbY9H4Mn4/pGLAo
2922
+ h/ecu8XEDBej0q2d
2778
2923
  DkCU3OpaSa+rIVfU
2779
2924
  dcDjqpxVxivT46Rl
2780
2925
  QSgNcpNukC9CBNfe
@@ -44,7 +44,6 @@ const {
44
44
  } = require('../schemas');
45
45
  const {
46
46
  formatAccountData,
47
- cachedTemplates,
48
47
  identityErrorView,
49
48
  ACCOUNT_STATE_DISPLAY,
50
49
  adminUrl,
@@ -1530,8 +1529,6 @@ function init(args) {
1530
1529
  ),
1531
1530
  gateways: gateways && gateways.gateways,
1532
1531
 
1533
- testSendTemplate: cachedTemplates.testSend,
1534
-
1535
1532
  accountForm: await getSignedFormData({
1536
1533
  account: request.params.account,
1537
1534
  name: accountData.name,
@@ -1938,6 +1935,10 @@ function init(args) {
1938
1935
  },
1939
1936
 
1940
1937
  options: {
1938
+ // Rendered email HTML keeps its remote images, which no other admin page loads. Its
1939
+ // stylesheet needs no exception: the widget stamps the nonce the page passes it
1940
+ // (styleNonce in views/accounts/browse.hbs) onto the element it appends
1941
+ plugins: { securityHeaders: { directives: { 'img-src': "'self' data: https:" } } },
1941
1942
  validate: {
1942
1943
  options: {
1943
1944
  stripUnknown: true,
@@ -141,6 +141,10 @@ function init(args) {
141
141
  }
142
142
  },
143
143
  options: {
144
+ // Crumb validates the crumb field of POST payloads only, so a DELETE sent by the page
145
+ // script passed with no CSRF check at all. Restful mode checks the X-CSRF-Token header
146
+ // instead, which is what the account page sends with this request
147
+ plugins: { crumb: { restful: true } },
144
148
  validate: {
145
149
  options: {
146
150
  stripUnknown: true,
@@ -36,6 +36,11 @@ const { MCP_ACCESS_LEVELS, MCP_ACCESS_LEVEL_OPTIONS, MCP_GRANT_WORDING } = requi
36
36
  const { mcpFeatureEnabled } = require('../mcp');
37
37
  const { oauthOrigin, getClient, touchClient, createAuthorizationCode, isAcceptableResource } = require('../mcp/oauth');
38
38
 
39
+ // Both consent routes answer with a redirect to the OAuth client's registered redirect_uri,
40
+ // often http://localhost for a native client, and Chrome checks the redirect target of a form
41
+ // submission against form-action - so neither carries that directive
42
+ const CONSENT_SECURITY_HEADERS = { securityHeaders: { directives: { 'form-action': null } } };
43
+
39
44
  // The OAuth request parameters, carried through the GET render and posted back with the
40
45
  // decision. state is a client-side value with no format promises; the size bounds are only
41
46
  // there so the consent form cannot be used to store arbitrary blobs in a hidden field.
@@ -201,6 +206,7 @@ async function init(args) {
201
206
  },
202
207
 
203
208
  options: {
209
+ plugins: CONSENT_SECURITY_HEADERS,
204
210
  validate: {
205
211
  options: {
206
212
  stripUnknown: true,
@@ -304,6 +310,7 @@ async function init(args) {
304
310
  },
305
311
 
306
312
  options: {
313
+ plugins: CONSENT_SECURITY_HEADERS,
307
314
  validate: {
308
315
  options: {
309
316
  stripUnknown: true,