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.
- package/.github/workflows/test.yml +80 -0
- package/.ncurc.js +23 -13
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +60 -0
- package/bin/emailengine.js +1 -1
- package/config/e2e.toml +2 -1
- package/config/test.toml +2 -1
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +1 -1
- package/lib/account/expected-identity.js +88 -0
- package/lib/account.js +145 -61
- package/lib/api-reference/format.js +105 -4
- package/lib/api-reference/index.js +24 -7
- package/lib/api-reference/model.js +148 -21
- package/lib/api-reference/schema-tree.js +282 -28
- package/lib/api-routes/account-routes.js +99 -36
- package/lib/api-routes/behavior-notes.js +3 -0
- package/lib/api-routes/blocklist-routes.js +21 -47
- package/lib/api-routes/chat-routes.js +10 -12
- package/lib/api-routes/delivery-test-routes.js +6 -26
- package/lib/api-routes/export-routes.js +2 -0
- package/lib/api-routes/gateway-routes.js +52 -11
- package/lib/api-routes/license-routes.js +2 -0
- package/lib/api-routes/mailbox-routes.js +29 -26
- package/lib/api-routes/message-routes.js +27 -21
- package/lib/api-routes/oauth2-app-routes.js +11 -29
- package/lib/api-routes/operation-impact.js +80 -0
- package/lib/api-routes/outbox-routes.js +15 -5
- package/lib/api-routes/permission-map.js +397 -0
- package/lib/api-routes/route-helpers.js +223 -9
- package/lib/api-routes/route-metadata.js +28 -0
- package/lib/api-routes/settings-routes.js +30 -25
- package/lib/api-routes/stats-routes.js +2 -2
- package/lib/api-routes/submit-routes.js +53 -31
- package/lib/api-routes/template-routes.js +3 -0
- package/lib/api-routes/token-routes.js +319 -33
- package/lib/api-routes/webhook-route-routes.js +14 -4
- package/lib/append-list.js +3 -14
- package/lib/arf-detect.js +23 -1
- package/lib/auth-token.js +80 -8
- package/lib/autodetect-imap-settings.js +40 -16
- package/lib/base32.js +30 -0
- package/lib/bounce-detect.js +182 -62
- package/lib/consts.js +10 -0
- package/lib/db.js +20 -2
- package/lib/delivery-error.js +30 -1
- package/lib/egress-filter.js +89 -8
- package/lib/email-client/base-client.js +35 -113
- package/lib/email-client/gmail-client.js +22 -13
- package/lib/email-client/imap/listing-diff.js +3 -3
- package/lib/email-client/imap/mailbox.js +28 -93
- package/lib/email-client/imap/subconnection.js +10 -7
- package/lib/email-client/imap/sync-operations.js +46 -46
- package/lib/email-client/imap-client.js +39 -28
- package/lib/email-client/message-builder.js +15 -15
- package/lib/email-client/notification-handler.js +1 -1
- package/lib/email-client/outlook/graph-api.js +10 -4
- package/lib/email-client/outlook-client.js +54 -55
- package/lib/email-client/smtp-pool-manager.js +1 -1
- package/lib/enum-descriptions.js +92 -2
- package/lib/export.js +2 -2
- package/lib/field-usage.js +133 -0
- package/lib/gateway.js +2 -2
- package/lib/get-raw-email.js +1 -1
- package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +3 -3
- package/lib/imapproxy/imap-core/lib/commands/id.js +2 -13
- package/lib/imapproxy/imap-core/lib/commands/starttls.js +1 -1
- package/lib/imapproxy/imap-core/lib/imap-command.js +21 -5
- package/lib/imapproxy/imap-core/lib/imap-connection.js +17 -7
- package/lib/imapproxy/imap-core/lib/imap-server.js +2 -2
- package/lib/imapproxy/imap-server.js +40 -10
- package/lib/license-beacon.js +5 -10
- package/lib/lists.js +49 -1
- package/lib/llm-pre-process.js +6 -6
- package/lib/logger.js +5 -1
- package/lib/metrics-collector.js +2 -2
- package/lib/msgpack.js +62 -0
- package/lib/oauth/decode-jwt-payload.js +39 -0
- package/lib/oauth/gmail.js +9 -12
- package/lib/oauth/mail-ru.js +5 -7
- package/lib/oauth/outlook-identity.js +61 -0
- package/lib/oauth/outlook.js +9 -9
- package/lib/oauth/pubsub/google.js +25 -10
- package/lib/oauth/retry-setup.js +38 -0
- package/lib/oauth/scope-checker.js +1 -1
- package/lib/oauth2-apps.js +224 -295
- package/lib/openapi/build-document.js +15 -7
- package/lib/openapi/joi-schema.js +20 -0
- package/lib/outbox.js +145 -14
- package/lib/pre-process.js +9 -9
- package/lib/queue-stats.js +49 -0
- package/lib/read-env-value.js +37 -0
- package/lib/reconnection-manager.js +2 -2
- package/lib/rewrite-text-nodes.js +4 -3
- package/lib/routes-ui.js +4 -0
- package/lib/schemas.js +223 -155
- package/lib/settings.js +84 -5
- package/lib/sub-script.js +2 -1
- package/lib/swagger-options.js +2 -1
- package/lib/templates.js +5 -5
- package/lib/threads.js +2 -2
- package/lib/token-audit-log.js +208 -0
- package/lib/token-permission-view.js +219 -0
- package/lib/token-permissions.js +172 -0
- package/lib/tokens.js +100 -16
- package/lib/tools.js +259 -85
- package/lib/totp.js +67 -0
- package/lib/ui-routes/account-routes.js +122 -26
- package/lib/ui-routes/admin-config-routes.js +20 -17
- package/lib/ui-routes/admin-entities-routes.js +66 -22
- package/lib/ui-routes/auth-routes.js +36 -48
- package/lib/ui-routes/export-routes.js +10 -4
- package/lib/ui-routes/oauth-config-routes.js +5 -5
- package/lib/ui-routes/reference-routes.js +11 -8
- package/lib/ui-routes/route-helpers.js +79 -2
- package/lib/ui-routes/settings-page.js +1 -1
- package/lib/ui-routes/smtp-test-routes.js +1 -1
- package/lib/ui-routes/suppression-list-routes.js +294 -0
- package/lib/ui-routes/unsubscribe-routes.js +19 -29
- package/lib/utils/is-email.js +34 -0
- package/lib/utils/network.js +2 -2
- package/lib/utils/to-camel-case.js +17 -0
- package/lib/web-safe-html.js +1 -1
- package/lib/webhook-egress.js +37 -0
- package/lib/webhook-routing.js +80 -0
- package/lib/webhooks.js +21 -15
- package/package.json +26 -27
- package/sbom.json +1 -0
- package/server.js +81 -42
- package/static/css/flyonui.css +1 -1
- package/static/css/public.css +3 -0
- package/static/css/src/app.tailwind.css +159 -9
- package/static/js/app.js +69 -0
- package/static/js/reference.js +741 -10
- package/static/js/ui.js +43 -0
- package/static/licenses.html +698 -1590
- package/translations/README.md +64 -0
- package/translations/de.mo +0 -0
- package/translations/de.po +164 -120
- package/translations/en.po +200 -161
- package/translations/et.mo +0 -0
- package/translations/et.po +163 -120
- package/translations/fr.mo +0 -0
- package/translations/fr.po +163 -120
- package/translations/ja.mo +0 -0
- package/translations/ja.po +163 -120
- package/translations/messages.pot +94 -64
- package/translations/nl.mo +0 -0
- package/translations/nl.po +164 -120
- package/translations/pl.mo +0 -0
- package/translations/pl.po +163 -120
- package/views/account-identity-error.hbs +34 -0
- package/views/accounts/account.hbs +69 -7
- package/views/accounts/browse.hbs +18 -35
- package/views/accounts/edit.hbs +1 -0
- package/views/accounts/register/imap.hbs +12 -2
- package/views/config/logging.hbs +6 -0
- package/views/config/oauth/app.hbs +0 -2
- package/views/config/security.hbs +13 -0
- package/views/layout/app.hbs +29 -5
- package/views/oauth-scope-error.hbs +1 -1
- package/views/partials/oauth_form.hbs +0 -15
- package/views/partials/reference/disclosure.hbs +8 -2
- package/views/partials/reference/nav.hbs +36 -9
- package/views/partials/reference/operation.hbs +48 -14
- package/views/partials/reference/params.hbs +17 -1
- package/views/partials/reference/schema-node.hbs +112 -54
- package/views/partials/reference/schema-tools.hbs +25 -0
- package/views/partials/reference/token-alert.hbs +35 -10
- package/views/partials/reference/try-it.hbs +84 -11
- package/views/partials/side_menu.hbs +1 -0
- package/views/partials/ui/checkbox.hbs +2 -2
- package/views/partials/ui/tabs.hbs +7 -1
- package/views/reference/index.hbs +1 -1
- package/views/reference/token.hbs +4 -0
- package/views/suppression-lists/index.hbs +85 -0
- package/views/suppression-lists/list.hbs +87 -0
- package/views/templates/index.hbs +8 -2
- package/views/tokens/index.hbs +31 -4
- package/views/tokens/new.hbs +324 -2
- package/workers/api.js +299 -140
- package/workers/documents.js +46 -26
- package/workers/export.js +20 -8
- package/workers/imap-proxy.js +2 -2
- package/workers/imap.js +13 -7
- package/workers/smtp.js +13 -7
- package/workers/submit.js +41 -31
- package/workers/webhooks.js +60 -37
- package/lib/feature-flags.js +0 -48
|
@@ -17,7 +17,6 @@ module.exports = {
|
|
|
17
17
|
let serverId = {};
|
|
18
18
|
let serverIdList = [];
|
|
19
19
|
let key = false;
|
|
20
|
-
let maxKeyLen = 0;
|
|
21
20
|
|
|
22
21
|
if (this._server.options.id && typeof this._server.options.id === 'object') {
|
|
23
22
|
Object.keys(this._server.options.id).forEach(key => {
|
|
@@ -37,7 +36,6 @@ module.exports = {
|
|
|
37
36
|
} else {
|
|
38
37
|
if (allowedKeys.indexOf(key) >= 0) {
|
|
39
38
|
clientId[key] = (val.value || '').toString();
|
|
40
|
-
maxKeyLen = Math.max(maxKeyLen, key.length);
|
|
41
39
|
}
|
|
42
40
|
key = false;
|
|
43
41
|
}
|
|
@@ -46,7 +44,8 @@ module.exports = {
|
|
|
46
44
|
this._server.logger.info(
|
|
47
45
|
{
|
|
48
46
|
tnx: 'id',
|
|
49
|
-
cid: this.id
|
|
47
|
+
cid: this.id,
|
|
48
|
+
clientId
|
|
50
49
|
},
|
|
51
50
|
'Client identification data received'
|
|
52
51
|
);
|
|
@@ -62,16 +61,6 @@ module.exports = {
|
|
|
62
61
|
.sort((a, b) => allowedKeys.indexOf(a) - allowedKeys.indexOf(b))
|
|
63
62
|
.forEach(key => {
|
|
64
63
|
logdata[`_client_id_${key}`] = clientId[key];
|
|
65
|
-
this._server.logger.info(
|
|
66
|
-
{
|
|
67
|
-
tnx: 'id',
|
|
68
|
-
cid: this.id
|
|
69
|
-
},
|
|
70
|
-
'%s%s: %s',
|
|
71
|
-
key,
|
|
72
|
-
new Array(maxKeyLen - key.length + 1).join(' '),
|
|
73
|
-
clientId[key]
|
|
74
|
-
);
|
|
75
64
|
});
|
|
76
65
|
|
|
77
66
|
this._server.loggelf(logdata);
|
|
@@ -104,7 +104,7 @@ function upgrade(connection) {
|
|
|
104
104
|
user: connection.session && connection.session.user && connection.session.user.username,
|
|
105
105
|
cipher: cipher && cipher.name
|
|
106
106
|
},
|
|
107
|
-
'Connection upgraded to TLS using ',
|
|
107
|
+
'Connection upgraded to TLS using %s',
|
|
108
108
|
(cipher && cipher.name) || 'N/A'
|
|
109
109
|
);
|
|
110
110
|
|
|
@@ -122,7 +122,7 @@ class IMAPCommand {
|
|
|
122
122
|
cid: this.connection.id,
|
|
123
123
|
src: 'C'
|
|
124
124
|
},
|
|
125
|
-
this.
|
|
125
|
+
this.loggablePayload()
|
|
126
126
|
);
|
|
127
127
|
|
|
128
128
|
this.payload = ''; // reset payload
|
|
@@ -180,7 +180,7 @@ class IMAPCommand {
|
|
|
180
180
|
cid: this.connection.id,
|
|
181
181
|
src: 'C'
|
|
182
182
|
},
|
|
183
|
-
this.
|
|
183
|
+
this.loggablePayload()
|
|
184
184
|
);
|
|
185
185
|
if (!this.countBadResponses()) {
|
|
186
186
|
// stop processing
|
|
@@ -197,8 +197,7 @@ class IMAPCommand {
|
|
|
197
197
|
cid: this.connection.id,
|
|
198
198
|
src: 'C'
|
|
199
199
|
},
|
|
200
|
-
|
|
201
|
-
(this.payload && this.payload.length) || 0
|
|
200
|
+
this.loggablePayload()
|
|
202
201
|
);
|
|
203
202
|
return this.connection._nextHandler(this.payload, next);
|
|
204
203
|
}
|
|
@@ -213,7 +212,7 @@ class IMAPCommand {
|
|
|
213
212
|
cid: this.connection.id,
|
|
214
213
|
src: 'C'
|
|
215
214
|
},
|
|
216
|
-
this.
|
|
215
|
+
this.loggablePayload()
|
|
217
216
|
);
|
|
218
217
|
this.connection.send(this.tag + ' BAD ' + E.message);
|
|
219
218
|
if (!this.countBadResponses()) {
|
|
@@ -318,6 +317,23 @@ class IMAPCommand {
|
|
|
318
317
|
});
|
|
319
318
|
}
|
|
320
319
|
|
|
320
|
+
// LOGIN and AUTHENTICATE payloads carry credentials and must never be logged raw.
|
|
321
|
+
// Also scans the payload itself for malformed lines (e.g. a missing tag) where the
|
|
322
|
+
// credential-bearing command name was not parsed into this.command.
|
|
323
|
+
loggablePayload() {
|
|
324
|
+
// A continuation frame is not a command, so neither the parsed command name nor the payload
|
|
325
|
+
// text identifies it - during AUTHENTICATE it is the bare base64 SASL blob. Nothing about
|
|
326
|
+
// it is safe to render, so report the size only, the same way the accepted path does.
|
|
327
|
+
if (typeof this.connection._nextHandler === 'function') {
|
|
328
|
+
return `<${(this.payload && this.payload.length) || 0} bytes of data>`;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (/^(AUTHENTICATE|LOGIN)/i.test(this.command || '') || /^\s*(?:\S+\s+)?(AUTHENTICATE|LOGIN)\b/i.test(this.payload || '')) {
|
|
332
|
+
return [this.tag, this.command, '(* payload hidden *)'].filter(v => v).join(' ');
|
|
333
|
+
}
|
|
334
|
+
return this.payload || '';
|
|
335
|
+
}
|
|
336
|
+
|
|
321
337
|
sendNotifications(handler, callback) {
|
|
322
338
|
if (this.connection.state !== 'Selected' || !!handler.disableNotifications) {
|
|
323
339
|
// nothing to advertise if not in Selected state
|
|
@@ -8,7 +8,7 @@ const search = require('./search');
|
|
|
8
8
|
const dns = require('dns');
|
|
9
9
|
const crypto = require('crypto');
|
|
10
10
|
const os = require('os');
|
|
11
|
-
const
|
|
11
|
+
const { base32Encode } = require('../../../base32');
|
|
12
12
|
const EventEmitter = require('events').EventEmitter;
|
|
13
13
|
const packageInfo = require('../../../../package');
|
|
14
14
|
|
|
@@ -33,7 +33,7 @@ class IMAPConnection extends EventEmitter {
|
|
|
33
33
|
|
|
34
34
|
options = options || {};
|
|
35
35
|
// Random session ID, used for logging
|
|
36
|
-
this.id = options.id ||
|
|
36
|
+
this.id = options.id || base32Encode(crypto.randomBytes(10)).toLowerCase();
|
|
37
37
|
|
|
38
38
|
this.ignore = options.ignore;
|
|
39
39
|
|
|
@@ -103,7 +103,7 @@ class IMAPConnection extends EventEmitter {
|
|
|
103
103
|
this._closed = false;
|
|
104
104
|
|
|
105
105
|
this.logger = {};
|
|
106
|
-
['info', 'debug', 'error'].forEach(level => {
|
|
106
|
+
['info', 'debug', 'warn', 'error'].forEach(level => {
|
|
107
107
|
this.logger[level] = (...args) => {
|
|
108
108
|
if (!this.ignore) {
|
|
109
109
|
this._server.logger[level](...args);
|
|
@@ -173,7 +173,7 @@ class IMAPConnection extends EventEmitter {
|
|
|
173
173
|
this.session.clientHostname = this.clientHostname = clientHostname || '[' + this.remoteAddress + ']';
|
|
174
174
|
|
|
175
175
|
if (greetingSent && clientHostname) {
|
|
176
|
-
this.logger.
|
|
176
|
+
this.logger.debug(
|
|
177
177
|
{
|
|
178
178
|
tnx: 'connect',
|
|
179
179
|
cid: this.id
|
|
@@ -267,7 +267,7 @@ class IMAPConnection extends EventEmitter {
|
|
|
267
267
|
this[!this.compression ? '_socket' : '_deflate'].write(payload + '\r\n', 'binary', (...args) => {
|
|
268
268
|
if (args[0]) {
|
|
269
269
|
// write error
|
|
270
|
-
this.logger.
|
|
270
|
+
this.logger.warn(
|
|
271
271
|
{
|
|
272
272
|
tnx: 'send',
|
|
273
273
|
cid: this.id,
|
|
@@ -284,7 +284,7 @@ class IMAPConnection extends EventEmitter {
|
|
|
284
284
|
});
|
|
285
285
|
} catch (err) {
|
|
286
286
|
// write error
|
|
287
|
-
this.logger.
|
|
287
|
+
this.logger.warn(
|
|
288
288
|
{
|
|
289
289
|
tnx: 'send',
|
|
290
290
|
cid: this.id,
|
|
@@ -510,6 +510,8 @@ class IMAPConnection extends EventEmitter {
|
|
|
510
510
|
return;
|
|
511
511
|
}
|
|
512
512
|
|
|
513
|
+
let logLevel = 'error';
|
|
514
|
+
|
|
513
515
|
if (err && /SSL[23]*_GET_CLIENT_HELLO|ssl[23]*_read_bytes|ssl_bytes_to_cipher_list/i.test(err.message)) {
|
|
514
516
|
let message = err.message;
|
|
515
517
|
err.message = 'Failed to establish TLS session';
|
|
@@ -521,6 +523,8 @@ class IMAPConnection extends EventEmitter {
|
|
|
521
523
|
message,
|
|
522
524
|
remoteAddress: this.remoteAddress
|
|
523
525
|
};
|
|
526
|
+
// TLS handshake garbage from the client, not a server fault
|
|
527
|
+
logLevel = 'warn';
|
|
524
528
|
}
|
|
525
529
|
|
|
526
530
|
if (!err || !err.message) {
|
|
@@ -530,15 +534,21 @@ class IMAPConnection extends EventEmitter {
|
|
|
530
534
|
err.meta = {
|
|
531
535
|
remoteAddress: this.remoteAddress
|
|
532
536
|
};
|
|
537
|
+
// Client-caused, same classification the server-level handler gives a SocketError. That
|
|
538
|
+
// handler never sees this one: `processed` below makes it return early, so the level has
|
|
539
|
+
// to be lowered here or every scanner and load-balancer probe lands in the error stream.
|
|
540
|
+
logLevel = 'warn';
|
|
533
541
|
}
|
|
534
542
|
|
|
535
|
-
this.logger
|
|
543
|
+
this.logger[logLevel](
|
|
536
544
|
{
|
|
537
545
|
err,
|
|
538
546
|
cid: this.id
|
|
539
547
|
},
|
|
540
548
|
err.message
|
|
541
549
|
);
|
|
550
|
+
// mark as logged so server-level listeners do not log a duplicate entry
|
|
551
|
+
err.processed = true;
|
|
542
552
|
this.emit('error', err);
|
|
543
553
|
}
|
|
544
554
|
|
|
@@ -8,7 +8,7 @@ const tlsOptions = require('./tls-options');
|
|
|
8
8
|
const EventEmitter = require('events').EventEmitter;
|
|
9
9
|
const shared = require('nodemailer/lib/shared');
|
|
10
10
|
const punycode = require('punycode.js');
|
|
11
|
-
const
|
|
11
|
+
const { base32Encode } = require('../../../base32');
|
|
12
12
|
|
|
13
13
|
const CLOSE_TIMEOUT = 1 * 1000; // how much to wait until pending connections are terminated
|
|
14
14
|
|
|
@@ -208,7 +208,7 @@ class IMAPServer extends EventEmitter {
|
|
|
208
208
|
|
|
209
209
|
_handleProxy(socket, callback) {
|
|
210
210
|
let socketOptions = {
|
|
211
|
-
id:
|
|
211
|
+
id: base32Encode(crypto.randomBytes(10)).toLowerCase()
|
|
212
212
|
};
|
|
213
213
|
|
|
214
214
|
if (
|
|
@@ -6,7 +6,17 @@ const config = require('@zone-eu/wild-config');
|
|
|
6
6
|
const logger = require('../logger');
|
|
7
7
|
const { oauth2Apps, oauth2ProviderData } = require('../oauth2-apps');
|
|
8
8
|
|
|
9
|
-
const {
|
|
9
|
+
const {
|
|
10
|
+
getDuration,
|
|
11
|
+
getBoolean,
|
|
12
|
+
resolveCredentials,
|
|
13
|
+
useAuthServerForOAuth2,
|
|
14
|
+
useAuthServerForConnection,
|
|
15
|
+
hasEnvValue,
|
|
16
|
+
readEnvValue,
|
|
17
|
+
emitChangeEvent,
|
|
18
|
+
loadTlsConfig
|
|
19
|
+
} = require('../tools');
|
|
10
20
|
const { getLocalAddress } = require('../utils/network');
|
|
11
21
|
|
|
12
22
|
const { redis } = require('../db');
|
|
@@ -176,7 +186,7 @@ async function onAuth(auth, session) {
|
|
|
176
186
|
// load OAuth2 tokens
|
|
177
187
|
let imapAuth;
|
|
178
188
|
|
|
179
|
-
if (accountData.oauth2
|
|
189
|
+
if (await useAuthServerForOAuth2(accountData.oauth2, logger, { account, target: 'imap' })) {
|
|
180
190
|
// An external authentication server owns this account's tokens, so ask it for one
|
|
181
191
|
// rather than renewing from a stored refresh token (there is none). The response is
|
|
182
192
|
// already in the { user, accessToken } shape the connection config expects.
|
|
@@ -210,7 +220,7 @@ async function onAuth(auth, session) {
|
|
|
210
220
|
}
|
|
211
221
|
|
|
212
222
|
// If authentication server is set then it overrides authentication data
|
|
213
|
-
if (imapConnectionConfig
|
|
223
|
+
if (await useAuthServerForConnection(imapConnectionConfig, logger, { account, target: 'imap' })) {
|
|
214
224
|
try {
|
|
215
225
|
imapConnectionConfig.auth = await resolveCredentials(account, 'imap');
|
|
216
226
|
} catch (err) {
|
|
@@ -307,7 +317,23 @@ const createServer = function (options = {}) {
|
|
|
307
317
|
let server = new IMAPServer(options);
|
|
308
318
|
|
|
309
319
|
server.on('error', err => {
|
|
310
|
-
|
|
320
|
+
if (err && err.processed) {
|
|
321
|
+
// already logged by the connection that raised it
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
let entry = { msg: 'Server error', err };
|
|
325
|
+
if (err && err.meta && err.meta.remoteAddress) {
|
|
326
|
+
entry.remoteAddress = err.meta.remoteAddress;
|
|
327
|
+
}
|
|
328
|
+
if (err && err.report === false) {
|
|
329
|
+
// e.g. a scanner closing the socket while initiating TLS
|
|
330
|
+
serverLogger.debug(entry);
|
|
331
|
+
} else if (err && (err.code === 'TLSError' || err.code === 'SocketError')) {
|
|
332
|
+
// client-caused connection or TLS handshake failure
|
|
333
|
+
serverLogger.warn(entry);
|
|
334
|
+
} else {
|
|
335
|
+
serverLogger.error(entry);
|
|
336
|
+
}
|
|
311
337
|
});
|
|
312
338
|
|
|
313
339
|
server.onAuth = function (login, session, callback) {
|
|
@@ -356,7 +382,7 @@ const createServer = function (options = {}) {
|
|
|
356
382
|
try {
|
|
357
383
|
downstream.imapClient.close();
|
|
358
384
|
} catch (err) {
|
|
359
|
-
proxyLogger.
|
|
385
|
+
proxyLogger.warn({ msg: 'Failed to close upstream connection', err });
|
|
360
386
|
}
|
|
361
387
|
|
|
362
388
|
try {
|
|
@@ -370,8 +396,8 @@ const createServer = function (options = {}) {
|
|
|
370
396
|
|
|
371
397
|
// Every terminal event from either leg funnels into the idempotent
|
|
372
398
|
// closeProxy(). The helper keeps that wiring declarative; pass a message
|
|
373
|
-
// to log (level defaults to '
|
|
374
|
-
const teardownOn = (emitter, event, msg, level = '
|
|
399
|
+
// to log (level defaults to 'warn', use 'info' for graceful closes).
|
|
400
|
+
const teardownOn = (emitter, event, msg, level = 'warn') => {
|
|
375
401
|
emitter.on(event, err => {
|
|
376
402
|
if (msg) {
|
|
377
403
|
let entry = { msg };
|
|
@@ -395,7 +421,7 @@ const createServer = function (options = {}) {
|
|
|
395
421
|
teardownOn(downstream.readSocket, 'end', 'Upstream connection closed', 'info');
|
|
396
422
|
|
|
397
423
|
downstream.readSocket.on('error', err => {
|
|
398
|
-
proxyLogger.
|
|
424
|
+
proxyLogger.warn({ msg: 'Upstream read error', err });
|
|
399
425
|
try {
|
|
400
426
|
// best-effort notice to the client before tearing down
|
|
401
427
|
upstream.socket.write('* BYE Upstream connection error\r\n');
|
|
@@ -436,26 +462,30 @@ const createServer = function (options = {}) {
|
|
|
436
462
|
})
|
|
437
463
|
.catch(err => {
|
|
438
464
|
if (err.authenticationFailed || err.serverResponseCode === 'AUTHENTICATIONFAILED') {
|
|
465
|
+
serverLogger.warn({ msg: 'Upstream authentication failed', account, cid: session.id, err });
|
|
439
466
|
let error = new Error(
|
|
440
467
|
`${err.serverResponseCode ? `[${err.serverResponseCode}] ` : ''}${err.responseText || err.message || 'Authentication failed'}`
|
|
441
468
|
);
|
|
442
469
|
error.response = err.responseStatus || 'NO';
|
|
443
470
|
return callback(error);
|
|
444
471
|
} else {
|
|
445
|
-
serverLogger.error({ msg: 'Failed to create proxy', err });
|
|
472
|
+
serverLogger.error({ msg: 'Failed to create proxy', account, cid: session.id, err });
|
|
446
473
|
return callback(err);
|
|
447
474
|
}
|
|
448
475
|
});
|
|
449
476
|
})
|
|
450
477
|
.catch(err => {
|
|
451
|
-
|
|
478
|
+
let entry = { msg: 'Authentication check failed', username: login.username, cid: session.id, remoteAddress: session.remoteAddress, err };
|
|
452
479
|
if (err.authenticationFailed || err.serverResponseCode === 'AUTHENTICATIONFAILED') {
|
|
480
|
+
// routine failed client login, not a proxy fault
|
|
481
|
+
serverLogger.warn(entry);
|
|
453
482
|
let error = new Error(
|
|
454
483
|
`${err.serverResponseCode ? `[${err.serverResponseCode}] ` : ''}${err.responseText || err.message || 'Authentication failed'}`
|
|
455
484
|
);
|
|
456
485
|
error.response = err.responseStatus || 'NO';
|
|
457
486
|
return callback(error);
|
|
458
487
|
}
|
|
488
|
+
serverLogger.error(entry);
|
|
459
489
|
return callback(err);
|
|
460
490
|
});
|
|
461
491
|
};
|
package/lib/license-beacon.js
CHANGED
|
@@ -16,14 +16,13 @@
|
|
|
16
16
|
// The caller is expected to also time-box this with withTimeout().
|
|
17
17
|
|
|
18
18
|
const crypto = require('crypto');
|
|
19
|
-
const msgpack = require('
|
|
19
|
+
const msgpack = require('./msgpack');
|
|
20
20
|
|
|
21
21
|
const settings = require('./settings');
|
|
22
22
|
const { getCounterValues, hasEnvValue, readEnvValue, getBoolean } = require('./tools');
|
|
23
23
|
const { REDIS_PREFIX } = require('./consts');
|
|
24
24
|
const { oauth2Apps } = require('./oauth2-apps');
|
|
25
25
|
const passkeys = require('./passkeys');
|
|
26
|
-
const featureFlags = require('./feature-flags');
|
|
27
26
|
const { documentStoreFeatureEnabled } = require('./document-store');
|
|
28
27
|
|
|
29
28
|
// Beacon schema version. Bump when the meaning of codes changes so the license server can adapt.
|
|
@@ -131,7 +130,7 @@ async function collectBeacon({ redis, logger }) {
|
|
|
131
130
|
return await fn();
|
|
132
131
|
} catch (err) {
|
|
133
132
|
if (logger) {
|
|
134
|
-
logger.
|
|
133
|
+
logger.debug({ msg: 'Beacon field collection failed', err });
|
|
135
134
|
}
|
|
136
135
|
return undefined;
|
|
137
136
|
}
|
|
@@ -270,7 +269,6 @@ async function collectBeacon({ redis, logger }) {
|
|
|
270
269
|
if (documentStoreFeatureEnabled) dep.push('documentStoreGate');
|
|
271
270
|
if (on('documentStoreGenerateEmbeddings')) dep.push('ds_embed');
|
|
272
271
|
if (on('documentStorePreProcessingEnabled')) dep.push('ds_preproc');
|
|
273
|
-
if (on('gmailEnabled') || on('outlookEnabled') || on('mailRuEnabled')) dep.push('legacyOauth');
|
|
274
272
|
if (on('trackSentMessages')) dep.push('trackSent');
|
|
275
273
|
await safe(async () => {
|
|
276
274
|
const ids = await redis.smembers(`${REDIS_PREFIX}wh:i`);
|
|
@@ -297,9 +295,6 @@ async function collectBeacon({ redis, logger }) {
|
|
|
297
295
|
});
|
|
298
296
|
diag.dep = dep.sort();
|
|
299
297
|
|
|
300
|
-
// Enabled EENGINE_FEATURE_* flags (already sorted).
|
|
301
|
-
diag.flags = (await safe(() => featureFlags.listEnabled())) || [];
|
|
302
|
-
|
|
303
298
|
// Runtime context.
|
|
304
299
|
diag.dist = installChannel();
|
|
305
300
|
diag.node = process.versions.node;
|
|
@@ -310,7 +305,7 @@ async function collectBeacon({ redis, logger }) {
|
|
|
310
305
|
return { fh, diag };
|
|
311
306
|
} catch (err) {
|
|
312
307
|
if (logger) {
|
|
313
|
-
logger.
|
|
308
|
+
logger.warn({ msg: 'Beacon collection failed', err });
|
|
314
309
|
}
|
|
315
310
|
return null;
|
|
316
311
|
}
|
|
@@ -334,7 +329,7 @@ async function attachBeacon(body, { redis, logger, now }) {
|
|
|
334
329
|
}
|
|
335
330
|
} catch (err) {
|
|
336
331
|
if (logger) {
|
|
337
|
-
logger.
|
|
332
|
+
logger.warn({ msg: 'License beacon collection failed', err });
|
|
338
333
|
}
|
|
339
334
|
}
|
|
340
335
|
}
|
|
@@ -355,7 +350,7 @@ async function persistBeaconMarkers({ redis, logger, body, now, needFull }) {
|
|
|
355
350
|
}
|
|
356
351
|
} catch (err) {
|
|
357
352
|
if (logger) {
|
|
358
|
-
logger.
|
|
353
|
+
logger.warn({ msg: 'Failed to persist license beacon markers', err });
|
|
359
354
|
}
|
|
360
355
|
}
|
|
361
356
|
}
|
package/lib/lists.js
CHANGED
|
@@ -19,6 +19,54 @@ class ListHandler {
|
|
|
19
19
|
return `${REDIS_PREFIX}lists:unsub:entries:${listId}`;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
normalizeRecipient(recipient) {
|
|
23
|
+
return (recipient || '').toString().toLowerCase().trim();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// does the list itself exist
|
|
27
|
+
async exists(listId) {
|
|
28
|
+
return (await this.redis.hexists(this.getListsIndexKey(), listId)) === 1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// is the recipient suppressed on this list
|
|
32
|
+
async has(listId, recipient) {
|
|
33
|
+
return (await this.redis.hexists(this.getListsContentKey(listId), this.normalizeRecipient(recipient))) === 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Adds a suppression record. The entry key is the normalized recipient address; the stored
|
|
37
|
+
// record echoes the recipient and is stamped with a created time unless the caller provides
|
|
38
|
+
// one. Returns 1 when the address was newly added, 0 when it was already listed (eeListAdd
|
|
39
|
+
// keeps the list counter in sync atomically).
|
|
40
|
+
async add(listId, recipient, meta) {
|
|
41
|
+
let record = Object.assign({ recipient }, meta || {});
|
|
42
|
+
if (!record.created) {
|
|
43
|
+
record.created = new Date().toISOString();
|
|
44
|
+
}
|
|
45
|
+
return await this.redis.eeListAdd(
|
|
46
|
+
this.getListsIndexKey(),
|
|
47
|
+
this.getListsContentKey(listId),
|
|
48
|
+
listId,
|
|
49
|
+
this.normalizeRecipient(recipient),
|
|
50
|
+
JSON.stringify(record)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Returns 1 when the address was removed, 0 when it was not listed
|
|
55
|
+
async remove(listId, recipient) {
|
|
56
|
+
return await this.redis.eeListRemove(this.getListsIndexKey(), this.getListsContentKey(listId), listId, this.normalizeRecipient(recipient));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Drops a whole list with all of its entries. Returns true when the list existed.
|
|
60
|
+
async deleteList(listId) {
|
|
61
|
+
let result = await this.redis.multi().hdel(this.getListsIndexKey(), listId).del(this.getListsContentKey(listId)).exec();
|
|
62
|
+
for (let [err] of result) {
|
|
63
|
+
if (err) {
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return !!result[0][1];
|
|
68
|
+
}
|
|
69
|
+
|
|
22
70
|
async list(page, pageSize) {
|
|
23
71
|
page = Math.max(Number(page) || 0, 0);
|
|
24
72
|
pageSize = Math.max(Number(pageSize) || 20, 1);
|
|
@@ -45,7 +93,7 @@ class ListHandler {
|
|
|
45
93
|
}
|
|
46
94
|
|
|
47
95
|
async listContent(listId, page, pageSize) {
|
|
48
|
-
let exists = await
|
|
96
|
+
let exists = await this.exists(listId);
|
|
49
97
|
if (!exists) {
|
|
50
98
|
let message = 'Requested blocklist was not found';
|
|
51
99
|
let error = Boom.boomify(new Error(message), { statusCode: 404 });
|
package/lib/llm-pre-process.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const { redis } = require('./db');
|
|
4
|
-
const msgpack = require('
|
|
4
|
+
const msgpack = require('./msgpack');
|
|
5
5
|
const logger = require('./logger');
|
|
6
6
|
const { REDIS_PREFIX } = require('./consts');
|
|
7
7
|
const settings = require('./settings');
|
|
@@ -41,7 +41,7 @@ class LLMPreProcessHandler {
|
|
|
41
41
|
} catch (err) {
|
|
42
42
|
await this.storeLog('filter', null, err.stack);
|
|
43
43
|
|
|
44
|
-
logger.error({ msg: '
|
|
44
|
+
logger.error({ msg: 'Failed to compile LLM pre-processing script', component: 'llm-pre-process', type: 'filter', err });
|
|
45
45
|
preProcessData.compiledFn = null;
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -54,7 +54,7 @@ class LLMPreProcessHandler {
|
|
|
54
54
|
return await preProcessData.compiledFn.exec(payload);
|
|
55
55
|
} catch (err) {
|
|
56
56
|
await this.storeLog('filter', payload, err.stack);
|
|
57
|
-
logger.error({ msg: '
|
|
57
|
+
logger.error({ msg: 'Failed to execute LLM pre-processing script', component: 'llm-pre-process', type: 'filter', err });
|
|
58
58
|
return null;
|
|
59
59
|
}
|
|
60
60
|
};
|
|
@@ -85,7 +85,7 @@ class LLMPreProcessHandler {
|
|
|
85
85
|
try {
|
|
86
86
|
await redis.multi().rpush(this.getPreProcessLogKey(), logRow).ltrim(this.getPreProcessLogKey(), -maxLogLines, -1).exec();
|
|
87
87
|
} catch (err) {
|
|
88
|
-
logger.error({ msg: 'Failed to insert error log entries', err });
|
|
88
|
+
logger.error({ msg: 'Failed to insert error log entries', component: 'llm-pre-process', err });
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -102,7 +102,7 @@ class LLMPreProcessHandler {
|
|
|
102
102
|
let entry = msgpack.decode(line);
|
|
103
103
|
logEntries.unshift(entry);
|
|
104
104
|
} catch (err) {
|
|
105
|
-
logger.error({ msg: 'Failed to
|
|
105
|
+
logger.error({ msg: 'Failed to decode log line', component: 'llm-pre-process', entry: line && line.toString('base64'), err });
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -124,7 +124,7 @@ class LLMPreProcessHandler {
|
|
|
124
124
|
} catch (err) {
|
|
125
125
|
await this.storeLog('filter', payload, err.stack);
|
|
126
126
|
|
|
127
|
-
logger.error({ msg: '
|
|
127
|
+
logger.error({ msg: 'Failed to execute LLM pre-processing script', component: 'llm-pre-process', type: 'filter', err });
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
if (canUse && payload) {
|
package/lib/logger.js
CHANGED
|
@@ -7,7 +7,7 @@ if (!process.env.EE_ENV_LOADED) {
|
|
|
7
7
|
|
|
8
8
|
const config = require('@zone-eu/wild-config');
|
|
9
9
|
const pino = require('pino');
|
|
10
|
-
const { TRANSIENT_NETWORK_CODES } = require('./consts');
|
|
10
|
+
const { TRANSIENT_NETWORK_CODES, REDACTED_LOG_KEYS } = require('./consts');
|
|
11
11
|
|
|
12
12
|
config.log = config.log || {
|
|
13
13
|
level: 'trace'
|
|
@@ -25,6 +25,10 @@ function isTransientFetchError(err) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
let logger = pino({
|
|
28
|
+
// Redaction belongs on the root logger, not on a single worker's child: the imap, smtp,
|
|
29
|
+
// imap-proxy, submit, webhooks, export and documents workers all log through this instance,
|
|
30
|
+
// and several of them log joi errors carrying credentials.
|
|
31
|
+
redact: REDACTED_LOG_KEYS,
|
|
28
32
|
formatters: {
|
|
29
33
|
log(object) {
|
|
30
34
|
if (object.err && ['TypeError', 'RangeError'].includes(object.err.name) && !isTransientFetchError(object.err)) {
|
package/lib/metrics-collector.js
CHANGED
|
@@ -51,9 +51,9 @@ class MetricsCollector {
|
|
|
51
51
|
if (this.collectorTimer) {
|
|
52
52
|
clearTimeout(this.collectorTimer);
|
|
53
53
|
this.collectorTimer = null;
|
|
54
|
+
this.logger.info({ msg: 'Stopped background metrics collector' });
|
|
54
55
|
}
|
|
55
56
|
this.isCollecting = false;
|
|
56
|
-
this.logger.info({ msg: 'Stopped background metrics collector' });
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/**
|
|
@@ -175,7 +175,7 @@ class MetricsCollector {
|
|
|
175
175
|
const cacheAge = this.lastCollectionTime ? Date.now() - this.lastCollectionTime : null;
|
|
176
176
|
this.logger.debug({
|
|
177
177
|
msg: 'Returning cached metrics',
|
|
178
|
-
|
|
178
|
+
threads: this.cachedThreadsInfo.length,
|
|
179
179
|
cacheAge
|
|
180
180
|
});
|
|
181
181
|
return this.cachedThreadsInfo;
|
package/lib/msgpack.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Wrapper around @msgpack/msgpack that keeps the call-site contract of the deprecated
|
|
4
|
+
// msgpack5 package this codebase used before:
|
|
5
|
+
// - encode() returns a Buffer (call sites chain .toString('base64url'), Buffer.concat and
|
|
6
|
+
// hsetBuffer on it) and omits undefined object properties instead of encoding nil
|
|
7
|
+
// - decode() reads the first value and ignores trailing bytes - graceful-degradation guards
|
|
8
|
+
// for corrupt stored blobs rely on a parseable prefix decoding instead of throwing
|
|
9
|
+
// - decode() returns Buffers for bin values where @msgpack/msgpack yields Uint8Array -
|
|
10
|
+
// call sites use .toString('hex')/.toString('base64') which are Buffer-only
|
|
11
|
+
// The wire format is plain spec msgpack in both directions, so blobs persisted by earlier
|
|
12
|
+
// msgpack5-based releases stay readable and vice versa.
|
|
13
|
+
|
|
14
|
+
const { Encoder, Decoder } = require('@msgpack/msgpack');
|
|
15
|
+
|
|
16
|
+
// shared instances so the per-call codec setup (internal 2KB encode buffer, decoder stack pool)
|
|
17
|
+
// amortizes across calls - decode runs on every API token check and mailbox listing entry.
|
|
18
|
+
// The library guards re-entrancy itself by cloning when an instance is already in use.
|
|
19
|
+
const encoder = new Encoder({ ignoreUndefined: true });
|
|
20
|
+
const decoder = new Decoder();
|
|
21
|
+
|
|
22
|
+
function bufferize(value) {
|
|
23
|
+
if (value instanceof Uint8Array) {
|
|
24
|
+
return Buffer.from(value.buffer, value.byteOffset, value.byteLength);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (Array.isArray(value)) {
|
|
28
|
+
for (let i = 0; i < value.length; i++) {
|
|
29
|
+
value[i] = bufferize(value[i]);
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (value && typeof value === 'object' && !(value instanceof Date)) {
|
|
35
|
+
for (let key of Object.keys(value)) {
|
|
36
|
+
value[key] = bufferize(value[key]);
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function encode(value) {
|
|
45
|
+
// copy into a standalone Buffer - encodeSharedRef() returns a view over the reused internal buffer
|
|
46
|
+
return Buffer.from(encoder.encodeSharedRef(value));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function decode(buf) {
|
|
50
|
+
for (let value of decoder.decodeMulti(buf)) {
|
|
51
|
+
return bufferize(value);
|
|
52
|
+
}
|
|
53
|
+
// empty input yields no values instead of throwing
|
|
54
|
+
throw new Error('Unable to decode msgpack value');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Decodes a byte stream of concatenated msgpack values (append-list hash fields)
|
|
58
|
+
function decodeMulti(buf) {
|
|
59
|
+
return Array.from(decoder.decodeMulti(buf), bufferize);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = { encode, decode, decodeMulti };
|