emailengine-app 2.78.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/.ncurc.js +23 -13
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +29 -0
- package/config/e2e.toml +2 -1
- package/config/test.toml +2 -1
- package/data/google-crawlers.json +1 -1
- package/lib/account.js +70 -35
- package/lib/api-reference/format.js +91 -4
- package/lib/api-reference/model.js +144 -19
- package/lib/api-reference/schema-tree.js +282 -28
- package/lib/api-routes/account-routes.js +80 -34
- 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/auth-token.js +80 -8
- package/lib/consts.js +10 -0
- package/lib/db.js +20 -2
- package/lib/delivery-error.js +30 -1
- package/lib/email-client/base-client.js +27 -41
- package/lib/email-client/gmail-client.js +19 -10
- package/lib/email-client/imap/mailbox.js +23 -24
- 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 +36 -26
- package/lib/email-client/message-builder.js +3 -3
- 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 +53 -54
- package/lib/email-client/smtp-pool-manager.js +1 -1
- package/lib/enum-descriptions.js +92 -2
- package/lib/export.js +1 -1
- package/lib/field-usage.js +133 -0
- package/lib/gateway.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 +15 -5
- package/lib/imapproxy/imap-server.js +27 -7
- package/lib/license-beacon.js +4 -9
- package/lib/lists.js +49 -1
- package/lib/llm-pre-process.js +5 -5
- package/lib/logger.js +5 -1
- package/lib/metrics-collector.js +2 -2
- package/lib/oauth/gmail.js +9 -12
- package/lib/oauth/mail-ru.js +5 -7
- package/lib/oauth/outlook.js +9 -9
- package/lib/oauth/pubsub/google.js +25 -10
- package/lib/oauth/scope-checker.js +1 -1
- package/lib/oauth2-apps.js +223 -294
- package/lib/openapi/build-document.js +15 -7
- package/lib/openapi/joi-schema.js +20 -0
- package/lib/outbox.js +85 -17
- package/lib/pre-process.js +8 -8
- package/lib/queue-stats.js +49 -0
- package/lib/read-env-value.js +1 -1
- 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 +216 -160
- package/lib/settings.js +84 -5
- package/lib/sub-script.js +2 -1
- package/lib/swagger-options.js +2 -1
- package/lib/templates.js +4 -4
- 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 +99 -15
- package/lib/tools.js +142 -37
- package/lib/ui-routes/account-routes.js +31 -11
- package/lib/ui-routes/admin-config-routes.js +18 -10
- package/lib/ui-routes/admin-entities-routes.js +66 -22
- package/lib/ui-routes/auth-routes.js +30 -24
- 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 +3 -3
- package/lib/ui-routes/route-helpers.js +51 -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/network.js +2 -2
- package/lib/web-safe-html.js +1 -1
- package/lib/webhook-routing.js +80 -0
- package/lib/webhooks.js +20 -14
- package/package.json +11 -10
- package/sbom.json +1 -1
- package/server.js +80 -41
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +136 -9
- package/static/js/reference.js +456 -10
- package/static/js/ui.js +43 -0
- package/static/licenses.html +51 -41
- package/translations/messages.pot +59 -59
- package/views/accounts/account.hbs +69 -7
- package/views/accounts/browse.hbs +18 -35
- package/views/config/logging.hbs +6 -0
- package/views/config/oauth/app.hbs +0 -2
- package/views/config/security.hbs +13 -0
- package/views/partials/oauth_form.hbs +0 -15
- package/views/partials/reference/disclosure.hbs +8 -2
- package/views/partials/reference/operation.hbs +47 -13
- package/views/partials/reference/params.hbs +17 -1
- package/views/partials/reference/schema-node.hbs +110 -52
- package/views/partials/reference/schema-tools.hbs +25 -0
- 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/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 +146 -57
- package/workers/documents.js +46 -26
- package/workers/export.js +20 -8
- package/workers/imap-proxy.js +2 -2
- package/workers/imap.js +12 -6
- package/workers/smtp.js +13 -7
- package/workers/submit.js +40 -30
- package/workers/webhooks.js +59 -25
- package/lib/feature-flags.js +0 -48
|
@@ -83,7 +83,7 @@ function authenticate(connection, token, requireClientToken, callback) {
|
|
|
83
83
|
action: 'fail',
|
|
84
84
|
cid: connection.id
|
|
85
85
|
},
|
|
86
|
-
'Authentication error for %s using %s
|
|
86
|
+
'Authentication error for %s using %s: %s',
|
|
87
87
|
username,
|
|
88
88
|
'PLAIN',
|
|
89
89
|
err.message
|
|
@@ -118,12 +118,12 @@ function authenticate(connection, token, requireClientToken, callback) {
|
|
|
118
118
|
method: 'PLAIN',
|
|
119
119
|
action: 'success',
|
|
120
120
|
cid: connection.id,
|
|
121
|
-
clientToken
|
|
121
|
+
clientToken: !!clientToken
|
|
122
122
|
},
|
|
123
123
|
'%s authenticated using %s%s',
|
|
124
124
|
username,
|
|
125
125
|
'PLAIN' + (requireClientToken ? '-CLIENTTOKEN' : ''),
|
|
126
|
-
clientToken ? ' with
|
|
126
|
+
clientToken ? ' with a client token' : ''
|
|
127
127
|
);
|
|
128
128
|
|
|
129
129
|
connection.setUser(response.user);
|
|
@@ -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
|
|
@@ -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
|
|
|
@@ -317,7 +317,23 @@ const createServer = function (options = {}) {
|
|
|
317
317
|
let server = new IMAPServer(options);
|
|
318
318
|
|
|
319
319
|
server.on('error', err => {
|
|
320
|
-
|
|
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
|
+
}
|
|
321
337
|
});
|
|
322
338
|
|
|
323
339
|
server.onAuth = function (login, session, callback) {
|
|
@@ -366,7 +382,7 @@ const createServer = function (options = {}) {
|
|
|
366
382
|
try {
|
|
367
383
|
downstream.imapClient.close();
|
|
368
384
|
} catch (err) {
|
|
369
|
-
proxyLogger.
|
|
385
|
+
proxyLogger.warn({ msg: 'Failed to close upstream connection', err });
|
|
370
386
|
}
|
|
371
387
|
|
|
372
388
|
try {
|
|
@@ -380,8 +396,8 @@ const createServer = function (options = {}) {
|
|
|
380
396
|
|
|
381
397
|
// Every terminal event from either leg funnels into the idempotent
|
|
382
398
|
// closeProxy(). The helper keeps that wiring declarative; pass a message
|
|
383
|
-
// to log (level defaults to '
|
|
384
|
-
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') => {
|
|
385
401
|
emitter.on(event, err => {
|
|
386
402
|
if (msg) {
|
|
387
403
|
let entry = { msg };
|
|
@@ -405,7 +421,7 @@ const createServer = function (options = {}) {
|
|
|
405
421
|
teardownOn(downstream.readSocket, 'end', 'Upstream connection closed', 'info');
|
|
406
422
|
|
|
407
423
|
downstream.readSocket.on('error', err => {
|
|
408
|
-
proxyLogger.
|
|
424
|
+
proxyLogger.warn({ msg: 'Upstream read error', err });
|
|
409
425
|
try {
|
|
410
426
|
// best-effort notice to the client before tearing down
|
|
411
427
|
upstream.socket.write('* BYE Upstream connection error\r\n');
|
|
@@ -446,26 +462,30 @@ const createServer = function (options = {}) {
|
|
|
446
462
|
})
|
|
447
463
|
.catch(err => {
|
|
448
464
|
if (err.authenticationFailed || err.serverResponseCode === 'AUTHENTICATIONFAILED') {
|
|
465
|
+
serverLogger.warn({ msg: 'Upstream authentication failed', account, cid: session.id, err });
|
|
449
466
|
let error = new Error(
|
|
450
467
|
`${err.serverResponseCode ? `[${err.serverResponseCode}] ` : ''}${err.responseText || err.message || 'Authentication failed'}`
|
|
451
468
|
);
|
|
452
469
|
error.response = err.responseStatus || 'NO';
|
|
453
470
|
return callback(error);
|
|
454
471
|
} else {
|
|
455
|
-
serverLogger.error({ msg: 'Failed to create proxy', err });
|
|
472
|
+
serverLogger.error({ msg: 'Failed to create proxy', account, cid: session.id, err });
|
|
456
473
|
return callback(err);
|
|
457
474
|
}
|
|
458
475
|
});
|
|
459
476
|
})
|
|
460
477
|
.catch(err => {
|
|
461
|
-
|
|
478
|
+
let entry = { msg: 'Authentication check failed', username: login.username, cid: session.id, remoteAddress: session.remoteAddress, err };
|
|
462
479
|
if (err.authenticationFailed || err.serverResponseCode === 'AUTHENTICATIONFAILED') {
|
|
480
|
+
// routine failed client login, not a proxy fault
|
|
481
|
+
serverLogger.warn(entry);
|
|
463
482
|
let error = new Error(
|
|
464
483
|
`${err.serverResponseCode ? `[${err.serverResponseCode}] ` : ''}${err.responseText || err.message || 'Authentication failed'}`
|
|
465
484
|
);
|
|
466
485
|
error.response = err.responseStatus || 'NO';
|
|
467
486
|
return callback(error);
|
|
468
487
|
}
|
|
488
|
+
serverLogger.error(entry);
|
|
469
489
|
return callback(err);
|
|
470
490
|
});
|
|
471
491
|
};
|
package/lib/license-beacon.js
CHANGED
|
@@ -23,7 +23,6 @@ const { getCounterValues, hasEnvValue, readEnvValue, getBoolean } = require('./t
|
|
|
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
|
@@ -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/oauth/gmail.js
CHANGED
|
@@ -176,7 +176,7 @@ const formatFetchBody = (searchParams, logRaw) => {
|
|
|
176
176
|
return data;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
for (let key of ['refresh_token', 'client_secret']) {
|
|
179
|
+
for (let key of ['refresh_token', 'client_secret', 'code']) {
|
|
180
180
|
if (data[key]) {
|
|
181
181
|
data[key] = formatPartialSecretKey(data[key]);
|
|
182
182
|
}
|
|
@@ -196,7 +196,7 @@ const formatFetchResponse = (responseObj, logRaw) => {
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
let data = structuredClone(responseObj);
|
|
199
|
-
for (let key of ['access_token', 'refresh_token']) {
|
|
199
|
+
for (let key of ['access_token', 'refresh_token', 'id_token']) {
|
|
200
200
|
if (data[key]) {
|
|
201
201
|
data[key] = logRaw ? data[key] : formatPartialSecretKey(data[key]);
|
|
202
202
|
}
|
|
@@ -379,7 +379,7 @@ class GmailOauth {
|
|
|
379
379
|
responseJson = await res.json();
|
|
380
380
|
} catch (err) {
|
|
381
381
|
if (this.logger) {
|
|
382
|
-
this.logger.error({ msg: 'Failed to
|
|
382
|
+
this.logger.error({ msg: 'Failed to parse JSON response', url: requestUrl, status: res.status, err });
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
385
|
|
|
@@ -413,7 +413,7 @@ class GmailOauth {
|
|
|
413
413
|
googleProjectId: this.googleProjectId,
|
|
414
414
|
serviceClientEmail: this.serviceClientEmail,
|
|
415
415
|
scopes: this.scopes,
|
|
416
|
-
code
|
|
416
|
+
code: formatPartialSecretKey(code)
|
|
417
417
|
};
|
|
418
418
|
try {
|
|
419
419
|
err.tokenRequest.response = responseJson || { error: 'Failed to parse response' };
|
|
@@ -494,7 +494,7 @@ class GmailOauth {
|
|
|
494
494
|
responseJson = await res.json();
|
|
495
495
|
} catch (err) {
|
|
496
496
|
if (this.logger) {
|
|
497
|
-
this.logger.error({ msg: 'Failed to
|
|
497
|
+
this.logger.error({ msg: 'Failed to parse JSON response', url: requestUrl, status: res.status, err });
|
|
498
498
|
}
|
|
499
499
|
}
|
|
500
500
|
|
|
@@ -613,7 +613,6 @@ class GmailOauth {
|
|
|
613
613
|
let err = new Error('OAuth2 request failed');
|
|
614
614
|
err.statusCode = res.status;
|
|
615
615
|
err.oauthRequest = {
|
|
616
|
-
o: 1,
|
|
617
616
|
url,
|
|
618
617
|
method,
|
|
619
618
|
provider: this.provider,
|
|
@@ -657,7 +656,7 @@ class GmailOauth {
|
|
|
657
656
|
// ignore
|
|
658
657
|
} finally {
|
|
659
658
|
if (this.logger) {
|
|
660
|
-
this.logger.
|
|
659
|
+
this.logger.warn(Object.assign({ msg: 'API request failed' }, err.oauthRequest));
|
|
661
660
|
}
|
|
662
661
|
}
|
|
663
662
|
|
|
@@ -665,11 +664,10 @@ class GmailOauth {
|
|
|
665
664
|
}
|
|
666
665
|
|
|
667
666
|
if (this.logger) {
|
|
668
|
-
this.logger.
|
|
667
|
+
this.logger.debug(
|
|
669
668
|
Object.assign(
|
|
670
669
|
{ msg: 'External API request completed' },
|
|
671
670
|
{
|
|
672
|
-
o: 2,
|
|
673
671
|
url,
|
|
674
672
|
method,
|
|
675
673
|
provider: this.provider,
|
|
@@ -695,7 +693,6 @@ class GmailOauth {
|
|
|
695
693
|
if (!['application/json', 'text/json'].includes(contentType)) {
|
|
696
694
|
let error = new Error('Expected JSON response for OAuth2 request');
|
|
697
695
|
error.oauthRequest = {
|
|
698
|
-
o: 3,
|
|
699
696
|
url,
|
|
700
697
|
method,
|
|
701
698
|
provider: this.provider,
|
|
@@ -717,7 +714,7 @@ class GmailOauth {
|
|
|
717
714
|
}
|
|
718
715
|
|
|
719
716
|
error.oauthRequest.response = {
|
|
720
|
-
|
|
717
|
+
length: responseText.length,
|
|
721
718
|
text: responseText.toString().substring(0, 5 * 1024)
|
|
722
719
|
};
|
|
723
720
|
throw error;
|
|
@@ -817,7 +814,7 @@ class GmailOauth {
|
|
|
817
814
|
}
|
|
818
815
|
} catch (err) {
|
|
819
816
|
if (this.logger) {
|
|
820
|
-
this.logger.
|
|
817
|
+
this.logger.warn({ msg: 'OAuth2 token revocation error', err });
|
|
821
818
|
}
|
|
822
819
|
}
|
|
823
820
|
}
|
package/lib/oauth/mail-ru.js
CHANGED
|
@@ -25,7 +25,7 @@ const formatFetchBody = (searchParams, logRaw) => {
|
|
|
25
25
|
return data;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
for (let key of ['refresh_token', 'client_secret']) {
|
|
28
|
+
for (let key of ['refresh_token', 'client_secret', 'code']) {
|
|
29
29
|
if (data[key]) {
|
|
30
30
|
data[key] = formatPartialSecretKey(data[key]);
|
|
31
31
|
}
|
|
@@ -40,7 +40,7 @@ const formatFetchResponse = (responseObj, logRaw) => {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
let data = structuredClone(responseObj);
|
|
43
|
-
for (let key of ['access_token', 'refresh_token']) {
|
|
43
|
+
for (let key of ['access_token', 'refresh_token', 'id_token']) {
|
|
44
44
|
if (data[key]) {
|
|
45
45
|
data[key] = logRaw ? data[key] : formatPartialSecretKey(data[key]);
|
|
46
46
|
}
|
|
@@ -125,7 +125,7 @@ class MailRuOauth {
|
|
|
125
125
|
responseJson = await res.json();
|
|
126
126
|
} catch (err) {
|
|
127
127
|
if (this.logger) {
|
|
128
|
-
this.logger.error({ msg: 'Failed to
|
|
128
|
+
this.logger.error({ msg: 'Failed to parse JSON response', url: requestUrl, status: res.status, err });
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -150,13 +150,12 @@ class MailRuOauth {
|
|
|
150
150
|
err.tokenRequest = {
|
|
151
151
|
url: requestUrl,
|
|
152
152
|
method,
|
|
153
|
-
authority: this.authority,
|
|
154
153
|
grant: 'authorization_code',
|
|
155
154
|
provider: this.provider,
|
|
156
155
|
status: res.status,
|
|
157
156
|
clientId: this.clientId,
|
|
158
157
|
scopes: this.scopes,
|
|
159
|
-
code
|
|
158
|
+
code: formatPartialSecretKey(code)
|
|
160
159
|
};
|
|
161
160
|
try {
|
|
162
161
|
err.tokenRequest.response = responseJson || { error: 'Failed to parse response' };
|
|
@@ -210,7 +209,7 @@ class MailRuOauth {
|
|
|
210
209
|
responseJson = await res.json();
|
|
211
210
|
} catch (err) {
|
|
212
211
|
if (this.logger) {
|
|
213
|
-
this.logger.error({ msg: 'Failed to
|
|
212
|
+
this.logger.error({ msg: 'Failed to parse JSON response', url: requestUrl, status: res.status, err });
|
|
214
213
|
}
|
|
215
214
|
}
|
|
216
215
|
|
|
@@ -235,7 +234,6 @@ class MailRuOauth {
|
|
|
235
234
|
err.tokenRequest = {
|
|
236
235
|
url: requestUrl,
|
|
237
236
|
method,
|
|
238
|
-
authority: this.authority,
|
|
239
237
|
grant: 'refresh_token',
|
|
240
238
|
provider: this.provider,
|
|
241
239
|
status: res.status,
|