emailengine-app 2.78.0 → 2.79.1
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 +68 -0
- package/config/e2e.toml +2 -1
- package/config/test.toml +2 -1
- package/data/google-crawlers.json +1 -1
- package/lib/account.js +112 -36
- 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 +401 -0
- package/lib/api-routes/route-helpers.js +294 -9
- package/lib/api-routes/route-metadata.js +28 -0
- package/lib/api-routes/settings-routes.js +66 -38
- 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 +526 -72
- package/lib/api-routes/webhook-route-routes.js +14 -4
- package/lib/arf-detect.js +17 -4
- package/lib/auth-token.js +80 -8
- package/lib/bounce-detect.js +28 -17
- package/lib/consts.js +16 -0
- package/lib/db.js +26 -2
- package/lib/delivery-error.js +30 -1
- package/lib/email-client/base-client.js +27 -41
- package/lib/email-client/gmail-client.js +23 -17
- package/lib/email-client/imap/mailbox.js +58 -59
- 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 +85 -28
- 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 +56 -64
- 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/lua/h-set-new-mark.lua +36 -0
- package/lib/message-port-stream.js +84 -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 +290 -292
- package/lib/openapi/build-document.js +20 -8
- 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 +218 -162
- package/lib/settings.js +98 -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 +231 -0
- package/lib/token-permission-view.js +219 -0
- package/lib/token-permissions.js +172 -0
- package/lib/tokens.js +247 -66
- package/lib/tools.js +142 -37
- package/lib/ui-routes/account-routes.js +42 -15
- package/lib/ui-routes/admin-config-routes.js +18 -10
- package/lib/ui-routes/admin-entities-routes.js +117 -38
- 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 +12 -12
- package/lib/ui-routes/reference-routes.js +3 -3
- package/lib/ui-routes/route-helpers.js +78 -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 +299 -0
- package/lib/ui-routes/unsubscribe-routes.js +19 -29
- package/lib/utils/decode-headers.js +42 -0
- package/lib/utils/header-map.js +48 -0
- package/lib/utils/network.js +2 -2
- package/lib/utils/unsafe-key.js +59 -0
- package/lib/web-safe-html.js +1 -1
- package/lib/webhook-routing.js +84 -0
- package/lib/webhooks.js +48 -14
- package/package.json +11 -10
- package/sbom.json +1 -1
- package/server.js +116 -55
- 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 +75 -13
- package/views/accounts/browse.hbs +19 -36
- package/views/accounts/edit.hbs +2 -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/gateways/edit.hbs +1 -1
- package/views/gateways/gateway.hbs +2 -2
- package/views/gateways/index.hbs +7 -7
- package/views/partials/accounts_table.hbs +7 -7
- 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 +10 -4
- package/views/templates/template.hbs +1 -1
- package/views/tokens/index.hbs +53 -6
- package/views/tokens/new.hbs +334 -5
- package/workers/api.js +185 -102
- package/workers/documents.js +46 -26
- package/workers/export.js +20 -8
- package/workers/imap-proxy.js +2 -2
- package/workers/imap.js +77 -78
- package/workers/smtp.js +13 -7
- package/workers/submit.js +40 -30
- package/workers/webhooks.js +80 -26
- package/lib/feature-flags.js +0 -48
package/lib/tools.js
CHANGED
|
@@ -8,6 +8,11 @@ const Joi = require('joi');
|
|
|
8
8
|
const he = require('he');
|
|
9
9
|
const packageData = require('../package.json');
|
|
10
10
|
const settings = require('./settings');
|
|
11
|
+
// Safe to require at load time despite db.js opening Redis clients: settings.js above already
|
|
12
|
+
// requires it, so db.js is in this file's dependency graph either way. db.js does not require
|
|
13
|
+
// tools.js back (it inlines readEnvValue precisely to avoid that), so there is no cycle.
|
|
14
|
+
const { QUEUES_BY_NAME } = require('./db');
|
|
15
|
+
const { queueStats } = require('./queue-stats');
|
|
11
16
|
const { brotliDecompress } = require('zlib');
|
|
12
17
|
const util = require('util');
|
|
13
18
|
const brotliDecompressAsync = util.promisify(brotliDecompress);
|
|
@@ -318,6 +323,72 @@ function resolveOAuthErrorStatus(responseError, err) {
|
|
|
318
323
|
return typeof fallback === 'number' && fallback >= 400 ? fallback : 500;
|
|
319
324
|
}
|
|
320
325
|
|
|
326
|
+
// Key names whose value must never be rendered into a validation message. Deliberately broad:
|
|
327
|
+
// a false positive only replaces the value with a placeholder in an error message, while a miss
|
|
328
|
+
// writes a credential to the log and returns it to the client.
|
|
329
|
+
const CREDENTIAL_KEY_REGEX = /pass|secret|token|key|seed|credential|signature/i;
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Strips the submitted values out of a joi ValidationError, in place, so it can be logged.
|
|
333
|
+
*
|
|
334
|
+
* A joi error exposes the rejected input in four places: the whole submitted payload in
|
|
335
|
+
* `_original`, the value in every detail context, and - for the `string.pattern` family, the only
|
|
336
|
+
* common rule that renders it - the value inlined into `message` and into the `stack` snapshot
|
|
337
|
+
* taken when the error was constructed. Deleting the first two is not enough, so values belonging
|
|
338
|
+
* to credential-shaped keys are masked in the text as well.
|
|
339
|
+
*/
|
|
340
|
+
function redactValidationError(err) {
|
|
341
|
+
if (!err || typeof err !== 'object') {
|
|
342
|
+
return err;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
delete err._original;
|
|
346
|
+
|
|
347
|
+
let secrets = new Set();
|
|
348
|
+
for (let detail of err.details || []) {
|
|
349
|
+
if (!detail.context) {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (typeof detail.context.value === 'string' && detail.context.value) {
|
|
354
|
+
if (CREDENTIAL_KEY_REGEX.test(detail.context.key) || CREDENTIAL_KEY_REGEX.test(detail.context.label)) {
|
|
355
|
+
secrets.add(detail.context.value);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
delete detail.context.value;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (!secrets.size) {
|
|
363
|
+
return err;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
let mask = text => {
|
|
367
|
+
for (let secret of secrets) {
|
|
368
|
+
text = text.replaceAll(secret, '(hidden)');
|
|
369
|
+
}
|
|
370
|
+
return text;
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
for (let detail of err.details || []) {
|
|
374
|
+
if (typeof detail.message === 'string') {
|
|
375
|
+
detail.message = mask(detail.message);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// `stack` is a plain string snapshot that already embeds the original message, so it has to be
|
|
380
|
+
// masked separately - reassigning `message` does not rewrite it
|
|
381
|
+
if (typeof err.stack === 'string') {
|
|
382
|
+
err.stack = mask(err.stack);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (typeof err.message === 'string') {
|
|
386
|
+
err.message = mask(err.message);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return err;
|
|
390
|
+
}
|
|
391
|
+
|
|
321
392
|
module.exports = {
|
|
322
393
|
// keep the re-export, lib/utils/to-camel-case.js holds it so pure modules can use it too
|
|
323
394
|
toCamelCase,
|
|
@@ -652,7 +723,10 @@ module.exports = {
|
|
|
652
723
|
});
|
|
653
724
|
|
|
654
725
|
if (error) {
|
|
655
|
-
|
|
726
|
+
// Every caller logs this error, and two of them (imap-client, message-builder) log it at
|
|
727
|
+
// error level to a logger that persists to the per-account log store and to Sentry. The
|
|
728
|
+
// raw joi error carries the auth server's `pass` and `accessToken` in `_original`.
|
|
729
|
+
throw redactValidationError(error);
|
|
656
730
|
}
|
|
657
731
|
|
|
658
732
|
return value;
|
|
@@ -1140,29 +1214,31 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
|
|
|
1140
1214
|
}
|
|
1141
1215
|
},
|
|
1142
1216
|
|
|
1217
|
+
redactValidationError,
|
|
1218
|
+
|
|
1143
1219
|
async failAction(request, h, err) {
|
|
1220
|
+
let error;
|
|
1144
1221
|
try {
|
|
1145
|
-
|
|
1222
|
+
redactValidationError(err);
|
|
1146
1223
|
|
|
1147
|
-
|
|
1224
|
+
let details = (err.details || []).map(detail => ({ message: detail.message, key: detail.context.key }));
|
|
1148
1225
|
|
|
1149
|
-
logger.
|
|
1226
|
+
request.logger.debug({
|
|
1150
1227
|
msg: 'Request failed',
|
|
1151
1228
|
method: request.method,
|
|
1152
1229
|
route: request.route.path,
|
|
1153
|
-
statusCode: request.response && request.response.statusCode,
|
|
1154
1230
|
err
|
|
1155
1231
|
});
|
|
1156
1232
|
|
|
1157
1233
|
let message = request.app.gt.gettext('Invalid input');
|
|
1158
|
-
|
|
1234
|
+
error = Boom.boomify(new Error(message), { statusCode: 400 });
|
|
1159
1235
|
error.output.payload.fields = details;
|
|
1160
|
-
|
|
1161
|
-
throw error;
|
|
1162
1236
|
} catch (E) {
|
|
1163
|
-
request.logger.error({ err: E });
|
|
1237
|
+
request.logger.error({ msg: 'Failed to process a validation failure', err: E });
|
|
1164
1238
|
throw E;
|
|
1165
1239
|
}
|
|
1240
|
+
|
|
1241
|
+
throw error;
|
|
1166
1242
|
},
|
|
1167
1243
|
|
|
1168
1244
|
async verifyAccountInfo(redis, accountData, logger) {
|
|
@@ -1264,7 +1340,7 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
|
|
|
1264
1340
|
response.mailboxes = mailboxList;
|
|
1265
1341
|
}
|
|
1266
1342
|
} catch (err) {
|
|
1267
|
-
logger.
|
|
1343
|
+
logger.debug({ msg: 'Account verification failed', err });
|
|
1268
1344
|
response.imap = {
|
|
1269
1345
|
success: false,
|
|
1270
1346
|
error: err.message,
|
|
@@ -1694,34 +1770,19 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
|
|
|
1694
1770
|
redisVersion = err.message;
|
|
1695
1771
|
}
|
|
1696
1772
|
|
|
1773
|
+
// Counted concurrently: the queues are independent, so serializing them only adds their
|
|
1774
|
+
// round trips together on a path that renders the admin dashboard. A queue that fails to
|
|
1775
|
+
// count is left out and the rest of the stats response still goes out.
|
|
1697
1776
|
let queues = {};
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
.
|
|
1704
|
-
.llen(`${REDIS_PREFIX}bull:${queue}:wait`)
|
|
1705
|
-
.llen(`${REDIS_PREFIX}bull:${queue}:paused`)
|
|
1706
|
-
.hget(`${REDIS_PREFIX}bull:${queue}:meta`, 'paused')
|
|
1707
|
-
.exec();
|
|
1708
|
-
if (resActive[0] || resDelayed[0] || resWaiting[0] || resPaused[0] || resMeta[0]) {
|
|
1709
|
-
// counting failed, skip this queue but keep the rest of the stats response
|
|
1710
|
-
logger.error({ msg: 'Failed to count queue length', queue, active: resActive, delayed: resDelayed, waiting: resWaiting });
|
|
1711
|
-
continue;
|
|
1777
|
+
await Promise.all(
|
|
1778
|
+
Object.entries(QUEUES_BY_NAME).map(async ([queue, queueObj]) => {
|
|
1779
|
+
try {
|
|
1780
|
+
queues[queue] = await queueStats(queueObj);
|
|
1781
|
+
} catch (err) {
|
|
1782
|
+
logger.error({ msg: 'Failed to count queue length', queue, err });
|
|
1712
1783
|
}
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
delayed: Number(resDelayed[1]) || 0,
|
|
1716
|
-
waiting: Number(resWaiting[1]) || 0,
|
|
1717
|
-
paused: Number(resPaused[1]) || 0,
|
|
1718
|
-
isPaused: !!Number(resMeta[1]) || false
|
|
1719
|
-
};
|
|
1720
|
-
queues[queue].total = queues[queue].active + queues[queue].delayed + queues[queue].waiting + queues[queue].paused;
|
|
1721
|
-
} catch (err) {
|
|
1722
|
-
logger.error({ msg: 'Failed to count queue length', queue, err });
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1784
|
+
})
|
|
1785
|
+
);
|
|
1725
1786
|
|
|
1726
1787
|
let stats = Object.assign(
|
|
1727
1788
|
{
|
|
@@ -1809,6 +1870,20 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
|
|
|
1809
1870
|
return secretKey.replace(/^(.{8}).*$/, `$1... (${secretKey.length}B)`);
|
|
1810
1871
|
},
|
|
1811
1872
|
|
|
1873
|
+
// Returns the URL with any embedded basic auth credentials removed, safe for logging. Never
|
|
1874
|
+
// throws: an unparseable value is replaced with a static placeholder rather than echoed back,
|
|
1875
|
+
// because the raw string could itself carry the credentials that made it unparseable.
|
|
1876
|
+
redactUrlCredentials(url) {
|
|
1877
|
+
try {
|
|
1878
|
+
let parsed = new URL(url);
|
|
1879
|
+
parsed.username = '';
|
|
1880
|
+
parsed.password = '';
|
|
1881
|
+
return parsed.toString();
|
|
1882
|
+
} catch {
|
|
1883
|
+
return 'invalid url';
|
|
1884
|
+
}
|
|
1885
|
+
},
|
|
1886
|
+
|
|
1812
1887
|
validUidValidity(value) {
|
|
1813
1888
|
if (typeof value === 'bigint') {
|
|
1814
1889
|
return value > BigInt(0);
|
|
@@ -1919,6 +1994,36 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
|
|
|
1919
1994
|
return { data: data.toString('base64url'), signature };
|
|
1920
1995
|
},
|
|
1921
1996
|
|
|
1997
|
+
// Builds the signed public subscription-management URL for one recipient on one list - the
|
|
1998
|
+
// same URL every outgoing message with a listId embeds as its List-Unsubscribe target, and
|
|
1999
|
+
// the page where a recipient can re-subscribe. Shared by the mailer (lib/email-client/
|
|
2000
|
+
// base-client.js) and the suppression-list admin UI so the two cannot drift. The signed blob
|
|
2001
|
+
// deliberately carries no nonce and no expiry (see parseSignedFormData): the link stays
|
|
2002
|
+
// valid for as long as the service secret does. messageId is optional - admin generated
|
|
2003
|
+
// links have no originating message. Returns an absolute URL when baseUrl is set and a
|
|
2004
|
+
// host-relative one when it is not, so a missing service URL never leaks a placeholder host.
|
|
2005
|
+
buildUnsubscribeUrl(serviceSecret, baseUrl, opts) {
|
|
2006
|
+
let payload = {
|
|
2007
|
+
act: 'unsub',
|
|
2008
|
+
acc: opts.account,
|
|
2009
|
+
list: opts.list,
|
|
2010
|
+
rcpt: opts.recipient
|
|
2011
|
+
};
|
|
2012
|
+
if (opts.messageId) {
|
|
2013
|
+
payload.msg = opts.messageId;
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
let { data: signedData, signature } = module.exports.getSignedFormDataSync(serviceSecret, payload, true);
|
|
2017
|
+
|
|
2018
|
+
let unsubscribeUrlObj = new URL('/unsubscribe', baseUrl || 'http://localhost');
|
|
2019
|
+
unsubscribeUrlObj.searchParams.append('data', signedData);
|
|
2020
|
+
if (signature) {
|
|
2021
|
+
unsubscribeUrlObj.searchParams.append('sig', signature);
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
return baseUrl ? unsubscribeUrlObj.href : unsubscribeUrlObj.pathname + unsubscribeUrlObj.search;
|
|
2025
|
+
},
|
|
2026
|
+
|
|
1922
2027
|
// Fail-closed HMAC check for service-secret-signed blobs, shared by every verification site.
|
|
1923
2028
|
// getServiceSecret() generates and persists a secret when missing, so verification is never
|
|
1924
2029
|
// silently skipped (an empty secret would otherwise accept forged, unsigned data). Returns true
|
|
@@ -2206,7 +2311,7 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg
|
|
|
2206
2311
|
logger.trace({ msg: 'Loaded environment TLS value from file', path, file: ref[path] });
|
|
2207
2312
|
delete ref[path];
|
|
2208
2313
|
} catch (err) {
|
|
2209
|
-
logger.
|
|
2314
|
+
logger.error({ msg: 'Failed to load TLS value from file', path, file: ref[path], err });
|
|
2210
2315
|
ref[key] = null;
|
|
2211
2316
|
}
|
|
2212
2317
|
}
|
|
@@ -42,7 +42,9 @@ const {
|
|
|
42
42
|
ACCOUNT_DISPLAY_STATES,
|
|
43
43
|
signedFormBlobFields: signedBlobFields
|
|
44
44
|
} = require('../schemas');
|
|
45
|
-
const { formatAccountData, cachedTemplates, identityErrorView, ACCOUNT_STATE_DISPLAY } = require('./route-helpers');
|
|
45
|
+
const { formatAccountData, cachedTemplates, identityErrorView, ACCOUNT_STATE_DISPLAY, adminUrl } = require('./route-helpers');
|
|
46
|
+
const { webhooks: Webhooks } = require('../webhooks');
|
|
47
|
+
const { describeEffectiveRouting, isDeliverableRoute } = require('../webhook-routing');
|
|
46
48
|
const { matchesExpectedIdentity, resolveExpectedIdentity } = require('../account/expected-identity');
|
|
47
49
|
|
|
48
50
|
const { REDIS_PREFIX, DEFAULT_PAGE_SIZE, NONCE_BYTES, MAX_FORM_TTL, MAX_FORM_PROBE_ATTEMPTS } = consts;
|
|
@@ -327,7 +329,7 @@ function init(args) {
|
|
|
327
329
|
}
|
|
328
330
|
|
|
329
331
|
await request.flash({ type: 'danger', message: `Failed to set up account${errors.account ? `: ${errors.account}` : ''}` });
|
|
330
|
-
request.logger.
|
|
332
|
+
request.logger.debug({ msg: 'Failed to update configuration', err });
|
|
331
333
|
|
|
332
334
|
return h.redirect('/admin/accounts').takeover();
|
|
333
335
|
},
|
|
@@ -489,7 +491,7 @@ function init(args) {
|
|
|
489
491
|
},
|
|
490
492
|
|
|
491
493
|
async failAction(request, h, err) {
|
|
492
|
-
request.logger.
|
|
494
|
+
request.logger.debug({ msg: 'Failed to validate request arguments', err });
|
|
493
495
|
let error = Boom.boomify(new Error(request.app.gt.gettext('Invalid request. Check your input and try again.')), { statusCode: 400 });
|
|
494
496
|
if (err.code) {
|
|
495
497
|
error.output.payload.code = err.code;
|
|
@@ -521,7 +523,7 @@ function init(args) {
|
|
|
521
523
|
},
|
|
522
524
|
|
|
523
525
|
async failAction(request, h, err) {
|
|
524
|
-
request.logger.
|
|
526
|
+
request.logger.debug({ msg: 'Failed to validate request arguments', err });
|
|
525
527
|
let error = Boom.boomify(new Error(request.app.gt.gettext('Invalid request. Check your input and try again.')), { statusCode: 400 });
|
|
526
528
|
if (err.code) {
|
|
527
529
|
error.output.payload.code = err.code;
|
|
@@ -737,7 +739,7 @@ function init(args) {
|
|
|
737
739
|
try {
|
|
738
740
|
serverSettings = await autodetectImapSettings(request.payload.email, request.app.gt);
|
|
739
741
|
} catch (err) {
|
|
740
|
-
request.logger.
|
|
742
|
+
request.logger.debug({ msg: 'Failed to resolve email server settings', email: request.payload.email, err });
|
|
741
743
|
}
|
|
742
744
|
|
|
743
745
|
let values = Object.assign(
|
|
@@ -801,7 +803,7 @@ function init(args) {
|
|
|
801
803
|
}
|
|
802
804
|
|
|
803
805
|
await request.flash({ type: 'danger', message: request.app.gt.gettext("Couldn't set up account. Try again.") });
|
|
804
|
-
request.logger.
|
|
806
|
+
request.logger.debug({ msg: 'Failed to process account', err });
|
|
805
807
|
|
|
806
808
|
// Repopulate the form (crucially the signed data/sig blob) from what was submitted;
|
|
807
809
|
// without it the hidden inputs render empty and the corrected re-submit fails the
|
|
@@ -1104,7 +1106,7 @@ function init(args) {
|
|
|
1104
1106
|
}
|
|
1105
1107
|
|
|
1106
1108
|
await request.flash({ type: 'danger', message: request.app.gt.gettext("Couldn't set up account. Try again.") });
|
|
1107
|
-
request.logger.
|
|
1109
|
+
request.logger.debug({ msg: 'Failed to process account', err });
|
|
1108
1110
|
|
|
1109
1111
|
// Rebuild the re-render values from the SAME schema that just validated the submission
|
|
1110
1112
|
// (coerces the tri-state checkboxes, strips unknown/prototype keys, drops both plaintext
|
|
@@ -1152,7 +1154,7 @@ function init(args) {
|
|
|
1152
1154
|
// lookup failure must never break the error re-render (failAction must not throw).
|
|
1153
1155
|
// Do NOT cache on failure - an exhausted probe cap or transient DNS error should
|
|
1154
1156
|
// not poison the hint for the whole TTL.
|
|
1155
|
-
request.logger.
|
|
1157
|
+
request.logger.debug({ msg: 'Failed to resolve app-password hint for form re-render', err });
|
|
1156
1158
|
}
|
|
1157
1159
|
}
|
|
1158
1160
|
}
|
|
@@ -1361,6 +1363,29 @@ function init(args) {
|
|
|
1361
1363
|
};
|
|
1362
1364
|
}
|
|
1363
1365
|
|
|
1366
|
+
const [webhookSettings, webhookRoutesList] = await Promise.all([
|
|
1367
|
+
settings.getMulti('webhooksEnabled', 'webhooks', 'webhookEvents', 'inboxNewOnly', 'webhooksCustomHeaders'),
|
|
1368
|
+
Webhooks.list(0, 1000)
|
|
1369
|
+
]);
|
|
1370
|
+
|
|
1371
|
+
// The listing carries route metadata only, but the worker's delivery gate also
|
|
1372
|
+
// requires a filter script, so the card needs the filter-presence markers for the
|
|
1373
|
+
// routes it is about to present as delivering
|
|
1374
|
+
const routeFilterInfo = await Webhooks.getFilterInfo(webhookRoutesList.webhooks.filter(isDeliverableRoute).map(route => route.id));
|
|
1375
|
+
|
|
1376
|
+
const webhookRouting = describeEffectiveRouting({
|
|
1377
|
+
webhooksEnabled: webhookSettings.webhooksEnabled,
|
|
1378
|
+
globalWebhooks: webhookSettings.webhooks,
|
|
1379
|
+
accountWebhooks: accountData.webhooks,
|
|
1380
|
+
webhookEvents: webhookSettings.webhookEvents,
|
|
1381
|
+
inboxNewOnly: webhookSettings.inboxNewOnly,
|
|
1382
|
+
globalCustomHeaders: webhookSettings.webhooksCustomHeaders,
|
|
1383
|
+
accountCustomHeaders: accountData.webhooksCustomHeaders,
|
|
1384
|
+
// Non-deliverable routes were not probed; their hasFilter stays undefined, which
|
|
1385
|
+
// describeEffectiveRouting() reads as "unknown" (and filters them out anyway)
|
|
1386
|
+
routes: webhookRoutesList.webhooks.map(route => Object.assign({}, route, { hasFilter: routeFilterInfo.get(route.id) }))
|
|
1387
|
+
});
|
|
1388
|
+
|
|
1364
1389
|
return h.view(
|
|
1365
1390
|
'accounts/account',
|
|
1366
1391
|
{
|
|
@@ -1407,7 +1432,9 @@ function init(args) {
|
|
|
1407
1432
|
t: Date.now()
|
|
1408
1433
|
}),
|
|
1409
1434
|
|
|
1410
|
-
showAdvanced: accountData.proxy || accountData.
|
|
1435
|
+
showAdvanced: accountData.proxy || accountData.path,
|
|
1436
|
+
|
|
1437
|
+
webhookRouting,
|
|
1411
1438
|
|
|
1412
1439
|
subConnectionInfo,
|
|
1413
1440
|
|
|
@@ -1457,8 +1484,8 @@ function init(args) {
|
|
|
1457
1484
|
return h.redirect('/admin/accounts');
|
|
1458
1485
|
} catch (err) {
|
|
1459
1486
|
await request.flash({ type: 'danger', message: `Couldn't delete account. Try again.` });
|
|
1460
|
-
request.logger.error({ msg: 'Failed to delete the account', err, account: request.
|
|
1461
|
-
return h.redirect(`/admin/accounts/${request.params.account}`);
|
|
1487
|
+
request.logger.error({ msg: 'Failed to delete the account', err, account: request.params.account, remoteAddress: request.app.ip });
|
|
1488
|
+
return h.redirect(adminUrl`/admin/accounts/${request.params.account}`);
|
|
1462
1489
|
}
|
|
1463
1490
|
},
|
|
1464
1491
|
options: {
|
|
@@ -1489,7 +1516,7 @@ function init(args) {
|
|
|
1489
1516
|
async handler(request) {
|
|
1490
1517
|
let account = request.params.account;
|
|
1491
1518
|
try {
|
|
1492
|
-
request.logger.info({ msg: '
|
|
1519
|
+
request.logger.info({ msg: 'Requesting account reconnect', account });
|
|
1493
1520
|
try {
|
|
1494
1521
|
await call({ cmd: 'reconnect', account });
|
|
1495
1522
|
} catch (err) {
|
|
@@ -1704,7 +1731,7 @@ function init(args) {
|
|
|
1704
1731
|
const canReadMail = (accountData.imap || accountData.oauth2) && !(accountData.imap && accountData.imap.disabled) && !DISABLE_MESSAGE_BROWSER;
|
|
1705
1732
|
if (!canReadMail) {
|
|
1706
1733
|
await request.flash({ type: 'danger', message: `Mail access is disabled for this account` });
|
|
1707
|
-
return h.redirect(`/admin/accounts/${request.params.account}`);
|
|
1734
|
+
return h.redirect(adminUrl`/admin/accounts/${request.params.account}`);
|
|
1708
1735
|
}
|
|
1709
1736
|
|
|
1710
1737
|
return h.view(
|
|
@@ -1935,7 +1962,7 @@ function init(args) {
|
|
|
1935
1962
|
|
|
1936
1963
|
await accountObject.update(updates);
|
|
1937
1964
|
|
|
1938
|
-
return h.redirect(`/admin/accounts/${request.params.account}`);
|
|
1965
|
+
return h.redirect(adminUrl`/admin/accounts/${request.params.account}`);
|
|
1939
1966
|
} catch (err) {
|
|
1940
1967
|
await request.flash({ type: 'danger', message: `Couldn't save account settings. Try again.` });
|
|
1941
1968
|
request.logger.error({ msg: 'Failed to update account settings', err, account: request.params.account });
|
|
@@ -1995,7 +2022,7 @@ function init(args) {
|
|
|
1995
2022
|
}
|
|
1996
2023
|
|
|
1997
2024
|
await request.flash({ type: 'danger', message: `Couldn't save settings. Try again.` });
|
|
1998
|
-
request.logger.
|
|
2025
|
+
request.logger.debug({ msg: 'Failed to update configuration', err });
|
|
1999
2026
|
|
|
2000
2027
|
let accountObject = new Account({ redis, account: request.params.account, call, secret: await getSecret() });
|
|
2001
2028
|
let accountData = await accountObject.loadAccountData();
|
|
@@ -381,6 +381,7 @@ function init(args) {
|
|
|
381
381
|
schema: {
|
|
382
382
|
serviceSecret: settingsSchema.serviceSecret,
|
|
383
383
|
ignoreMailCertErrors: settingsSchema.ignoreMailCertErrors.default(false),
|
|
384
|
+
tokenAuditLog: settingsSchema.tokenAuditLog.default(false),
|
|
384
385
|
|
|
385
386
|
// Following options can only be changed via the UI
|
|
386
387
|
enableOAuthTokensApi: Joi.boolean()
|
|
@@ -392,13 +393,14 @@ function init(args) {
|
|
|
392
393
|
},
|
|
393
394
|
|
|
394
395
|
async loadValues() {
|
|
395
|
-
const storedValues = await settings.getMulti('serviceSecret', 'disableTokens', 'enableOAuthTokensApi', 'ignoreMailCertErrors');
|
|
396
|
+
const storedValues = await settings.getMulti('serviceSecret', 'disableTokens', 'enableOAuthTokensApi', 'ignoreMailCertErrors', 'tokenAuditLog');
|
|
396
397
|
|
|
397
398
|
return {
|
|
398
399
|
serviceSecret: storedValues.serviceSecret || null,
|
|
399
400
|
enableTokens: !storedValues.disableTokens,
|
|
400
401
|
enableOAuthTokensApi: storedValues.enableOAuthTokensApi || false,
|
|
401
|
-
ignoreMailCertErrors: storedValues.ignoreMailCertErrors || false
|
|
402
|
+
ignoreMailCertErrors: storedValues.ignoreMailCertErrors || false,
|
|
403
|
+
tokenAuditLog: storedValues.tokenAuditLog || false
|
|
402
404
|
};
|
|
403
405
|
},
|
|
404
406
|
|
|
@@ -413,7 +415,8 @@ function init(args) {
|
|
|
413
415
|
let data = {
|
|
414
416
|
disableTokens: !request.payload.enableTokens,
|
|
415
417
|
enableOAuthTokensApi: request.payload.enableOAuthTokensApi,
|
|
416
|
-
ignoreMailCertErrors: request.payload.ignoreMailCertErrors
|
|
418
|
+
ignoreMailCertErrors: request.payload.ignoreMailCertErrors,
|
|
419
|
+
tokenAuditLog: request.payload.tokenAuditLog
|
|
417
420
|
};
|
|
418
421
|
|
|
419
422
|
// Only overwrite the service secret when a non-empty value is provided: an empty
|
|
@@ -767,7 +770,7 @@ return true;`
|
|
|
767
770
|
|
|
768
771
|
return { success: true, models };
|
|
769
772
|
} catch (err) {
|
|
770
|
-
request.logger.
|
|
773
|
+
request.logger.warn({ msg: 'Failed to reload OpenAI models', err });
|
|
771
774
|
return {
|
|
772
775
|
success: false,
|
|
773
776
|
error: err.message
|
|
@@ -817,7 +820,7 @@ return true;`
|
|
|
817
820
|
},
|
|
818
821
|
|
|
819
822
|
async failAction(request, h, err) {
|
|
820
|
-
request.logger.
|
|
823
|
+
request.logger.debug({ msg: 'Failed to process preview', err });
|
|
821
824
|
return h.redirect('/admin').takeover();
|
|
822
825
|
},
|
|
823
826
|
|
|
@@ -932,7 +935,10 @@ return true;`
|
|
|
932
935
|
// checkbox must render as checked regardless of the stored setting - also on
|
|
933
936
|
// error re-renders, where the disabled (unsubmitted) field is absent from
|
|
934
937
|
// the payload
|
|
935
|
-
sentryChecked: sentryEnvManaged || !!values.sentryEnabled
|
|
938
|
+
sentryChecked: sentryEnvManaged || !!values.sentryEnabled,
|
|
939
|
+
// reporting was turned on by trial activation, not by the operator; disclosed
|
|
940
|
+
// on the page because saving the form converts it into an explicit choice
|
|
941
|
+
sentryTrialManaged: !sentryEnvManaged && !!(await settings.get('sentryAutoEnabled'))
|
|
936
942
|
};
|
|
937
943
|
},
|
|
938
944
|
|
|
@@ -1100,7 +1106,9 @@ return true;`
|
|
|
1100
1106
|
duration
|
|
1101
1107
|
};
|
|
1102
1108
|
} catch (err) {
|
|
1103
|
-
|
|
1109
|
+
// log the parsed URL, not the raw payload value, so embedded basic-auth credentials
|
|
1110
|
+
// stay out of the log
|
|
1111
|
+
request.logger.warn({ msg: 'Failed to post test webhook', webhooks: parsed.toString(), event: 'test', err });
|
|
1104
1112
|
return {
|
|
1105
1113
|
success: false,
|
|
1106
1114
|
target: webhooks,
|
|
@@ -1207,7 +1215,7 @@ return true;`
|
|
|
1207
1215
|
return h.redirect('/admin/config/license');
|
|
1208
1216
|
} catch (err) {
|
|
1209
1217
|
await request.flash({ type: 'danger', message: `Couldn't register license. Check the key and try again.` });
|
|
1210
|
-
request.logger.
|
|
1218
|
+
request.logger.warn({ msg: 'Failed to register license key', err });
|
|
1211
1219
|
|
|
1212
1220
|
return h.view(
|
|
1213
1221
|
'config/license',
|
|
@@ -1249,7 +1257,7 @@ return true;`
|
|
|
1249
1257
|
}
|
|
1250
1258
|
|
|
1251
1259
|
await request.flash({ type: 'danger', message: `Couldn't register license. Check the key and try again.` });
|
|
1252
|
-
request.logger.
|
|
1260
|
+
request.logger.warn({ msg: 'Failed to register license key', err });
|
|
1253
1261
|
|
|
1254
1262
|
return h
|
|
1255
1263
|
.view(
|
|
@@ -1302,7 +1310,7 @@ return true;`
|
|
|
1302
1310
|
return h.redirect('/admin/config/license');
|
|
1303
1311
|
} catch (err) {
|
|
1304
1312
|
await request.flash({ type: 'danger', message: `Couldn't remove license. Try again.` });
|
|
1305
|
-
request.logger.error({ msg: 'Failed to unregister license key', err,
|
|
1313
|
+
request.logger.error({ msg: 'Failed to unregister license key', err, remoteAddress: request.app.ip });
|
|
1306
1314
|
return h.redirect('/admin/config/license');
|
|
1307
1315
|
}
|
|
1308
1316
|
},
|