emailengine-app 2.84.2 → 2.86.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.
- package/.ncurc.js +29 -9
- package/.prettierignore +5 -1
- package/.prettierrc.js +2 -0
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +107 -0
- package/Dockerfile +20 -1
- package/ENVIRONMENT.md +139 -0
- package/README.md +2 -2
- package/bin/emailengine.js +434 -408
- package/config/default.toml +2 -0
- package/copy-static-files.sh +41 -14
- package/data/google-crawlers.json +1 -1
- package/data/public_suffix_list.dat +16563 -0
- package/eslint.config.js +81 -99
- package/lib/account-assignment.js +19 -0
- package/lib/account.js +230 -170
- package/lib/api-error-codes.js +49 -0
- package/lib/api-reference/format.js +4 -3
- package/lib/api-reference/model.js +6 -1
- package/lib/api-routes/account-routes.js +255 -38
- package/lib/api-routes/blocklist-routes.js +91 -4
- package/lib/api-routes/delivery-test-routes.js +27 -4
- package/lib/api-routes/export-routes.js +28 -2
- package/lib/api-routes/gateway-routes.js +110 -12
- package/lib/api-routes/index.js +4 -0
- package/lib/api-routes/license-routes.js +2 -2
- package/lib/api-routes/mailbox-routes.js +44 -5
- package/lib/api-routes/message-routes.js +112 -10
- package/lib/api-routes/oauth2-app-routes.js +63 -23
- package/lib/api-routes/outbox-routes.js +97 -52
- package/lib/api-routes/permission-map.js +67 -7
- package/lib/api-routes/scoped-routes.js +74 -0
- package/lib/api-routes/settings-routes.js +34 -6
- package/lib/api-routes/stats-routes.js +5 -1
- package/lib/api-routes/submit-routes.js +337 -309
- package/lib/api-routes/template-routes.js +45 -8
- package/lib/api-routes/token-routes.js +152 -100
- package/lib/api-routes/webhook-delivery-routes.js +262 -0
- package/lib/api-routes/webhook-route-routes.js +132 -6
- package/lib/bounce-detect.js +397 -205
- package/lib/calendar-event.js +81 -1
- package/lib/consts.js +38 -45
- package/lib/db.js +14 -6
- package/lib/delivery-error.js +6 -0
- package/lib/deprecations.js +270 -0
- package/lib/email-client/base-client.js +137 -184
- package/lib/email-client/fallback-poll.js +62 -0
- package/lib/email-client/gmail-client.js +60 -22
- package/lib/email-client/imap/adaptive-idle-store.js +73 -0
- package/lib/email-client/imap/adaptive-idle.js +278 -0
- package/lib/email-client/imap/connection-errors.js +14 -1
- package/lib/email-client/imap/idle-settings.js +31 -5
- package/lib/email-client/imap/listing-diff.js +37 -0
- package/lib/email-client/imap/mailbox.js +372 -242
- package/lib/email-client/imap/subconnection.js +8 -30
- package/lib/email-client/imap/sync-operations.js +220 -127
- package/lib/email-client/imap-client.js +228 -164
- package/lib/email-client/message-builder.js +14 -79
- package/lib/email-client/notification-handler.js +1 -2
- package/lib/email-client/outlook-client.js +372 -338
- package/lib/email-client/smtp-pool-manager.js +16 -13
- package/lib/email-client/sync-state-fields.js +19 -0
- package/lib/encrypt.js +157 -41
- package/lib/enum-descriptions.js +3 -1
- package/lib/env-setting-overrides.js +288 -0
- package/lib/export-worker.js +751 -0
- package/lib/export.js +64 -15
- package/lib/gateway.js +19 -4
- package/lib/get-raw-email.js +25 -107
- package/lib/hapi-request-logger.js +107 -0
- package/lib/health.js +75 -0
- package/lib/imapproxy/imap-core/README.md +6 -5
- package/lib/lock-run.js +119 -0
- package/lib/logger-consts.js +48 -0
- package/lib/logger.js +1 -1
- package/lib/lua/z-head-scores.lua +28 -0
- package/lib/mcp/tools.js +37 -8
- package/lib/network-errors.js +1 -1
- package/lib/node-version.js +24 -0
- package/lib/notify-attachments.js +36 -0
- package/lib/oauth/outlook-mailbox.js +35 -0
- package/lib/oauth/state.js +24 -0
- package/lib/oauth2-apps.js +631 -656
- package/lib/outbox.js +184 -54
- package/lib/parse-message.js +3 -3
- package/lib/pbkdf2-phc.js +1 -1
- package/lib/privileged-settings.js +2 -2
- package/lib/queue-browser/definitions.js +11 -0
- package/lib/queue-browser/index.js +68 -19
- package/lib/queue-job-actions.js +18 -1
- package/lib/queue-retention.js +48 -12
- package/lib/queue-stats.js +11 -2
- package/lib/read-env-value.js +3 -0
- package/lib/redis-memory-warnings.js +99 -0
- package/lib/redis-reconnect.js +29 -0
- package/lib/request-timing.js +23 -0
- package/lib/respawn-backoff.js +35 -0
- package/lib/rewrite-text-nodes.js +19 -59
- package/lib/schemas.js +164 -40
- package/lib/settings.js +6 -2
- package/lib/smtp-auth.js +19 -1
- package/lib/sso.js +1 -1
- package/lib/swagger-options.js +1 -1
- package/lib/thread-diagnostics.js +63 -0
- package/lib/timezones.js +109 -0
- package/lib/tls/provision.js +6 -3
- package/lib/token-audit-log.js +19 -20
- package/lib/token-permission-view.js +7 -6
- package/lib/tools.js +48 -51
- package/lib/totp.js +2 -5
- package/lib/translations.js +1 -2
- package/lib/ui-routes/account-routes.js +475 -454
- package/lib/ui-routes/account-setup.js +99 -0
- package/lib/ui-routes/admin-config-routes.js +152 -100
- package/lib/ui-routes/admin-entities-routes.js +93 -21
- package/lib/ui-routes/auth-routes.js +90 -38
- package/lib/ui-routes/imap-idle-field.js +1 -1
- package/lib/ui-routes/internals-routes.js +5 -0
- package/lib/ui-routes/oauth-config-routes.js +124 -82
- package/lib/ui-routes/outlook-subscription-view.js +1 -1
- package/lib/ui-routes/overridable-fields.js +84 -0
- package/lib/ui-routes/queue-routes.js +8 -5
- package/lib/ui-routes/route-helpers.js +19 -3
- package/lib/ui-routes/settings-page.js +6 -0
- package/lib/ui-routes/tls-config-routes.js +58 -15
- package/lib/utils/back-off.js +82 -0
- package/lib/utils/decode-headers.js +3 -12
- package/lib/utils/filter-empty.js +20 -0
- package/lib/utils/int-setting.js +48 -0
- package/lib/utils/murmurhash3.js +66 -0
- package/lib/utils/public-suffix.js +122 -0
- package/lib/utils/random-id.js +26 -0
- package/lib/utils/tracking-settings.js +35 -0
- package/lib/utils/version.js +74 -0
- package/lib/web-safe-html.js +18 -105
- package/lib/webhook-delivery.js +461 -0
- package/lib/webhook-failures.js +132 -0
- package/lib/webhook-request.js +29 -1
- package/lib/webhook-routing.js +56 -0
- package/lib/webhook-test.js +88 -0
- package/lib/webhooks.js +93 -45
- package/lib/worker-rpc-error.js +2 -1
- package/package.json +37 -38
- package/sbom.json +7902 -1
- package/server.js +784 -518
- package/static/js/ace/ace.js +1 -1
- package/static/licenses.html +225 -1060
- package/translations/messages.pot +62 -63
- package/views/config/ai.hbs +1 -1
- package/views/config/security.hbs +24 -2
- package/views/config/service.hbs +47 -0
- package/views/config/webhooks.hbs +36 -0
- package/views/internals/index.hbs +8 -0
- package/views/partials/queue_retention_note.hbs +12 -8
- package/views/partials/ui/env-managed-alert.hbs +16 -7
- package/views/partials/webhook_form.hbs +1 -1
- package/views/suppression-lists/index.hbs +1 -1
- package/workers/api.js +840 -611
- package/workers/export.js +17 -632
- package/workers/imap.js +13 -0
- package/workers/smtp.js +9 -11
- package/workers/submit.js +1 -1
- package/workers/webhooks.js +18 -448
- package/lib/email-client/outlook-fallback-poll.js +0 -30
package/lib/calendar-event.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// ISO timestamps are the instant the invite means wherever EmailEngine happens to run.
|
|
10
10
|
|
|
11
11
|
const ical = require('ical.js');
|
|
12
|
+
const { filterEmptyObjectValues } = require('./utils/filter-empty');
|
|
12
13
|
|
|
13
14
|
const CALENDAR_CONTENT_TYPES = ['text/calendar', 'application/ics'];
|
|
14
15
|
|
|
@@ -75,4 +76,83 @@ function parseCalendarEvent(content) {
|
|
|
75
76
|
};
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
/**
|
|
80
|
+
* The calendar events of a new message, for the messageNew webhook (`notifyCalendarEvents`).
|
|
81
|
+
* Shared by the IMAP mailbox and the Gmail API and Graph clients, which differ only in how an
|
|
82
|
+
* attachment's content is loaded. text/calendar is read before application/ics, an event seen in
|
|
83
|
+
* both is listed once, and an event without a file name gets invite.ics or event.ics
|
|
84
|
+
* @param {Object[]} attachments - The message's attachments
|
|
85
|
+
* @param {Function} load - async (attachment) => void, sets attachment.content (base64) when it can
|
|
86
|
+
* @param {Object} logger
|
|
87
|
+
* @returns {Promise<Object[]|undefined>} The events, or undefined when there are none
|
|
88
|
+
*/
|
|
89
|
+
async function collectCalendarEvents(attachments, load, logger) {
|
|
90
|
+
const events = new Map();
|
|
91
|
+
|
|
92
|
+
for (const attachment of [...(attachments || [])].sort(sortCalendarAttachments)) {
|
|
93
|
+
if (!CALENDAR_CONTENT_TYPES.includes(attachment.contentType)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (!attachment.content) {
|
|
97
|
+
await load(attachment);
|
|
98
|
+
}
|
|
99
|
+
if (!attachment.content) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const contentBuf = Buffer.from(attachment.content, 'base64');
|
|
104
|
+
let event;
|
|
105
|
+
try {
|
|
106
|
+
event = parseCalendarEvent(contentBuf);
|
|
107
|
+
} catch (err) {
|
|
108
|
+
logger.warn({ msg: 'Failed to parse calendar event', attachment: Object.assign({}, attachment, { content: `${contentBuf.length} bytes` }), err });
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (!event) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (events.has(event.eventId)) {
|
|
116
|
+
const existing = events.get(event.eventId);
|
|
117
|
+
if (attachment.filename && !existing.filename) {
|
|
118
|
+
existing.filename = attachment.filename;
|
|
119
|
+
}
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
events.set(
|
|
124
|
+
event.eventId,
|
|
125
|
+
filterEmptyObjectValues({
|
|
126
|
+
eventId: event.eventId,
|
|
127
|
+
attachment: attachment.id,
|
|
128
|
+
method: attachment.method || event.method || null,
|
|
129
|
+
|
|
130
|
+
summary: event.summary,
|
|
131
|
+
description: event.description,
|
|
132
|
+
timezone: event.timezone,
|
|
133
|
+
startDate: event.startDate,
|
|
134
|
+
endDate: event.endDate,
|
|
135
|
+
organizer: event.organizer,
|
|
136
|
+
|
|
137
|
+
filename: attachment.filename,
|
|
138
|
+
contentType: attachment.contentType,
|
|
139
|
+
encoding: 'base64',
|
|
140
|
+
content: attachment.content
|
|
141
|
+
})
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (!events.size) {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return Array.from(events.values()).map(calendarEvent => {
|
|
150
|
+
if (!calendarEvent.filename) {
|
|
151
|
+
const method = calendarEvent.method && calendarEvent.method.toUpperCase();
|
|
152
|
+
calendarEvent.filename = method === 'CANCEL' || method === 'REQUEST' ? 'invite.ics' : 'event.ics';
|
|
153
|
+
}
|
|
154
|
+
return calendarEvent;
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
module.exports = { CALENDAR_CONTENT_TYPES, sortCalendarAttachments, parseCalendarEvent, collectCalendarEvents };
|
package/lib/consts.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const dotenv = require('dotenv');
|
|
4
|
+
const { readEnvValue } = require('./read-env-value');
|
|
5
|
+
const { REDACTED_LOG_KEYS, TRANSIENT_NETWORK_CODES } = require('./logger-consts');
|
|
4
6
|
|
|
5
7
|
if (!process.env.EE_ENV_LOADED) {
|
|
6
8
|
dotenv.config({ quiet: true });
|
|
@@ -187,7 +189,7 @@ module.exports = {
|
|
|
187
189
|
// separate constant from the live description rather than a reference to it.
|
|
188
190
|
AUTH_FAILURE_DISABLED_LEGACY_DESCRIPTION: 'IMAP was disabled for the account due to exceeding the authentication error threshold',
|
|
189
191
|
|
|
190
|
-
REDIS_PREFIX: ((
|
|
192
|
+
REDIS_PREFIX: ((readEnvValue('EENGINE_REDIS_PREFIX') || '').toString().trim() + ':').replace(/^:/, ''),
|
|
191
193
|
|
|
192
194
|
REDIS_BATCH_DELETE_SIZE: 1000,
|
|
193
195
|
|
|
@@ -207,15 +209,15 @@ module.exports = {
|
|
|
207
209
|
// limits worth worrying about, and certificates signed by an untrusted root - which is also why
|
|
208
210
|
// the default here has to stay production. A build that shipped staging by default would hand
|
|
209
211
|
// every IMAP, SMTP and HTTPS client a certificate it refuses.
|
|
210
|
-
ACME_ENVIRONMENT: (
|
|
211
|
-
ACME_DIRECTORY_URL: (
|
|
212
|
+
ACME_ENVIRONMENT: (readEnvValue('EENGINE_ACME_ENVIRONMENT') || '').toString().trim() || 'emailengine',
|
|
213
|
+
ACME_DIRECTORY_URL: (readEnvValue('EENGINE_ACME_DIRECTORY_URL') || '').toString().trim() || 'https://acme-v02.api.letsencrypt.org/directory',
|
|
212
214
|
|
|
213
215
|
// Exactly one of the two was overridden, which is the combination the paragraph above says
|
|
214
216
|
// cannot work. Derived here, from the same reads the values themselves come from, so it can
|
|
215
217
|
// never disagree with them; lib/cert-handler.js is what reports it, since nothing in the CA's
|
|
216
218
|
// rejection says why every order failed.
|
|
217
219
|
ACME_OVERRIDE_PARTIAL:
|
|
218
|
-
!!(
|
|
220
|
+
!!(readEnvValue('EENGINE_ACME_ENVIRONMENT') || '').toString().trim() !== !!(readEnvValue('EENGINE_ACME_DIRECTORY_URL') || '').toString().trim(),
|
|
219
221
|
|
|
220
222
|
// do not attempt certificate renewal more often than once in 8 hours
|
|
221
223
|
BLOCK_TLS_RENEW: 8 * 3600 * 1000,
|
|
@@ -283,6 +285,15 @@ module.exports = {
|
|
|
283
285
|
|
|
284
286
|
// How many times to retry an email sending before it is considered as failing
|
|
285
287
|
DEFAULT_DELIVERY_ATTEMPTS: 10,
|
|
288
|
+
|
|
289
|
+
// How many attempts a webhook delivery gets, and the first backoff delay between them in ms
|
|
290
|
+
// (it doubles with every attempt). The webhooksDeliveryAttempts and webhooksRetryDelay
|
|
291
|
+
// settings override them
|
|
292
|
+
DEFAULT_WEBHOOK_ATTEMPTS: 10,
|
|
293
|
+
MAX_WEBHOOK_ATTEMPTS: 100,
|
|
294
|
+
DEFAULT_WEBHOOK_RETRY_DELAY: 5000,
|
|
295
|
+
MIN_WEBHOOK_RETRY_DELAY: 1000,
|
|
296
|
+
MAX_WEBHOOK_RETRY_DELAY: 60 * 60 * 1000,
|
|
286
297
|
// The most a caller may ask for, through the API or the X-EE-Delivery-Attempts header of a
|
|
287
298
|
// stored draft or SMTP submission
|
|
288
299
|
MAX_DELIVERY_ATTEMPTS: 100,
|
|
@@ -314,12 +325,12 @@ module.exports = {
|
|
|
314
325
|
|
|
315
326
|
// while we do require a valid cert, the passing requirements are extremely low
|
|
316
327
|
TLS_DEFAULTS: {
|
|
317
|
-
minVersion: (
|
|
318
|
-
minDHSize: Number((
|
|
319
|
-
ciphers: (
|
|
328
|
+
minVersion: (readEnvValue('EENGINE_TLS_MIN_VERSION') || '').toString().trim() || 'TLSv1',
|
|
329
|
+
minDHSize: Number((readEnvValue('EENGINE_TLS_MIN_DH_SIZE') || '').toString().trim()) || 1024,
|
|
330
|
+
ciphers: (readEnvValue('EENGINE_TLS_CIPHERS') || '').toString().trim() || 'DEFAULT@SECLEVEL=0'
|
|
320
331
|
},
|
|
321
332
|
|
|
322
|
-
URL_FETCH_TIMEOUT: Number((
|
|
333
|
+
URL_FETCH_TIMEOUT: Number((readEnvValue('EENGINE_FETCH_TIMEOUT') || '').toString().trim()) || 90 * 1000,
|
|
323
334
|
|
|
324
335
|
// hard limit for subscript execution (does not include waiting for promises)
|
|
325
336
|
SUBSCRIPT_RUNTIME_TIMEOUT: 30 * 1000,
|
|
@@ -351,6 +362,11 @@ module.exports = {
|
|
|
351
362
|
// length would store a string that names no account while claiming to name one.
|
|
352
363
|
MAX_ACCOUNT_ID_LENGTH: 256,
|
|
353
364
|
|
|
365
|
+
// Token audit log bounds when neither the setting nor its environment variable is set
|
|
366
|
+
// (tokenLogEntries / EENGINE_TOKEN_LOG_ENTRIES, tokenLogAge / EENGINE_TOKEN_LOG_AGE)
|
|
367
|
+
TOKEN_LOG_ENTRIES_DEFAULT: 1000,
|
|
368
|
+
TOKEN_LOG_AGE_DEFAULT: 7 * 24 * 3600,
|
|
369
|
+
|
|
354
370
|
// Class names on the collapse marker web-safe HTML wraps quoted thread history in. Part of the
|
|
355
371
|
// output contract - consumers select on them to style or hide the block - so they are defined
|
|
356
372
|
// once here and referenced by both the generator (lib/web-safe-html.js) and the API docs.
|
|
@@ -434,6 +450,16 @@ module.exports = {
|
|
|
434
450
|
// How far back a manual sync of a Graph account may be asked to look (PUT /v1/account/{account}/sync `since`)
|
|
435
451
|
OUTLOOK_SYNC_MAX_LOOKBACK: 30 * 24 * 60 * 60 * 1000, // ms
|
|
436
452
|
|
|
453
|
+
// Bounds for an IMAP IDLE restart interval (imap.maxIdleTime, and what lib/email-client/imap/adaptive-idle.js
|
|
454
|
+
// learns), in milliseconds. Anything shorter than the floor is polling rather than idling, and the
|
|
455
|
+
// RFC 3501 autologout timer is 30 minutes
|
|
456
|
+
IMAP_MAX_IDLE_TIME_MIN: 10 * 1000,
|
|
457
|
+
IMAP_MAX_IDLE_TIME_MAX: 30 * 60 * 1000,
|
|
458
|
+
|
|
459
|
+
// Settings a new message pass reads after the fetch, read together with settings.getMulti(): once
|
|
460
|
+
// per sync pass for IMAP, once per message for the API clients
|
|
461
|
+
NEW_MESSAGE_SETTINGS: ['notifyAttachments', 'notifyAttachmentSize', 'notifyCalendarEvents', 'notifyWebSafeHtml', 'resolveGmailCategories'],
|
|
462
|
+
|
|
437
463
|
// Google Pub/Sub subscription defaults
|
|
438
464
|
GMAIL_PUBSUB_DEFAULT_EXPIRATION_TTL: '2678400s', // 31 days in seconds (Google's default)
|
|
439
465
|
GMAIL_PUBSUB_ACK_DEADLINE_SECONDS: 30,
|
|
@@ -441,22 +467,8 @@ module.exports = {
|
|
|
441
467
|
// error (5xx, 408, 429, network) is retried after each of these delays (ms), about 3.5 hours in all
|
|
442
468
|
CHANGE_EVENT_RETRY_DELAYS: [1, 4, 16, 60, 60, 60].map(minutes => minutes * 60 * 1000),
|
|
443
469
|
|
|
444
|
-
// Transient network error codes that indicate a retry-worthy connection failure
|
|
445
|
-
TRANSIENT_NETWORK_CODES
|
|
446
|
-
'ENOTFOUND',
|
|
447
|
-
'EAI_AGAIN',
|
|
448
|
-
'ETIMEDOUT',
|
|
449
|
-
'ECONNRESET',
|
|
450
|
-
'ECONNREFUSED',
|
|
451
|
-
// no route to the host, such as an IPv6 address on a host without IPv6 connectivity
|
|
452
|
-
'ENETUNREACH',
|
|
453
|
-
'EHOSTUNREACH',
|
|
454
|
-
'UND_ERR_SOCKET',
|
|
455
|
-
'UND_ERR_CONNECT_TIMEOUT',
|
|
456
|
-
'UND_ERR_HEADERS_TIMEOUT',
|
|
457
|
-
// a response body that stalled mid-transfer
|
|
458
|
-
'UND_ERR_BODY_TIMEOUT'
|
|
459
|
-
]),
|
|
470
|
+
// Transient network error codes that indicate a retry-worthy connection failure (lib/logger-consts.js)
|
|
471
|
+
TRANSIENT_NETWORK_CODES,
|
|
460
472
|
|
|
461
473
|
// Error codes meaning "the IMAP connection is gone", as opposed to the command itself failing
|
|
462
474
|
CONNECTION_CLOSING_CODES: new Set(['IMAPConnectionClosing', 'EConnectionClosed', 'NoConnection']),
|
|
@@ -466,27 +478,8 @@ module.exports = {
|
|
|
466
478
|
// `documentStoreEnabled` setting is still on
|
|
467
479
|
LAST_DOCUMENT_STORE_VERSION: '2.81.2',
|
|
468
480
|
|
|
469
|
-
//
|
|
470
|
-
|
|
471
|
-
// each detail context, and `rawPacket` is a TLS-error field that can carry an unparsed
|
|
472
|
-
// credential frame - without these a failed validation writes plaintext passwords, OAuth2
|
|
473
|
-
// client secrets and access tokens into the log, the per-account log store and Sentry.
|
|
474
|
-
// `req.query.access_token` is here because the api-token scheme accepts the credential as a
|
|
475
|
-
// query argument, and hapi-pino logs the parsed query object with every request - so a client
|
|
476
|
-
// using that form wrote a live token into this instance's own request log. The serialized
|
|
477
|
-
// `req.url` is the pathname only (pino-std-serializers reports `req.path`), so the credential
|
|
478
|
-
// reaches the log through the query object and nowhere else.
|
|
479
|
-
REDACTED_LOG_KEYS: [
|
|
480
|
-
'req.headers.authorization',
|
|
481
|
-
'req.headers.cookie',
|
|
482
|
-
'req.query.access_token',
|
|
483
|
-
'err.rawPacket',
|
|
484
|
-
'err._original',
|
|
485
|
-
'err.details[*].context.value',
|
|
486
|
-
// the WHATWG URL parser attaches the string it rejected, and a stored proxy or webhook URL
|
|
487
|
-
// carries its credentials inline
|
|
488
|
-
'err.input'
|
|
489
|
-
],
|
|
481
|
+
// Log paths pino redacts, see lib/logger-consts.js
|
|
482
|
+
REDACTED_LOG_KEYS,
|
|
490
483
|
|
|
491
484
|
generateWebhookTable() {
|
|
492
485
|
let entries = [];
|
package/lib/db.js
CHANGED
|
@@ -9,6 +9,7 @@ const fs = require('fs');
|
|
|
9
9
|
const config = require('@zone-eu/wild-config');
|
|
10
10
|
const pathlib = require('path');
|
|
11
11
|
const redisUrl = require('./redis-url');
|
|
12
|
+
const { reconnectOnErrorReply } = require('./redis-reconnect');
|
|
12
13
|
const { threadId } = require('worker_threads');
|
|
13
14
|
const logger = require('./logger');
|
|
14
15
|
const { readEnvValue } = require('./read-env-value');
|
|
@@ -36,12 +37,13 @@ const REDIS_CONF = Object.assign(
|
|
|
36
37
|
return delay;
|
|
37
38
|
},
|
|
38
39
|
reconnectOnError(err) {
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
// Runs for every error reply, see lib/redis-reconnect.js. Everything other than a
|
|
41
|
+
// failover is the caller's to handle, so only the reconnect itself is logged
|
|
42
|
+
let reconnect = reconnectOnErrorReply(err);
|
|
43
|
+
if (reconnect) {
|
|
44
|
+
logger.warn({ msg: 'Redis replied READONLY, reconnecting', isMainThread, threadId, err });
|
|
45
|
+
}
|
|
46
|
+
return reconnect;
|
|
45
47
|
},
|
|
46
48
|
offlineQueue: true
|
|
47
49
|
},
|
|
@@ -122,6 +124,7 @@ const zExpungeScript = fs.readFileSync(pathlib.join(__dirname, '/lua/z-expunge.l
|
|
|
122
124
|
const zSetScript = fs.readFileSync(pathlib.join(__dirname, 'lua/z-set.lua'), 'utf-8');
|
|
123
125
|
const zGetScript = fs.readFileSync(pathlib.join(__dirname, 'lua/z-get.lua'), 'utf-8');
|
|
124
126
|
const zGetByUidScript = fs.readFileSync(pathlib.join(__dirname, 'lua/z-get-by-uid.lua'), 'utf-8');
|
|
127
|
+
const zHeadScoresScript = fs.readFileSync(pathlib.join(__dirname, 'lua/z-head-scores.lua'), 'utf-8');
|
|
125
128
|
const zGetMailboxIdScript = fs.readFileSync(pathlib.join(__dirname, 'lua/z-get-mailbox-id.lua'), 'utf-8');
|
|
126
129
|
const zGetMailboxPathScript = fs.readFileSync(pathlib.join(__dirname, 'lua/z-get-mailbox-path.lua'), 'utf-8');
|
|
127
130
|
const sListAccountsScript = fs.readFileSync(pathlib.join(__dirname, 'lua/s-list-accounts.lua'), 'utf-8');
|
|
@@ -160,6 +163,11 @@ redis.defineCommand('zGetByUid', {
|
|
|
160
163
|
lua: zGetByUidScript
|
|
161
164
|
});
|
|
162
165
|
|
|
166
|
+
redis.defineCommand('zHeadScores', {
|
|
167
|
+
numberOfKeys: 1,
|
|
168
|
+
lua: zHeadScoresScript
|
|
169
|
+
});
|
|
170
|
+
|
|
163
171
|
redis.defineCommand('zGetMailboxId', {
|
|
164
172
|
numberOfKeys: 2,
|
|
165
173
|
lua: zGetMailboxIdScript
|
package/lib/delivery-error.js
CHANGED
|
@@ -52,6 +52,12 @@ function isPermanentDeliveryError(err) {
|
|
|
52
52
|
return false;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// nodemailer (10.2.0) decides it from the reply itself, which also covers a rejection of every
|
|
56
|
+
// recipient where only some were deferred: that one is transient although its first code is 5xx
|
|
57
|
+
if (typeof err.permanent === 'boolean') {
|
|
58
|
+
return err.permanent;
|
|
59
|
+
}
|
|
60
|
+
|
|
55
61
|
const smtpResponseCode = Number(err.responseCode);
|
|
56
62
|
if (smtpResponseCode) {
|
|
57
63
|
// A real SMTP reply decides on its own: 5xx is permanent, everything else (transient 4xx, or
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Interfaces that are scheduled for removal, and how their callers are told. Dependency-free, so
|
|
4
|
+
// the route modules and server.js can both use it and a test needs nothing running.
|
|
5
|
+
//
|
|
6
|
+
// - The pre-2.79 token endpoints (POST /v1/token, DELETE /v1/token/{token},
|
|
7
|
+
// GET /v1/tokens/account/{account}) answer with the Deprecation (RFC 9745), Sunset (RFC 8594)
|
|
8
|
+
// and Link rel="successor-version" headers, and each use is logged at warn, at most once an hour
|
|
9
|
+
// per endpoint and worker, so a busy integration does not flood the log. A route opts in with a
|
|
10
|
+
// `plugins.deprecation` block ({ since, successor, link }), which the one server-level
|
|
11
|
+
// onPreResponse extension from deprecationExt() reads, the way lib/security-headers.js reads
|
|
12
|
+
// `plugins.securityHeaders`.
|
|
13
|
+
// - The /admin/bull-board redirects to the queue browser, through the same plugins.deprecation
|
|
14
|
+
// block as the token endpoints.
|
|
15
|
+
// - The legacy SMTP server options (EENGINE_SMTP_ENABLED/_SECRET/_PORT/_HOST/_PROXY and the matching
|
|
16
|
+
// [smtp] config keys) only seed the SMTP server settings on a first start. Their use is logged at
|
|
17
|
+
// startup. The EENGINE_SMTP_TLS_* variables and [smtp] maxMessageSize / maxClients are current
|
|
18
|
+
// and not affected.
|
|
19
|
+
// - Request fields that are still accepted although what they controlled is gone or replaced
|
|
20
|
+
// (DEPRECATED_FIELDS). Their schema carries a custom rule from deprecatedField(), so a request
|
|
21
|
+
// that sends one is logged at warn, at most once an hour per field and worker, from whichever
|
|
22
|
+
// route and location it arrives through. The rule is on the schema rather than on the routes
|
|
23
|
+
// because most of these fields are shared by several routes and nested in their payloads.
|
|
24
|
+
|
|
25
|
+
const REMOVAL_DATE = '2027-01-01';
|
|
26
|
+
|
|
27
|
+
// HTTP-date form of REMOVAL_DATE, for the Sunset header
|
|
28
|
+
const SUNSET_HTTP_DATE = new Date(`${REMOVAL_DATE}T00:00:00Z`).toUTCString();
|
|
29
|
+
|
|
30
|
+
// When the token endpoints were deprecated: the 2.79.0 release, which renamed them
|
|
31
|
+
const TOKEN_ROUTES_DEPRECATED_AT = Date.parse('2026-08-18T07:47:01Z');
|
|
32
|
+
|
|
33
|
+
// When the /admin/bull-board redirects were deprecated: the 2.84.0 release, which replaced
|
|
34
|
+
// bull-board with the queue browser at /admin/queues
|
|
35
|
+
const BULL_BOARD_REDIRECTS_DEPRECATED_AT = Date.parse('2026-10-15T07:35:26Z');
|
|
36
|
+
|
|
37
|
+
const LOG_INTERVAL = 60 * 60 * 1000;
|
|
38
|
+
|
|
39
|
+
const LEGACY_SMTP_ENV = ['EENGINE_SMTP_ENABLED', 'EENGINE_SMTP_SECRET', 'EENGINE_SMTP_PORT', 'EENGINE_SMTP_HOST', 'EENGINE_SMTP_PROXY'];
|
|
40
|
+
|
|
41
|
+
// The built-in values of the legacy [smtp] keys (config/default.toml); only a different value
|
|
42
|
+
// means an operator set one
|
|
43
|
+
const LEGACY_SMTP_CONFIG_DEFAULTS = { enabled: false, port: 2525, host: '127.0.0.1', secret: '', proxy: false };
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Response headers that announce a deprecated endpoint
|
|
47
|
+
* @param {number} deprecatedAt - When it was deprecated, in milliseconds
|
|
48
|
+
* @param {string} [link] - Path of the endpoint to use instead, for the Link header. Left out where
|
|
49
|
+
* the successor path would have to carry a request parameter, such as a token
|
|
50
|
+
* @returns {Object} Header name to value
|
|
51
|
+
*/
|
|
52
|
+
function deprecationHeaders(deprecatedAt, link) {
|
|
53
|
+
const headers = {
|
|
54
|
+
Deprecation: `@${Math.floor(deprecatedAt / 1000)}`,
|
|
55
|
+
Sunset: SUNSET_HTTP_DATE
|
|
56
|
+
};
|
|
57
|
+
if (link) {
|
|
58
|
+
headers.Link = `<${link}>; rel="successor-version"`;
|
|
59
|
+
}
|
|
60
|
+
return headers;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A per-key once-per-LOG_INTERVAL gate, so a deprecated endpoint or field in constant use is
|
|
65
|
+
* reported each hour instead of on every request
|
|
66
|
+
* @param {Function} now - Clock
|
|
67
|
+
* @returns {Function} (key) => true when the use of key is to be logged now
|
|
68
|
+
*/
|
|
69
|
+
function createLogThrottle(now) {
|
|
70
|
+
const lastLogged = new Map();
|
|
71
|
+
return key => {
|
|
72
|
+
const time = now();
|
|
73
|
+
if (lastLogged.has(key) && time - lastLogged.get(key) < LOG_INTERVAL) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
lastLogged.set(key, time);
|
|
77
|
+
return true;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Server-level onPreResponse extension for deprecated endpoints. A route declares itself with
|
|
83
|
+
* `options.plugins.deprecation`:
|
|
84
|
+
* - `since` - when it was deprecated, in milliseconds
|
|
85
|
+
* - `successor` - the endpoint to use instead, as logged, e.g. "POST /v1/tokens"
|
|
86
|
+
* - `link` - optional, its path for the Link header, see deprecationHeaders()
|
|
87
|
+
* Every response of such a route, errors included, carries the headers, and its use is logged
|
|
88
|
+
* @param {Object} opts
|
|
89
|
+
* @param {Object} opts.logger - pino logger
|
|
90
|
+
* @param {Function} [opts.now] - Clock, for tests
|
|
91
|
+
* @returns {Function} The extension method
|
|
92
|
+
*/
|
|
93
|
+
function deprecationExt(opts) {
|
|
94
|
+
const { logger, now = Date.now } = opts;
|
|
95
|
+
// per method and path, so every deprecated endpoint in use is reported
|
|
96
|
+
const shouldLog = createLogThrottle(now);
|
|
97
|
+
|
|
98
|
+
return function deprecationResponse(request, h) {
|
|
99
|
+
const deprecation = request.route && request.route.settings.plugins && request.route.settings.plugins.deprecation;
|
|
100
|
+
if (!deprecation) {
|
|
101
|
+
return h.continue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const response = request.response;
|
|
105
|
+
const target = response && response.isBoom ? response.output.headers : response && response.headers;
|
|
106
|
+
if (target) {
|
|
107
|
+
Object.assign(target, deprecationHeaders(deprecation.since, deprecation.link));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const method = request.method.toUpperCase();
|
|
111
|
+
if (shouldLog(`${method} ${request.route.path}`)) {
|
|
112
|
+
logger.warn({
|
|
113
|
+
msg: 'Deprecated API endpoint called',
|
|
114
|
+
method,
|
|
115
|
+
path: request.route.path,
|
|
116
|
+
successor: deprecation.successor,
|
|
117
|
+
removal: REMOVAL_DATE,
|
|
118
|
+
// the token's id (its hash), as the rate limiter logs it, never the token itself
|
|
119
|
+
token: (request.auth && request.auth.artifacts && request.auth.artifacts.id) || undefined
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return h.continue;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The legacy SMTP server options an operator set
|
|
129
|
+
* @param {Object} opts
|
|
130
|
+
* @param {Function} opts.hasEnvValue - Whether an environment value is set (lib/read-env-value)
|
|
131
|
+
* @param {Object} [opts.smtpConfig] - The [smtp] section of the loaded config
|
|
132
|
+
* @returns {string[]} Option names, environment variables first
|
|
133
|
+
*/
|
|
134
|
+
function legacySmtpOptionsInUse({ hasEnvValue, smtpConfig }) {
|
|
135
|
+
const used = LEGACY_SMTP_ENV.filter(name => hasEnvValue(name));
|
|
136
|
+
for (const [key, defaultValue] of Object.entries(LEGACY_SMTP_CONFIG_DEFAULTS)) {
|
|
137
|
+
const value = smtpConfig && smtpConfig[key];
|
|
138
|
+
if (value === undefined || value === null) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
// config values can arrive as strings from --smtp.port=2525 style arguments
|
|
142
|
+
if (String(value) !== String(defaultValue)) {
|
|
143
|
+
used.push(`[smtp] ${key}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return used;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// The request fields deprecatedField() reports, with what to use instead (`successor`, as logged)
|
|
150
|
+
// and what the schema says about them (`note`, completed with the removal date). Removed after
|
|
151
|
+
// REMOVAL_DATE. A field is left out of the published API document unless `published` is set
|
|
152
|
+
const DEPRECATED_FIELDS = {
|
|
153
|
+
documentStore: { successor: 'nothing, the Document Store was removed in 2.82.0', note: 'Deprecated - Document Store feature has been removed' },
|
|
154
|
+
syncFrom: { successor: 'nothing, the Document Store was removed in 2.82.0', note: 'Deprecated - Document Store feature has been removed' },
|
|
155
|
+
documentStoreEnabled: { successor: 'nothing, the Document Store was removed in 2.82.0', note: 'Deprecated - Document Store feature has been removed' },
|
|
156
|
+
generateRiskAssessment: { successor: 'nothing, the risk assessment was removed', note: 'Deprecated - This feature has been removed' },
|
|
157
|
+
openAiGenerateEmbeddings: {
|
|
158
|
+
successor: 'nothing, embeddings generation was removed in 2.82.0',
|
|
159
|
+
note: 'Deprecated - embeddings generation has been removed'
|
|
160
|
+
},
|
|
161
|
+
trackSentMessages: {
|
|
162
|
+
successor: 'the trackClicks and trackOpens settings',
|
|
163
|
+
note: 'Enable tracking features for outgoing messages. Deprecated, use trackClicks and trackOpens instead',
|
|
164
|
+
removedAfter: true
|
|
165
|
+
},
|
|
166
|
+
'oauth2.authority': {
|
|
167
|
+
successor: 'the authority setting of the OAuth2 application',
|
|
168
|
+
note: 'Deprecated - Authority is set by the OAuth2 application configuration'
|
|
169
|
+
},
|
|
170
|
+
tenant: {
|
|
171
|
+
successor: 'the tenant ID as the authority of the OAuth2 application',
|
|
172
|
+
note: 'Deprecated, set the tenant ID as authority instead',
|
|
173
|
+
published: true
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Reports uses of deprecated request fields, at most once per LOG_INTERVAL per field
|
|
179
|
+
* @param {Object} opts
|
|
180
|
+
* @param {Function} opts.getLogger - Returns the logger, resolved on the first report
|
|
181
|
+
* @param {Function} [opts.now] - Clock, for tests
|
|
182
|
+
* @returns {Function} (field) => void
|
|
183
|
+
*/
|
|
184
|
+
function createFieldReporter(opts) {
|
|
185
|
+
const { getLogger, now = Date.now } = opts;
|
|
186
|
+
const shouldLog = createLogThrottle(now);
|
|
187
|
+
|
|
188
|
+
return function reportDeprecatedField(field) {
|
|
189
|
+
if (!shouldLog(field)) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
getLogger().warn({
|
|
193
|
+
msg: 'Deprecated request field used',
|
|
194
|
+
field,
|
|
195
|
+
successor: DEPRECATED_FIELDS[field].successor,
|
|
196
|
+
removal: REMOVAL_DATE
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Resolved lazily: lib/schemas.js requires this module, and the logger has no business loading
|
|
202
|
+
// before something is actually reported
|
|
203
|
+
let defaultReporter = createFieldReporter({ getLogger: () => require('./logger') });
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* A joi custom rule that reports the use of a deprecated field and passes its value on unchanged.
|
|
207
|
+
* Joi runs it only for a value that is present, after `.empty()`, so an empty string sent by a form
|
|
208
|
+
* is not a use.
|
|
209
|
+
* @param {string} field - DEPRECATED_FIELDS key
|
|
210
|
+
* @returns {Array} Arguments for joi's `.custom()`
|
|
211
|
+
*/
|
|
212
|
+
function deprecatedField(field) {
|
|
213
|
+
if (!Object.hasOwn(DEPRECATED_FIELDS, field)) {
|
|
214
|
+
throw new Error(`${field} is not a deprecated field`);
|
|
215
|
+
}
|
|
216
|
+
return [
|
|
217
|
+
value => {
|
|
218
|
+
defaultReporter(field);
|
|
219
|
+
return value;
|
|
220
|
+
},
|
|
221
|
+
`deprecated field ${field}`
|
|
222
|
+
];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Marks a joi schema as a deprecated request field: reports its use (deprecatedField()), describes
|
|
227
|
+
* it from DEPRECATED_FIELDS with the removal date, and keeps it out of the API document unless the
|
|
228
|
+
* field is listed as published. The one place these three are applied, so a description can not
|
|
229
|
+
* drift from what is logged
|
|
230
|
+
* @param {Object} schema - joi schema
|
|
231
|
+
* @param {string} field - DEPRECATED_FIELDS key
|
|
232
|
+
* @returns {Object} The schema
|
|
233
|
+
*/
|
|
234
|
+
function deprecated(schema, field) {
|
|
235
|
+
const rule = deprecatedField(field);
|
|
236
|
+
const { note, removedAfter, published } = DEPRECATED_FIELDS[field];
|
|
237
|
+
const description = removedAfter ? `${note}. Removed after ${REMOVAL_DATE}` : `${note}. Accepted until ${REMOVAL_DATE}`;
|
|
238
|
+
let marked = schema.custom(...rule).description(description);
|
|
239
|
+
if (!published) {
|
|
240
|
+
marked = marked.meta({ swaggerHidden: true });
|
|
241
|
+
}
|
|
242
|
+
return marked;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Replaces the reporter deprecatedField() rules call, for tests
|
|
247
|
+
* @param {Function} reporter - (field) => void
|
|
248
|
+
* @returns {Function} The previous reporter
|
|
249
|
+
*/
|
|
250
|
+
function setFieldReporter(reporter) {
|
|
251
|
+
const previous = defaultReporter;
|
|
252
|
+
defaultReporter = reporter;
|
|
253
|
+
return previous;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
module.exports = {
|
|
257
|
+
REMOVAL_DATE,
|
|
258
|
+
DEPRECATED_FIELDS,
|
|
259
|
+
createFieldReporter,
|
|
260
|
+
deprecatedField,
|
|
261
|
+
deprecated,
|
|
262
|
+
setFieldReporter,
|
|
263
|
+
SUNSET_HTTP_DATE,
|
|
264
|
+
TOKEN_ROUTES_DEPRECATED_AT,
|
|
265
|
+
BULL_BOARD_REDIRECTS_DEPRECATED_AT,
|
|
266
|
+
LOG_INTERVAL,
|
|
267
|
+
deprecationHeaders,
|
|
268
|
+
deprecationExt,
|
|
269
|
+
legacySmtpOptionsInUse
|
|
270
|
+
};
|