emailengine-app 2.79.7 → 2.79.8
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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +17 -0
- package/DOCKER_DEPLOYMENT.md +2 -0
- package/bin/emailengine.js +29 -13
- package/config/default.toml +13 -3
- package/data/google-crawlers.json +7 -1
- package/docker-compose.yml +12 -3
- package/install.sh +2 -0
- package/lib/api-routes/account-routes.js +14 -3
- package/lib/api-routes/mailbox-routes.js +4 -1
- package/lib/api-routes/message-routes.js +6 -5
- package/lib/api-routes/outbox-routes.js +7 -4
- package/lib/api-routes/settings-routes.js +34 -25
- package/lib/api-routes/stats-routes.js +8 -1
- package/lib/api-routes/submit-routes.js +2 -1
- package/lib/api-routes/template-routes.js +3 -2
- package/lib/bounce-detect.js +45 -0
- package/lib/consts.js +5 -1
- package/lib/egress-filter.js +39 -4
- package/lib/email-client/base-client.js +274 -24
- package/lib/email-client/gmail/gmail-api.js +15 -7
- package/lib/email-client/gmail-client.js +121 -64
- package/lib/email-client/imap/mailbox.js +18 -59
- package/lib/email-client/imap-client.js +53 -29
- package/lib/email-client/notification-handler.js +11 -2
- package/lib/email-client/outlook/graph-api.js +106 -90
- package/lib/email-client/outlook-client.js +222 -106
- package/lib/generate-text-preview.js +10 -5
- package/lib/headers-rewriter.js +1 -1
- package/lib/llm-pre-process.js +4 -1
- package/lib/mcp/json-schema.js +50 -2
- package/lib/outbox.js +22 -5
- package/lib/pre-process.js +4 -1
- package/lib/rewrite-text-nodes.js +12 -1
- package/lib/schemas.js +27 -5
- package/lib/settings.js +19 -1
- package/lib/sso.js +13 -3
- package/lib/submit-progress.js +29 -0
- package/lib/templates.js +11 -0
- package/lib/tools.js +96 -53
- package/lib/ui-routes/account-routes.js +70 -11
- package/lib/ui-routes/admin-config-routes.js +7 -21
- package/lib/ui-routes/admin-entities-routes.js +42 -12
- package/lib/ui-routes/auth-routes.js +87 -28
- package/lib/ui-routes/dashboard-routes.js +1 -1
- package/lib/ui-routes/internals-routes.js +2 -0
- package/lib/ui-routes/mcp-consent-routes.js +5 -2
- package/lib/ui-routes/network-config-routes.js +2 -2
- package/lib/ui-routes/oauth-config-routes.js +12 -1
- package/lib/ui-routes/route-helpers.js +41 -6
- package/lib/ui-routes/settings-page.js +10 -0
- package/lib/ui-routes/suppression-list-routes.js +16 -5
- package/lib/ui-routes/unsubscribe-routes.js +22 -3
- package/lib/webhooks.js +14 -2
- package/package.json +11 -11
- package/sbom.json +1 -1
- package/server.js +63 -35
- package/static/css/flyonui.css +1 -1
- package/static/licenses.html +17 -17
- package/translations/messages.pot +49 -49
- package/views/account/passkeys.hbs +8 -0
- package/views/account/password.hbs +11 -0
- package/views/account/security.hbs +18 -7
- package/views/accounts/account.hbs +6 -1
- package/views/accounts/register/imap-server.hbs +10 -2
- package/views/config/ai.hbs +2 -0
- package/views/config/branding.hbs +2 -0
- package/views/config/email-processing.hbs +2 -0
- package/views/config/imap-proxy.hbs +2 -0
- package/views/config/logging.hbs +3 -1
- package/views/config/mcp.hbs +2 -0
- package/views/config/network.hbs +2 -0
- package/views/config/oauth/app.hbs +2 -2
- package/views/config/security.hbs +2 -0
- package/views/config/service.hbs +2 -0
- package/views/config/smtp.hbs +2 -0
- package/views/config/webhooks.hbs +2 -0
- package/views/error.hbs +6 -0
- package/views/layout/app.hbs +6 -3
- package/views/layout/login.hbs +1 -1
- package/views/layout/prompt.hbs +1 -1
- package/views/layout/public.hbs +1 -1
- package/views/legal.hbs +1 -1
- package/views/partials/filter_editor_js.hbs +1 -1
- package/views/partials/oauth_form.hbs +5 -5
- package/views/partials/ui/env-managed-alert.hbs +19 -0
- package/views/partials/webhook_form.hbs +1 -1
- package/views/unsubscribe.hbs +6 -0
- package/workers/api.js +137 -63
- package/workers/imap.js +32 -3
- package/workers/smtp.js +7 -0
- package/workers/submit.js +25 -1
- package/workers/webhooks.js +13 -17
- package/lib/reconnection-manager.js +0 -106
|
@@ -42,7 +42,16 @@ const {
|
|
|
42
42
|
ACCOUNT_DISPLAY_STATES,
|
|
43
43
|
signedFormBlobFields: signedBlobFields
|
|
44
44
|
} = require('../schemas');
|
|
45
|
-
const {
|
|
45
|
+
const {
|
|
46
|
+
formatAccountData,
|
|
47
|
+
cachedTemplates,
|
|
48
|
+
identityErrorView,
|
|
49
|
+
ACCOUNT_STATE_DISPLAY,
|
|
50
|
+
adminUrl,
|
|
51
|
+
accountSuggestions,
|
|
52
|
+
isClientError,
|
|
53
|
+
closedAfterConnectMessage
|
|
54
|
+
} = require('./route-helpers');
|
|
46
55
|
const { webhooks: Webhooks } = require('../webhooks');
|
|
47
56
|
const { describeEffectiveRouting, isDeliverableRoute } = require('../webhook-routing');
|
|
48
57
|
const { matchesExpectedIdentity, resolveExpectedIdentity } = require('../account/expected-identity');
|
|
@@ -141,10 +150,6 @@ function init(args) {
|
|
|
141
150
|
|
|
142
151
|
const accounts = await accountObject.listAccounts(request.query.state, request.query.query, request.query.page - 1, request.query.pageSize);
|
|
143
152
|
|
|
144
|
-
if (accounts.pages < request.query.page) {
|
|
145
|
-
request.query.page = accounts.pages;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
153
|
for (let account of accounts.accounts) {
|
|
149
154
|
let accountObject = new Account({ redis, account: account.account });
|
|
150
155
|
try {
|
|
@@ -189,6 +194,13 @@ function init(args) {
|
|
|
189
194
|
return url.pathname + url.search;
|
|
190
195
|
};
|
|
191
196
|
|
|
197
|
+
// A page past the end lists nothing, and the view renders its page links only
|
|
198
|
+
// around a non-empty listing, so it would show "No accounts found" with no way
|
|
199
|
+
// back - send it to the last page instead
|
|
200
|
+
if (accounts.pages && request.query.page > accounts.pages) {
|
|
201
|
+
return h.redirect(getPagingUrl(accounts.pages, request.query.state, request.query.query));
|
|
202
|
+
}
|
|
203
|
+
|
|
192
204
|
if (accounts.pages > accounts.page + 1) {
|
|
193
205
|
nextPage = getPagingUrl(accounts.page + 2, request.query.state, request.query.query);
|
|
194
206
|
}
|
|
@@ -806,6 +818,10 @@ function init(args) {
|
|
|
806
818
|
{
|
|
807
819
|
pageTitleFull: request.app.gt.gettext('Email Account Setup'),
|
|
808
820
|
values,
|
|
821
|
+
// Nothing resolved for the domain, so the server fields come up empty - the
|
|
822
|
+
// page says why rather than looking like a form that forgot its defaults
|
|
823
|
+
autodetectFailed: !serverSettings,
|
|
824
|
+
autodetectDomain: request.payload.email.split('@').pop(),
|
|
809
825
|
autoTest:
|
|
810
826
|
values._source &&
|
|
811
827
|
values.imap_auth_user &&
|
|
@@ -925,13 +941,47 @@ function init(args) {
|
|
|
925
941
|
|
|
926
942
|
if (verifyResult) {
|
|
927
943
|
if (verifyResult.imap && verifyResult.imap.error && verifyResult.imap.code) {
|
|
944
|
+
// The same translation the SMTP branch below does for its codes: the raw
|
|
945
|
+
// socket or ImapFlow error text is not something the person at the form
|
|
946
|
+
// can act on. Closed-after-connect keeps the TLS hint the account state
|
|
947
|
+
// badge shows for it, because a wrong port/TLS pairing is the usual cause.
|
|
928
948
|
switch (verifyResult.imap.code) {
|
|
929
949
|
case 'ENOTFOUND':
|
|
950
|
+
case 'EAI_AGAIN':
|
|
930
951
|
verifyResult.imap.error = request.app.gt.gettext('Server hostname was not found');
|
|
931
952
|
break;
|
|
932
953
|
case 'AUTHENTICATIONFAILED':
|
|
933
954
|
verifyResult.imap.error = request.app.gt.gettext('Invalid username or password');
|
|
934
955
|
break;
|
|
956
|
+
case 'ETIMEDOUT':
|
|
957
|
+
case 'ETIMEOUT':
|
|
958
|
+
case 'GREETING_TIMEOUT':
|
|
959
|
+
verifyResult.imap.error = request.app.gt.gettext('Connection timed out');
|
|
960
|
+
break;
|
|
961
|
+
case 'ECONNREFUSED':
|
|
962
|
+
case 'ECONNRESET':
|
|
963
|
+
case 'EHOSTUNREACH':
|
|
964
|
+
case 'ENETUNREACH':
|
|
965
|
+
verifyResult.imap.error = request.app.gt.gettext('Could not connect to server');
|
|
966
|
+
break;
|
|
967
|
+
case 'ClosedAfterConnectTLS':
|
|
968
|
+
case 'ClosedAfterConnectText':
|
|
969
|
+
verifyResult.imap.error = closedAfterConnectMessage(verifyResult.imap.code, request.app.gt);
|
|
970
|
+
break;
|
|
971
|
+
case 'EPROTO':
|
|
972
|
+
case 'ERR_TLS_CERT_ALTNAME_INVALID':
|
|
973
|
+
case 'ERR_SSL_WRONG_VERSION_NUMBER':
|
|
974
|
+
case 'CERT_HAS_EXPIRED':
|
|
975
|
+
case 'DEPTH_ZERO_SELF_SIGNED_CERT':
|
|
976
|
+
case 'SELF_SIGNED_CERT_IN_CHAIN':
|
|
977
|
+
case 'UNABLE_TO_VERIFY_LEAF_SIGNATURE':
|
|
978
|
+
verifyResult.imap.error = request.app.gt.gettext('TLS protocol error');
|
|
979
|
+
break;
|
|
980
|
+
default:
|
|
981
|
+
if (/openssl|ssl routines/i.test(verifyResult.imap.error)) {
|
|
982
|
+
verifyResult.imap.error = request.app.gt.gettext('TLS protocol error');
|
|
983
|
+
}
|
|
984
|
+
break;
|
|
935
985
|
}
|
|
936
986
|
}
|
|
937
987
|
|
|
@@ -1455,7 +1505,7 @@ function init(args) {
|
|
|
1455
1505
|
return h.view(
|
|
1456
1506
|
'accounts/account',
|
|
1457
1507
|
{
|
|
1458
|
-
pageTitle: `Accounts
|
|
1508
|
+
pageTitle: `Accounts - ${accountData.email}`,
|
|
1459
1509
|
|
|
1460
1510
|
menuAccounts: true,
|
|
1461
1511
|
account: accountData,
|
|
@@ -1544,13 +1594,22 @@ function init(args) {
|
|
|
1544
1594
|
try {
|
|
1545
1595
|
let accountObject = new Account({ redis, account: request.params.account, documentsQueue, call, secret: await getSecret() });
|
|
1546
1596
|
|
|
1547
|
-
let deleted = await accountObject.delete();
|
|
1597
|
+
let { deleted } = await accountObject.delete();
|
|
1548
1598
|
if (deleted) {
|
|
1549
1599
|
await request.flash({ type: 'info', message: `Account deleted` });
|
|
1600
|
+
} else {
|
|
1601
|
+
await request.flash({ type: 'danger', message: `Requested account was not found` });
|
|
1550
1602
|
}
|
|
1551
1603
|
|
|
1552
1604
|
return h.redirect('/admin/accounts');
|
|
1553
1605
|
} catch (err) {
|
|
1606
|
+
if (isClientError(err) && err.output.statusCode === 404) {
|
|
1607
|
+
// Already gone (a stale tab, a double submit): say so and land on the
|
|
1608
|
+
// listing rather than on the deleted account's page
|
|
1609
|
+
await request.flash({ type: 'danger', message: `Requested account was not found` });
|
|
1610
|
+
return h.redirect('/admin/accounts');
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1554
1613
|
await request.flash({ type: 'danger', message: `Couldn't delete account. Try again.` });
|
|
1555
1614
|
request.logger.error({ msg: 'Failed to delete the account', err, account: request.params.account, remoteAddress: request.app.ip });
|
|
1556
1615
|
return h.redirect(adminUrl`/admin/accounts/${request.params.account}`);
|
|
@@ -1865,7 +1924,7 @@ function init(args) {
|
|
|
1865
1924
|
return h.view(
|
|
1866
1925
|
'accounts/browse',
|
|
1867
1926
|
{
|
|
1868
|
-
pageTitle: `Browse
|
|
1927
|
+
pageTitle: `Browse - ${accountData.email}`,
|
|
1869
1928
|
|
|
1870
1929
|
menuAccounts: true,
|
|
1871
1930
|
account: request.params.account,
|
|
@@ -1945,7 +2004,7 @@ function init(args) {
|
|
|
1945
2004
|
return h.view(
|
|
1946
2005
|
'accounts/edit',
|
|
1947
2006
|
{
|
|
1948
|
-
pageTitle: `Accounts
|
|
2007
|
+
pageTitle: `Accounts - ${accountData.email}`,
|
|
1949
2008
|
|
|
1950
2009
|
menuAccounts: true,
|
|
1951
2010
|
account: request.params.account,
|
|
@@ -2108,7 +2167,7 @@ function init(args) {
|
|
|
2108
2167
|
return h.view(
|
|
2109
2168
|
'accounts/edit',
|
|
2110
2169
|
{
|
|
2111
|
-
pageTitle: `Accounts
|
|
2170
|
+
pageTitle: `Accounts - ${accountData.email}`,
|
|
2112
2171
|
|
|
2113
2172
|
menuAccounts: true,
|
|
2114
2173
|
account: request.params.account,
|
|
@@ -2165,7 +2224,7 @@ function init(args) {
|
|
|
2165
2224
|
.view(
|
|
2166
2225
|
'accounts/edit',
|
|
2167
2226
|
{
|
|
2168
|
-
pageTitle: `Accounts
|
|
2227
|
+
pageTitle: `Accounts - ${accountData.email}`,
|
|
2169
2228
|
|
|
2170
2229
|
menuAccounts: true,
|
|
2171
2230
|
account: request.params.account,
|
|
@@ -10,7 +10,6 @@ const Joi = require('joi');
|
|
|
10
10
|
const crypto = require('crypto');
|
|
11
11
|
const config = require('@zone-eu/wild-config');
|
|
12
12
|
const libmime = require('libmime');
|
|
13
|
-
const he = require('he');
|
|
14
13
|
const os = require('os');
|
|
15
14
|
const packageData = require('../../package.json');
|
|
16
15
|
const { simpleParser } = require('mailparser');
|
|
@@ -21,7 +20,7 @@ const consts = require('../consts');
|
|
|
21
20
|
const getSecret = require('../get-secret');
|
|
22
21
|
const timezonesList = require('timezones-list').default;
|
|
23
22
|
const { redis, submitQueue, notifyQueue, documentsQueue } = require('../db');
|
|
24
|
-
const { getByteSize, formatByteSize, getDuration, failAction, readEnvValue, readEnvList, httpAgent } = require('../tools');
|
|
23
|
+
const { getByteSize, formatByteSize, getDuration, failAction, readEnvValue, readEnvList, httpAgent, splitUrlCredentials } = require('../tools');
|
|
25
24
|
const { validateWebhookTarget } = require('../webhook-egress');
|
|
26
25
|
const { sendWebhookRequest } = require('../webhook-request');
|
|
27
26
|
const { llmPreProcess } = require('../llm-pre-process');
|
|
@@ -369,10 +368,9 @@ function init(args) {
|
|
|
369
368
|
timezone: request.payload.timezone
|
|
370
369
|
};
|
|
371
370
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
371
|
+
// Written when emptied too: the schema accepts a blank field, and skipping the
|
|
372
|
+
// write would leave the old URL in place after a save meant to clear it
|
|
373
|
+
data.serviceUrl = request.payload.serviceUrl ? new URL(request.payload.serviceUrl).origin : null;
|
|
376
374
|
|
|
377
375
|
await settings.setMulti(data);
|
|
378
376
|
}
|
|
@@ -1139,21 +1137,9 @@ return true;`
|
|
|
1139
1137
|
};
|
|
1140
1138
|
}
|
|
1141
1139
|
|
|
1142
|
-
let parsed =
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
if (parsed.username) {
|
|
1146
|
-
username = he.decode(parsed.username);
|
|
1147
|
-
parsed.username = '';
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
if (parsed.password) {
|
|
1151
|
-
password = he.decode(parsed.password);
|
|
1152
|
-
parsed.password = '';
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
if (username || password) {
|
|
1156
|
-
headers.Authorization = `Basic ${Buffer.from(he.encode(username || '') + ':' + he.encode(password || '')).toString('base64')}`;
|
|
1140
|
+
let { url: parsed, authorization } = splitUrlCredentials(webhooks);
|
|
1141
|
+
if (authorization) {
|
|
1142
|
+
headers.Authorization = authorization;
|
|
1157
1143
|
}
|
|
1158
1144
|
|
|
1159
1145
|
let customHeaders = request.payload.customHeaders
|
|
@@ -17,7 +17,7 @@ const { templates } = require('../templates');
|
|
|
17
17
|
const { webhooks } = require('../webhooks');
|
|
18
18
|
const consts = require('../consts');
|
|
19
19
|
const wellKnownServices = require('nodemailer/lib/well-known/services.json');
|
|
20
|
-
const { authAwareLevel, resolveKnownAccounts, adminUrl, mcpToolGrants, accountPickerEntry } = require('./route-helpers');
|
|
20
|
+
const { authAwareLevel, isClientError, resolveKnownAccounts, adminUrl, mcpToolGrants, accountPickerEntry, submittedValues } = require('./route-helpers');
|
|
21
21
|
const exampleWebhookPayloads = require('../payload-examples-webhooks.json');
|
|
22
22
|
|
|
23
23
|
const { DEFAULT_PAGE_SIZE } = consts;
|
|
@@ -316,6 +316,7 @@ return payload;`)
|
|
|
316
316
|
{
|
|
317
317
|
pageTitle: 'Webhook Routes',
|
|
318
318
|
menuWebhooks: true,
|
|
319
|
+
values: request.payload,
|
|
319
320
|
errors: err.details,
|
|
320
321
|
|
|
321
322
|
examplePayloadsJson: JSON.stringify(await getExampleWebhookPayloads()),
|
|
@@ -352,14 +353,16 @@ return payload;`)
|
|
|
352
353
|
|
|
353
354
|
return h
|
|
354
355
|
.view(
|
|
355
|
-
'
|
|
356
|
+
'webhooks/new',
|
|
356
357
|
{
|
|
357
|
-
pageTitle: '
|
|
358
|
-
|
|
358
|
+
pageTitle: 'Webhook Routes',
|
|
359
|
+
menuWebhooks: true,
|
|
360
|
+
values: request.payload,
|
|
359
361
|
errors,
|
|
360
362
|
|
|
361
363
|
examplePayloadsJson: JSON.stringify(await getExampleWebhookPayloads()),
|
|
362
|
-
notificationTypesJson: JSON.stringify(notificationTypes)
|
|
364
|
+
notificationTypesJson: JSON.stringify(notificationTypes),
|
|
365
|
+
scriptEnvJson: JSON.stringify((await settings.get('scriptEnv')) || '{}')
|
|
363
366
|
},
|
|
364
367
|
{
|
|
365
368
|
layout: 'app'
|
|
@@ -637,6 +640,7 @@ return payload;`)
|
|
|
637
640
|
|
|
638
641
|
webhook,
|
|
639
642
|
|
|
643
|
+
values: request.payload,
|
|
640
644
|
errors: err.details,
|
|
641
645
|
|
|
642
646
|
examplePayloadsJson: JSON.stringify(await getExampleWebhookPayloads()),
|
|
@@ -686,6 +690,7 @@ return payload;`)
|
|
|
686
690
|
|
|
687
691
|
webhook,
|
|
688
692
|
|
|
693
|
+
values: request.payload,
|
|
689
694
|
errors,
|
|
690
695
|
|
|
691
696
|
examplePayloadsJson: JSON.stringify(await getExampleWebhookPayloads()),
|
|
@@ -1100,6 +1105,7 @@ return payload;`)
|
|
|
1100
1105
|
|
|
1101
1106
|
formats: CODE_FORMATS.map(format => Object.assign({ selected: format.format === request.payload.format }, format)),
|
|
1102
1107
|
|
|
1108
|
+
values: request.payload,
|
|
1103
1109
|
errors: err.details,
|
|
1104
1110
|
|
|
1105
1111
|
contentHtmlJson: JSON.stringify(request.payload.contentHtml || ''),
|
|
@@ -1165,6 +1171,7 @@ return payload;`)
|
|
|
1165
1171
|
|
|
1166
1172
|
formats: CODE_FORMATS.map(format => Object.assign({ selected: format.format === request.payload.format }, format)),
|
|
1167
1173
|
|
|
1174
|
+
values: request.payload,
|
|
1168
1175
|
errors,
|
|
1169
1176
|
|
|
1170
1177
|
contentHtmlJson: JSON.stringify(request.payload.contentHtml || ''),
|
|
@@ -1319,6 +1326,7 @@ return payload;`)
|
|
|
1319
1326
|
|
|
1320
1327
|
formats: CODE_FORMATS.map(format => Object.assign({ selected: format.format === request.payload.format }, format)),
|
|
1321
1328
|
|
|
1329
|
+
values: request.payload,
|
|
1322
1330
|
errors: err.details,
|
|
1323
1331
|
|
|
1324
1332
|
contentHtmlJson: JSON.stringify(request.payload.contentHtml || ''),
|
|
@@ -1376,6 +1384,7 @@ return payload;`)
|
|
|
1376
1384
|
|
|
1377
1385
|
formats: CODE_FORMATS.map(format => Object.assign({ selected: format.format === request.payload.format }, format)),
|
|
1378
1386
|
|
|
1387
|
+
values: request.payload,
|
|
1379
1388
|
errors,
|
|
1380
1389
|
|
|
1381
1390
|
contentHtmlJson: JSON.stringify(request.payload.contentHtml || ''),
|
|
@@ -1558,10 +1567,6 @@ return payload;`)
|
|
|
1558
1567
|
|
|
1559
1568
|
let gateways = await gatewayObject.listGateways(request.query.page - 1, request.query.pageSize, request.query.query);
|
|
1560
1569
|
|
|
1561
|
-
if (gateways.pages < request.query.page) {
|
|
1562
|
-
request.query.page = gateways.pages;
|
|
1563
|
-
}
|
|
1564
|
-
|
|
1565
1570
|
let nextPage = false;
|
|
1566
1571
|
let prevPage = false;
|
|
1567
1572
|
|
|
@@ -1577,6 +1582,13 @@ return payload;`)
|
|
|
1577
1582
|
return url.pathname + url.search;
|
|
1578
1583
|
};
|
|
1579
1584
|
|
|
1585
|
+
// A page past the end lists nothing, and the view renders its page links only
|
|
1586
|
+
// around a non-empty listing, so it would show "No gateways found" with no way
|
|
1587
|
+
// back - send it to the last page instead
|
|
1588
|
+
if (gateways.pages && request.query.page > gateways.pages) {
|
|
1589
|
+
return h.redirect(getPagingUrl(gateways.pages));
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1580
1592
|
if (gateways.pages > gateways.page + 1) {
|
|
1581
1593
|
nextPage = getPagingUrl(gateways.page + 2);
|
|
1582
1594
|
}
|
|
@@ -1808,7 +1820,10 @@ return payload;`)
|
|
|
1808
1820
|
{
|
|
1809
1821
|
pageTitle: 'Gateways',
|
|
1810
1822
|
menuGateways: true,
|
|
1811
|
-
wellKnownServices: JSON.stringify(Object.keys(wellKnownServices).map(key => Object.assign({ key }, wellKnownServices[key])))
|
|
1823
|
+
wellKnownServices: JSON.stringify(Object.keys(wellKnownServices).map(key => Object.assign({ key }, wellKnownServices[key]))),
|
|
1824
|
+
// the submitted password is not echoed back into the page
|
|
1825
|
+
values: submittedValues(request, 'pass'),
|
|
1826
|
+
errors: err.details
|
|
1812
1827
|
},
|
|
1813
1828
|
{
|
|
1814
1829
|
layout: 'app'
|
|
@@ -1846,6 +1861,7 @@ return payload;`)
|
|
|
1846
1861
|
pageTitle: 'Gateways',
|
|
1847
1862
|
menuGateways: true,
|
|
1848
1863
|
wellKnownServices: JSON.stringify(Object.keys(wellKnownServices).map(key => Object.assign({ key }, wellKnownServices[key]))),
|
|
1864
|
+
values: submittedValues(request, 'pass'),
|
|
1849
1865
|
|
|
1850
1866
|
errors
|
|
1851
1867
|
},
|
|
@@ -1930,7 +1946,9 @@ return payload;`)
|
|
|
1930
1946
|
menuGateways: true,
|
|
1931
1947
|
wellKnownServices: JSON.stringify(Object.keys(wellKnownServices).map(key => Object.assign({ key }, wellKnownServices[key]))),
|
|
1932
1948
|
hasSMTPPass,
|
|
1933
|
-
gatewayData
|
|
1949
|
+
gatewayData,
|
|
1950
|
+
values: submittedValues(request, 'pass'),
|
|
1951
|
+
errors: err.details
|
|
1934
1952
|
},
|
|
1935
1953
|
{
|
|
1936
1954
|
layout: 'app'
|
|
@@ -1975,6 +1993,7 @@ return payload;`)
|
|
|
1975
1993
|
wellKnownServices: JSON.stringify(Object.keys(wellKnownServices).map(key => Object.assign({ key }, wellKnownServices[key]))),
|
|
1976
1994
|
hasSMTPPass,
|
|
1977
1995
|
gatewayData,
|
|
1996
|
+
values: submittedValues(request, 'pass'),
|
|
1978
1997
|
|
|
1979
1998
|
errors
|
|
1980
1999
|
},
|
|
@@ -2138,13 +2157,22 @@ return payload;`)
|
|
|
2138
2157
|
try {
|
|
2139
2158
|
let gatewayObject = new Gateway({ redis, gateway: request.params.gateway, secret: await getSecret() });
|
|
2140
2159
|
|
|
2141
|
-
let deleted = await gatewayObject.delete();
|
|
2160
|
+
let { deleted } = await gatewayObject.delete();
|
|
2142
2161
|
if (deleted) {
|
|
2143
2162
|
await request.flash({ type: 'info', message: `Gateway deleted` });
|
|
2163
|
+
} else {
|
|
2164
|
+
await request.flash({ type: 'danger', message: `Requested gateway was not found` });
|
|
2144
2165
|
}
|
|
2145
2166
|
|
|
2146
2167
|
return h.redirect('/admin/gateways');
|
|
2147
2168
|
} catch (err) {
|
|
2169
|
+
if (isClientError(err) && err.output.statusCode === 404) {
|
|
2170
|
+
// Already gone (a stale tab, a double submit): say so and land on the
|
|
2171
|
+
// listing rather than on the deleted gateway's page
|
|
2172
|
+
await request.flash({ type: 'danger', message: `Requested gateway was not found` });
|
|
2173
|
+
return h.redirect('/admin/gateways');
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2148
2176
|
await request.flash({ type: 'danger', message: `Couldn't delete gateway. Try again.` });
|
|
2149
2177
|
request.logger.error({ msg: 'Failed to delete the gateway', err, gateway: request.params.gateway, remoteAddress: request.app.ip });
|
|
2150
2178
|
return h.redirect(adminUrl`/admin/gateways/gateway/${request.params.gateway}`);
|
|
@@ -2523,6 +2551,8 @@ return payload;`)
|
|
|
2523
2551
|
let deleted = await tokens.delete(request.payload.token, { remoteAddress: request.app.ip });
|
|
2524
2552
|
if (deleted) {
|
|
2525
2553
|
await request.flash({ type: 'info', message: `Token deleted` });
|
|
2554
|
+
} else {
|
|
2555
|
+
await request.flash({ type: 'danger', message: `Requested token was not found` });
|
|
2526
2556
|
}
|
|
2527
2557
|
|
|
2528
2558
|
return h.redirect('/admin/tokens');
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
const Joi = require('joi');
|
|
12
12
|
const crypto = require('crypto');
|
|
13
|
+
const { parentPort } = require('worker_threads');
|
|
13
14
|
const pbkdf2 = require('@phc/pbkdf2');
|
|
14
15
|
const QRCode = require('qrcode');
|
|
15
16
|
const { generateTotpSeed, verifyTotp, generateTotpUrl } = require('../totp');
|
|
@@ -100,6 +101,29 @@ async function verifyAdminPassword(hash, password, logger) {
|
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
|
|
104
|
+
// The current-password check behind the security page's step-down actions (the password change
|
|
105
|
+
// and switching the second factor off). A live session alone is not supposed to reveal the
|
|
106
|
+
// password, and unthrottled the field let a hijacked session guess it at full speed, so the
|
|
107
|
+
// check is rate limited the way the login form is: keyed on the account rather than the address
|
|
108
|
+
// because the caller is already authenticated as it, and with the login form's per-username
|
|
109
|
+
// budget. Owns the limiter and the warn logs; the caller decides how to report the failure.
|
|
110
|
+
//
|
|
111
|
+
// @returns {Promise<{ ok: true } | { ok: false, reason: 'rateLimited' | 'invalid' }>}
|
|
112
|
+
async function verifyCurrentPassword(request, h, authData, password) {
|
|
113
|
+
let rateLimit = await h.checkRateLimit(`password:verify:${authData.user || 'admin'}`, 1, 10, 60);
|
|
114
|
+
if (!rateLimit.success) {
|
|
115
|
+
request.logger.warn({ msg: 'Rate limited', rateLimit, remoteAddress: request.app.ip });
|
|
116
|
+
return { ok: false, reason: 'rateLimited' };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!(await verifyAdminPassword(authData.password, password, request.logger))) {
|
|
120
|
+
request.logger.warn({ msg: 'Invalid current password', remoteAddress: request.app.ip });
|
|
121
|
+
return { ok: false, reason: 'invalid' };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return { ok: true };
|
|
125
|
+
}
|
|
126
|
+
|
|
103
127
|
// View model for the security page's passkey list. Only the fields the list renders are
|
|
104
128
|
// exposed - the stored credential also carries the public key, the signature counter and
|
|
105
129
|
// the owning user, none of which belong in a template context.
|
|
@@ -542,7 +566,9 @@ function init(args) {
|
|
|
542
566
|
{
|
|
543
567
|
pageTitle: 'Login',
|
|
544
568
|
menuLogin: true,
|
|
545
|
-
errors
|
|
569
|
+
errors,
|
|
570
|
+
// the hidden next input, so a retry still lands where the login started
|
|
571
|
+
values: { next: request.payload.next }
|
|
546
572
|
},
|
|
547
573
|
{
|
|
548
574
|
layout: 'login'
|
|
@@ -578,7 +604,8 @@ function init(args) {
|
|
|
578
604
|
{
|
|
579
605
|
pageTitle: 'Login',
|
|
580
606
|
menuLogin: true,
|
|
581
|
-
errors
|
|
607
|
+
errors,
|
|
608
|
+
values: { next: request.payload.next }
|
|
582
609
|
},
|
|
583
610
|
{
|
|
584
611
|
layout: 'login'
|
|
@@ -709,7 +736,10 @@ function init(args) {
|
|
|
709
736
|
|
|
710
737
|
let username = (request.auth && request.auth.credentials && request.auth.credentials.user) || 'admin';
|
|
711
738
|
|
|
712
|
-
|
|
739
|
+
// The RP ID is what the page names as the hostname the passkeys are bound to: it is
|
|
740
|
+
// derived from the Service URL on every ceremony, so a changed host silently strands
|
|
741
|
+
// every registered passkey, and the page is where that gets explained
|
|
742
|
+
let [registeredPasskeys, { rpId, origin: serviceUrl }] = await Promise.all([listPasskeysForView(username), passkeys.getRpConfig()]);
|
|
713
743
|
|
|
714
744
|
// Both reasons registration would fail are known here, so the button is disabled with
|
|
715
745
|
// the reason on it instead of letting the ceremony run into a server error.
|
|
@@ -730,7 +760,8 @@ function init(args) {
|
|
|
730
760
|
|
|
731
761
|
passkeys: registeredPasskeys,
|
|
732
762
|
passkeyBlockReason,
|
|
733
|
-
serviceUrl
|
|
763
|
+
serviceUrl,
|
|
764
|
+
rpId
|
|
734
765
|
},
|
|
735
766
|
{
|
|
736
767
|
layout: 'app'
|
|
@@ -813,6 +844,22 @@ function init(args) {
|
|
|
813
844
|
}
|
|
814
845
|
|
|
815
846
|
try {
|
|
847
|
+
// Switching the second factor off is a step down that a live session alone should
|
|
848
|
+
// not be able to take - the password change and passkey registration both ask for
|
|
849
|
+
// the password again, and so does this, through the same rate-limited check as
|
|
850
|
+
// the password change because it is the same guess-the-password surface.
|
|
851
|
+
let authData = await settings.get('authData');
|
|
852
|
+
if (authData && authData.password) {
|
|
853
|
+
let verified = await verifyCurrentPassword(request, h, authData, request.payload.password);
|
|
854
|
+
if (!verified.ok) {
|
|
855
|
+
await request.flash({
|
|
856
|
+
type: 'danger',
|
|
857
|
+
message: verified.reason === 'rateLimited' ? `Rate limited, please wait and try again` : `Invalid password`
|
|
858
|
+
});
|
|
859
|
+
return h.redirect(`/admin/account/security`);
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
816
863
|
await settings.set('totpEnabled', false);
|
|
817
864
|
await settings.set('totpSeed', false);
|
|
818
865
|
|
|
@@ -836,11 +883,12 @@ function init(args) {
|
|
|
836
883
|
await request.flash({ type: 'danger', message: `Couldn't disable two-factor auth. Try again.` });
|
|
837
884
|
request.logger.error({ msg: 'Failed to disable 2FA', err });
|
|
838
885
|
|
|
839
|
-
return h.redirect('/admin').takeover();
|
|
886
|
+
return h.redirect('/admin/account/security').takeover();
|
|
840
887
|
},
|
|
841
888
|
|
|
842
889
|
payload: Joi.object({
|
|
843
|
-
type: Joi.string().valid('totp').description('The type of the two-factor authentication method').required()
|
|
890
|
+
type: Joi.string().valid('totp').description('The type of the two-factor authentication method').required(),
|
|
891
|
+
password: Joi.string().max(256).required().label('Current password')
|
|
844
892
|
})
|
|
845
893
|
}
|
|
846
894
|
}
|
|
@@ -1333,7 +1381,9 @@ function init(args) {
|
|
|
1333
1381
|
activePassword: true,
|
|
1334
1382
|
disableAuthWarning: true,
|
|
1335
1383
|
|
|
1336
|
-
username
|
|
1384
|
+
username,
|
|
1385
|
+
// the form warns that a password change removes these
|
|
1386
|
+
passkeyCount: await passkeys.countCredentials(username)
|
|
1337
1387
|
},
|
|
1338
1388
|
{
|
|
1339
1389
|
layout: 'app'
|
|
@@ -1354,23 +1404,11 @@ function init(args) {
|
|
|
1354
1404
|
let authData = await settings.get('authData');
|
|
1355
1405
|
let hasExistingPassword = !!(authData && authData.password);
|
|
1356
1406
|
if (hasExistingPassword) {
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
let rateLimit = await h.checkRateLimit(`password:verify:${authData.user || 'admin'}`, 1, 10, 60);
|
|
1363
|
-
if (!rateLimit.success) {
|
|
1364
|
-
request.logger.warn({ msg: 'Rate limited', rateLimit, remoteAddress: request.app.ip });
|
|
1365
|
-
let err = new Error('Rate limited, please wait and try again');
|
|
1366
|
-
err.details = { password0: err.message };
|
|
1367
|
-
throw err;
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
let valid = await verifyAdminPassword(authData.password, request.payload.password0, request.logger);
|
|
1371
|
-
if (!valid) {
|
|
1372
|
-
request.logger.warn({ msg: 'Invalid current password', remoteAddress: request.app.ip });
|
|
1373
|
-
let err = new Error('Failed to verify current password');
|
|
1407
|
+
let verified = await verifyCurrentPassword(request, h, authData, request.payload.password0);
|
|
1408
|
+
if (!verified.ok) {
|
|
1409
|
+
let err = new Error(
|
|
1410
|
+
verified.reason === 'rateLimited' ? 'Rate limited, please wait and try again' : 'Failed to verify current password'
|
|
1411
|
+
);
|
|
1374
1412
|
err.details = { password0: err.message };
|
|
1375
1413
|
throw err;
|
|
1376
1414
|
}
|
|
@@ -1389,9 +1427,14 @@ function init(args) {
|
|
|
1389
1427
|
|
|
1390
1428
|
await settings.set('authData', authData);
|
|
1391
1429
|
|
|
1430
|
+
// Every passkey goes with the old password: registering one takes the password,
|
|
1431
|
+
// so a passkey that outlived a password change could be one registered by whoever
|
|
1432
|
+
// had the old password. The form warns about this while passkeys exist, and the
|
|
1433
|
+
// flash below says how many went.
|
|
1434
|
+
let clearedPasskeys = 0;
|
|
1392
1435
|
try {
|
|
1393
|
-
await passkeys.deleteAllCredentials(authData.user || 'admin');
|
|
1394
|
-
request.logger.info({ msg: 'All passkeys cleared after password change', user: authData.user || 'admin' });
|
|
1436
|
+
clearedPasskeys = await passkeys.deleteAllCredentials(authData.user || 'admin');
|
|
1437
|
+
request.logger.info({ msg: 'All passkeys cleared after password change', user: authData.user || 'admin', cleared: clearedPasskeys });
|
|
1395
1438
|
} catch (passkeyErr) {
|
|
1396
1439
|
request.logger.error({ msg: 'Failed to clear passkeys after password change', err: passkeyErr });
|
|
1397
1440
|
}
|
|
@@ -1402,6 +1445,16 @@ function init(args) {
|
|
|
1402
1445
|
user: authData.user,
|
|
1403
1446
|
passwordVersion: authData.passwordVersion
|
|
1404
1447
|
});
|
|
1448
|
+
|
|
1449
|
+
// Only this API worker's server got the default strategy above. With
|
|
1450
|
+
// EENGINE_WORKERS_API > 1 the other workers decided at boot that the instance
|
|
1451
|
+
// is open (settings.isInstanceSecured() was false then) and would keep serving
|
|
1452
|
+
// /admin without a login until restarted, so the same settings broadcast the
|
|
1453
|
+
// network config page uses tells every API worker to apply it (workers/api.js
|
|
1454
|
+
// handles the authData key). The value is a marker, not the credential.
|
|
1455
|
+
if (parentPort) {
|
|
1456
|
+
parentPort.postMessage({ cmd: 'settings', data: { authData: true } });
|
|
1457
|
+
}
|
|
1405
1458
|
} else {
|
|
1406
1459
|
request.cookieAuth.set('passwordVersion', authData.passwordVersion);
|
|
1407
1460
|
}
|
|
@@ -1416,7 +1469,12 @@ function init(args) {
|
|
|
1416
1469
|
return h.redirect('/admin');
|
|
1417
1470
|
}
|
|
1418
1471
|
|
|
1419
|
-
await request.flash({
|
|
1472
|
+
await request.flash({
|
|
1473
|
+
type: 'info',
|
|
1474
|
+
message: clearedPasskeys
|
|
1475
|
+
? `Password updated and ${clearedPasskeys} registered passkey${clearedPasskeys === 1 ? '' : 's'} removed`
|
|
1476
|
+
: `Password updated`
|
|
1477
|
+
});
|
|
1420
1478
|
|
|
1421
1479
|
return h.redirect('/admin/account/password');
|
|
1422
1480
|
} catch (err) {
|
|
@@ -1434,7 +1492,8 @@ function init(args) {
|
|
|
1434
1492
|
disableAuthWarning: true,
|
|
1435
1493
|
errors: err.details,
|
|
1436
1494
|
|
|
1437
|
-
username
|
|
1495
|
+
username,
|
|
1496
|
+
passkeyCount: await passkeys.countCredentials(username)
|
|
1438
1497
|
},
|
|
1439
1498
|
{
|
|
1440
1499
|
layout: 'app'
|
|
@@ -98,7 +98,7 @@ function init(args) {
|
|
|
98
98
|
color: typeof stats.redisPing !== 'number' ? 'warning' : stats.redisPing < ALLOWED_REDIS_LATENCY ? 'success' : 'danger',
|
|
99
99
|
icon: 'icon-[tabler--clock]',
|
|
100
100
|
comment: 'How many milliseconds does it take to run a Redis command',
|
|
101
|
-
value: typeof stats.redisPing !== 'number' ? '
|
|
101
|
+
value: typeof stats.redisPing !== 'number' ? '-' : nrFormatter.format(stats.redisPing / 1000000)
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
104
|
{
|
|
@@ -240,6 +240,8 @@ function init(args) {
|
|
|
240
240
|
let killed = await call({ cmd: 'kill-thread', thread: request.payload.thread });
|
|
241
241
|
if (killed) {
|
|
242
242
|
await request.flash({ type: 'info', message: `Worker stopped` });
|
|
243
|
+
} else {
|
|
244
|
+
await request.flash({ type: 'danger', message: `Requested worker thread was not found` });
|
|
243
245
|
}
|
|
244
246
|
|
|
245
247
|
return h.redirect('/admin/internals');
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// Nothing reachable before the human clicks ever redirects off this origin. RFC 6749 4.1.2.1
|
|
8
8
|
// only forbids redirecting when the client or the redirect_uri cannot be validated, and an
|
|
9
9
|
// earlier revision of this file followed that literally: a validated-but-malformed request
|
|
10
|
-
// (wrong response_type, a code_challenge_method other than S256, a resource naming another
|
|
10
|
+
// (wrong response_type, a code_challenge_method missing or other than S256, a resource naming another
|
|
11
11
|
// server) bounced straight back to the client's address with ?error=. Client registration is
|
|
12
12
|
// open and unauthenticated, so anyone could register their own https redirect_uri and turn that
|
|
13
13
|
// into a no-interaction redirect off the admin origin - an open redirector aimed by whoever
|
|
@@ -173,7 +173,10 @@ async function init(args) {
|
|
|
173
173
|
return renderError(h, `This client asked for an unsupported response type ("${request.query.response_type}"). Only "code" is supported.`);
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
// An absent method is not S256: RFC 7636 defaults it to "plain", which the token
|
|
177
|
+
// endpoint refuses - so a client that omits it would clear consent and only fail at
|
|
178
|
+
// the exchange, where nobody is looking. Required explicitly, the reason renders here.
|
|
179
|
+
if (request.query.code_challenge_method !== 'S256') {
|
|
177
180
|
return renderError(h, 'This client asked for an unsupported PKCE method. Only "S256" is supported.');
|
|
178
181
|
}
|
|
179
182
|
|