emailengine-app 2.84.1 → 2.85.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/.dockerignore +6 -0
- package/.ncurc.js +5 -3
- package/.prettierignore +5 -1
- package/.prettierrc.js +2 -0
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +61 -0
- package/Dockerfile +8 -2
- package/README.md +1 -1
- package/bin/emailengine.js +444 -403
- package/copy-static-files.sh +39 -14
- package/data/google-crawlers.json +1 -1
- package/data/public_suffix_list.dat +16562 -0
- package/docker-compose.yml +1 -1
- package/eslint.config.js +81 -99
- package/lib/account/own-account-key.js +42 -0
- package/lib/account-assignment.js +1 -33
- package/lib/account.js +68 -24
- package/lib/add-trackers.js +11 -4
- package/lib/api-reference/format.js +4 -3
- package/lib/api-routes/account-routes.js +244 -26
- package/lib/api-routes/blocklist-routes.js +23 -2
- package/lib/api-routes/delivery-test-routes.js +26 -3
- package/lib/api-routes/export-routes.js +28 -2
- package/lib/api-routes/gateway-routes.js +37 -5
- package/lib/api-routes/mailbox-routes.js +41 -2
- package/lib/api-routes/message-routes.js +104 -4
- package/lib/api-routes/mint-bounds.js +11 -0
- package/lib/api-routes/oauth2-app-routes.js +48 -15
- package/lib/api-routes/outbox-routes.js +45 -11
- package/lib/api-routes/permission-map.js +12 -1
- package/lib/api-routes/route-helpers.js +125 -3
- package/lib/api-routes/settings-routes.js +23 -2
- package/lib/api-routes/submit-routes.js +338 -309
- package/lib/api-routes/template-routes.js +38 -2
- package/lib/api-routes/token-routes.js +142 -96
- package/lib/api-routes/webhook-route-routes.js +13 -2
- package/lib/auth-token.js +23 -10
- package/lib/bounce-detect.js +414 -210
- package/lib/consts.js +39 -4
- package/lib/create-imap-client.js +41 -2
- package/lib/email-client/base-client.js +30 -41
- package/lib/email-client/gmail-client.js +30 -18
- package/lib/email-client/imap/mailbox.js +13 -23
- package/lib/email-client/imap/response-metrics.js +75 -0
- package/lib/email-client/imap/subconnection.js +1 -1
- package/lib/email-client/imap-client.js +6 -3
- package/lib/email-client/message-builder.js +7 -2
- package/lib/email-client/notification-handler.js +1 -2
- package/lib/email-client/outlook/graph-api.js +17 -2
- package/lib/email-client/outlook-client.js +6 -3
- package/lib/email-client/smtp-pool-manager.js +6 -0
- package/lib/encrypt.js +9 -0
- package/lib/export.js +3 -1
- package/lib/gateway.js +2 -3
- package/lib/get-raw-email.js +4 -2
- package/lib/hapi-request-logger.js +107 -0
- package/lib/imap-proxy-auth.js +14 -1
- package/lib/imapproxy/imap-core/README.md +6 -5
- package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +1 -0
- package/lib/imapproxy/imap-core/lib/commands/login.js +1 -0
- package/lib/imapproxy/imap-core/lib/imap-command.js +86 -43
- package/lib/imapproxy/imap-core/lib/imap-stream.js +58 -13
- package/lib/imapproxy/imap-core/lib/indexer/indexer.js +3 -1
- package/lib/mcp/listen.js +10 -1
- package/lib/mcp/tools.js +37 -8
- package/lib/notify-attachments.js +17 -0
- package/lib/oauth/external-account-config.js +3 -1
- package/lib/oauth/gmail.js +21 -48
- package/lib/oauth/mail-ru.js +5 -38
- package/lib/oauth/outlook-mailbox.js +35 -0
- package/lib/oauth/outlook.js +26 -44
- package/lib/oauth/state.js +24 -0
- package/lib/oauth2-apps.js +1 -1
- package/lib/pbkdf2-phc.js +19 -2
- package/lib/privileged-settings.js +6 -3
- package/lib/redis-scan-delete.js +15 -1
- package/lib/schemas.js +79 -33
- package/lib/settings.js +13 -1
- package/lib/smtp-auth.js +23 -0
- package/lib/sso.js +1 -1
- package/lib/swagger-options.js +1 -1
- package/lib/thread-diagnostics.js +46 -0
- package/lib/timezones.js +109 -0
- package/lib/token-permission-view.js +3 -3
- package/lib/tools.js +285 -66
- package/lib/totp.js +2 -5
- package/lib/translations.js +1 -2
- package/lib/ui-routes/account-routes.js +491 -491
- package/lib/ui-routes/account-setup.js +99 -0
- package/lib/ui-routes/admin-config-routes.js +98 -48
- package/lib/ui-routes/admin-entities-routes.js +113 -31
- package/lib/ui-routes/auth-routes.js +137 -62
- package/lib/ui-routes/connection-security-form.js +74 -0
- package/lib/ui-routes/form-lists.js +46 -0
- package/lib/ui-routes/internals-routes.js +5 -0
- package/lib/ui-routes/mcp-consent-routes.js +5 -1
- package/lib/ui-routes/oauth-config-routes.js +133 -100
- package/lib/ui-routes/route-helpers.js +19 -3
- package/lib/ui-routes/sign-in-helpers.js +59 -0
- package/lib/ui-routes/tls-config-routes.js +58 -15
- package/lib/ui-routes/unsubscribe-routes.js +6 -3
- package/lib/utils/back-off.js +82 -0
- package/lib/utils/map-concurrent.js +36 -0
- package/lib/utils/murmurhash3.js +66 -0
- package/lib/utils/network.js +28 -0
- package/lib/utils/provider-id.js +27 -0
- package/lib/utils/public-suffix.js +122 -0
- package/lib/utils/random-id.js +26 -0
- package/lib/utils/require-tls.js +33 -0
- package/lib/utils/version.js +74 -0
- package/lib/web-safe-html.js +5 -6
- package/lib/webhook-penalty.js +75 -0
- package/lib/webhook-routing.js +49 -2
- package/lib/webhooks.js +41 -6
- package/package.json +37 -39
- package/sbom.json +7980 -1
- package/server.js +659 -455
- package/static/js/ace/ace.js +1 -1
- package/static/js/ace/mode-handlebars.js +1 -1
- package/static/js/ace/mode-html.js +1 -1
- package/static/js/ace/mode-javascript.js +1 -1
- package/static/js/ace/mode-markdown.js +1 -1
- package/static/js/ace/worker-html.js +1 -1
- package/static/js/ace/worker-javascript.js +1 -1
- package/static/js/ace/worker-json.js +1 -1
- package/static/js/ee-client.js +5 -0
- package/static/licenses.html +191 -1016
- package/translations/messages.pot +70 -71
- package/views/account/security.hbs +10 -0
- package/views/accounts/account.hbs +11 -11
- package/views/accounts/edit.hbs +6 -2
- package/views/config/ai.hbs +1 -1
- package/views/config/security.hbs +2 -2
- package/views/config/service.hbs +3 -0
- package/views/internals/index.hbs +8 -0
- package/views/partials/gateway_form.hbs +3 -1
- package/views/partials/webhook_form.hbs +1 -1
- package/views/suppression-lists/index.hbs +1 -1
- package/workers/api.js +780 -585
- package/workers/export.js +1 -1
- package/workers/submit.js +1 -1
- package/workers/webhooks.js +54 -34
- package/config/test.toml +0 -46
- package/install.sh +0 -428
- package/setup-production.sh +0 -215
- package/systemd/emailengine.service +0 -97
- package/systemd/nginx-proxy.conf +0 -77
|
@@ -34,6 +34,8 @@ const passkeys = require('../passkeys');
|
|
|
34
34
|
const sso = require('../sso');
|
|
35
35
|
const { redis } = require('../db');
|
|
36
36
|
const { windowBudget, reserveAttempts, releaseAttempts, incrementCounter } = require('../rate-limit');
|
|
37
|
+
const { reserveLoginAttempt, upgradePasswordHash } = require('./sign-in-helpers');
|
|
38
|
+
const { budgetAddress } = require('../utils/network');
|
|
37
39
|
|
|
38
40
|
const { LOGIN_PERIOD_TTL, TOTP_WINDOW_SIZE, REDIS_PREFIX } = consts;
|
|
39
41
|
|
|
@@ -136,22 +138,28 @@ async function verifyAdminPassword(hash, password, logger) {
|
|
|
136
138
|
// because the caller is already authenticated as it, and with the login form's per-username
|
|
137
139
|
// budget. Owns the limiter and the warn logs; the caller decides how to report the failure.
|
|
138
140
|
//
|
|
139
|
-
// @returns {Promise<{ ok: true } | { ok: false, reason: 'rateLimited' | 'invalid' }>}
|
|
141
|
+
// @returns {Promise<{ ok: true } | { ok: false, reason: 'rateLimited' | 'invalid', message: String }>}
|
|
140
142
|
async function verifyCurrentPassword(request, h, authData, password) {
|
|
141
143
|
let rateLimit = await h.checkRateLimit(`password:verify:${authData.user || 'admin'}`, 1, 10, 60);
|
|
142
144
|
if (!rateLimit.success) {
|
|
143
145
|
request.logger.warn({ msg: 'Rate limited', rateLimit, remoteAddress: request.app.ip });
|
|
144
|
-
return { ok: false, reason: 'rateLimited' };
|
|
146
|
+
return { ok: false, reason: 'rateLimited', message: 'Rate limited, please wait and try again' };
|
|
145
147
|
}
|
|
146
148
|
|
|
147
149
|
if (!(await verifyAdminPassword(authData.password, password, request.logger))) {
|
|
148
150
|
request.logger.warn({ msg: 'Invalid current password', remoteAddress: request.app.ip });
|
|
149
|
-
return { ok: false, reason: 'invalid' };
|
|
151
|
+
return { ok: false, reason: 'invalid', message: 'Invalid password' };
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
return { ok: true };
|
|
153
155
|
}
|
|
154
156
|
|
|
157
|
+
// Sends a refused step-down action on the security page back to the page with the reason
|
|
158
|
+
async function refuseSecurityAction(request, h, verified) {
|
|
159
|
+
await request.flash({ type: 'danger', message: verified.message });
|
|
160
|
+
return h.redirect(`/admin/account/security`);
|
|
161
|
+
}
|
|
162
|
+
|
|
155
163
|
// Counts a failed second-factor code against the password-stage session that submitted it, keyed
|
|
156
164
|
// on the session's random sid. An exact counter rather than a rate-limit bucket, because the
|
|
157
165
|
// session is ended on a count, not throttled over a window. Returns the failures so far.
|
|
@@ -182,9 +190,32 @@ async function listPasskeysForView(username) {
|
|
|
182
190
|
});
|
|
183
191
|
}
|
|
184
192
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
193
|
+
// --- Passkey (WebAuthn) routes ---
|
|
194
|
+
|
|
195
|
+
const passkeyCredentialSchema = Joi.object({
|
|
196
|
+
id: Joi.string()
|
|
197
|
+
.max(512)
|
|
198
|
+
.pattern(/^[A-Za-z0-9_-]+$/)
|
|
199
|
+
.required(),
|
|
200
|
+
rawId: Joi.string()
|
|
201
|
+
.max(512)
|
|
202
|
+
.pattern(/^[A-Za-z0-9_-]+$/)
|
|
203
|
+
.required(),
|
|
204
|
+
response: Joi.object({
|
|
205
|
+
clientDataJSON: Joi.string().max(16384).required(),
|
|
206
|
+
attestationObject: Joi.string().max(65536),
|
|
207
|
+
authenticatorData: Joi.string().max(8192),
|
|
208
|
+
signature: Joi.string().max(2048),
|
|
209
|
+
userHandle: Joi.string().max(512).allow(''),
|
|
210
|
+
publicKey: Joi.string().max(4096),
|
|
211
|
+
publicKeyAlgorithm: Joi.number().integer()
|
|
212
|
+
}).required(),
|
|
213
|
+
type: Joi.string().valid('public-key').required(),
|
|
214
|
+
authenticatorAttachment: Joi.string().optional(),
|
|
215
|
+
clientExtensionResults: Joi.object().optional()
|
|
216
|
+
}).required();
|
|
217
|
+
|
|
218
|
+
function registerGetLogin(server) {
|
|
188
219
|
server.route({
|
|
189
220
|
method: 'GET',
|
|
190
221
|
path: '/admin/login',
|
|
@@ -282,7 +313,9 @@ function init(args) {
|
|
|
282
313
|
}
|
|
283
314
|
}
|
|
284
315
|
});
|
|
316
|
+
}
|
|
285
317
|
|
|
318
|
+
function registerGetLogout(server) {
|
|
286
319
|
server.route({
|
|
287
320
|
method: 'GET',
|
|
288
321
|
path: '/admin/logout',
|
|
@@ -312,7 +345,9 @@ function init(args) {
|
|
|
312
345
|
return h.redirect('/');
|
|
313
346
|
}
|
|
314
347
|
});
|
|
348
|
+
}
|
|
315
349
|
|
|
350
|
+
function registerPostLogin(server) {
|
|
316
351
|
server.route({
|
|
317
352
|
method: 'POST',
|
|
318
353
|
path: '/admin/login',
|
|
@@ -324,7 +359,7 @@ function init(args) {
|
|
|
324
359
|
return h.redirect('/admin/login');
|
|
325
360
|
}
|
|
326
361
|
try {
|
|
327
|
-
let ipRateLimit = await h.checkRateLimit(`login:ip:${request.app.ip}`, 1, 30, 60);
|
|
362
|
+
let ipRateLimit = await h.checkRateLimit(`login:ip:${budgetAddress(request.app.ip)}`, 1, 30, 60);
|
|
328
363
|
if (!ipRateLimit.success) {
|
|
329
364
|
request.logger.warn({ msg: 'Rate limited', ipRateLimit, remoteAddress: request.app.ip });
|
|
330
365
|
let err = new Error('Rate limited, please wait and try again');
|
|
@@ -332,9 +367,10 @@ function init(args) {
|
|
|
332
367
|
throw err;
|
|
333
368
|
}
|
|
334
369
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
370
|
+
// The per-account budget counts failures only (see lib/ui-routes/sign-in-helpers.js)
|
|
371
|
+
const attempt = await reserveLoginAttempt(request.payload.username);
|
|
372
|
+
if (!attempt.admitted) {
|
|
373
|
+
request.logger.warn({ msg: 'Rate limited', key: attempt.key, remoteAddress: request.app.ip });
|
|
338
374
|
let err = new Error('Rate limited, please wait and try again');
|
|
339
375
|
err.responseText = err.message;
|
|
340
376
|
throw err;
|
|
@@ -362,6 +398,9 @@ function init(args) {
|
|
|
362
398
|
throw err;
|
|
363
399
|
}
|
|
364
400
|
|
|
401
|
+
// a hash written with older parameters is replaced now that the password is known
|
|
402
|
+
await upgradePasswordHash(authData, request.payload.password, request.logger);
|
|
403
|
+
|
|
365
404
|
setAdminSession(request, {
|
|
366
405
|
user: authData.user,
|
|
367
406
|
requireTotp: totpEnabled,
|
|
@@ -374,6 +413,9 @@ function init(args) {
|
|
|
374
413
|
}
|
|
375
414
|
}
|
|
376
415
|
|
|
416
|
+
// accepted, so the attempt reserved above is not a failure
|
|
417
|
+
attempt.release().catch(err => request.logger.warn({ msg: 'Failed to release a login attempt', err }));
|
|
418
|
+
|
|
377
419
|
request.logger.info({ msg: 'Admin login successful', user: authData.user, method: 'password', remoteAddress: request.app.ip });
|
|
378
420
|
|
|
379
421
|
if (totpEnabled) {
|
|
@@ -484,7 +526,9 @@ function init(args) {
|
|
|
484
526
|
}
|
|
485
527
|
}
|
|
486
528
|
});
|
|
529
|
+
}
|
|
487
530
|
|
|
531
|
+
function registerGetTotp(server) {
|
|
488
532
|
server.route({
|
|
489
533
|
method: 'GET',
|
|
490
534
|
path: '/admin/totp',
|
|
@@ -533,7 +577,9 @@ function init(args) {
|
|
|
533
577
|
}
|
|
534
578
|
}
|
|
535
579
|
});
|
|
580
|
+
}
|
|
536
581
|
|
|
582
|
+
function registerPostTotp(server) {
|
|
537
583
|
server.route({
|
|
538
584
|
method: 'POST',
|
|
539
585
|
path: '/admin/totp',
|
|
@@ -736,7 +782,9 @@ function init(args) {
|
|
|
736
782
|
}
|
|
737
783
|
}
|
|
738
784
|
});
|
|
785
|
+
}
|
|
739
786
|
|
|
787
|
+
function registerGetAccountSecurity(server) {
|
|
740
788
|
server.route({
|
|
741
789
|
method: 'GET',
|
|
742
790
|
path: '/admin/account/security',
|
|
@@ -816,11 +864,13 @@ function init(args) {
|
|
|
816
864
|
);
|
|
817
865
|
}
|
|
818
866
|
});
|
|
867
|
+
}
|
|
819
868
|
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
869
|
+
// Passkeys get a page of their own, the way the password does: the security page above is an
|
|
870
|
+
// inventory of ways into the account, and a credential list that grows to MAX_PASSKEYS_PER_USER
|
|
871
|
+
// rows would take it over. Registering needs an account password, so an instance without one
|
|
872
|
+
// has nothing to show here.
|
|
873
|
+
function registerGetAccountPasskeys(server) {
|
|
824
874
|
server.route({
|
|
825
875
|
method: 'GET',
|
|
826
876
|
path: '/admin/account/passkeys',
|
|
@@ -869,7 +919,9 @@ function init(args) {
|
|
|
869
919
|
);
|
|
870
920
|
}
|
|
871
921
|
});
|
|
922
|
+
}
|
|
872
923
|
|
|
924
|
+
function registerPostAccountTfaEnable(server) {
|
|
873
925
|
server.route({
|
|
874
926
|
method: 'POST',
|
|
875
927
|
path: '/admin/account/tfa/enable',
|
|
@@ -885,6 +937,18 @@ function init(args) {
|
|
|
885
937
|
return h.redirect(`/admin/account/security`);
|
|
886
938
|
}
|
|
887
939
|
|
|
940
|
+
// Switching the second factor on bumps the password version, which ends every
|
|
941
|
+
// other session and leaves only this one signed in. A hijacked session could lock
|
|
942
|
+
// the real admin out that way, so like the step down, the password change and a
|
|
943
|
+
// passkey registration, it asks for the password again
|
|
944
|
+
let authData = await settings.get('authData');
|
|
945
|
+
if (authData && authData.password) {
|
|
946
|
+
let verified = await verifyCurrentPassword(request, h, authData, request.payload.password);
|
|
947
|
+
if (!verified.ok) {
|
|
948
|
+
return refuseSecurityAction(request, h, verified);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
|
|
888
952
|
let verified = verifyTotp(totpSeed, request.payload.code, { window: TOTP_WINDOW_SIZE });
|
|
889
953
|
|
|
890
954
|
if (!verified) {
|
|
@@ -894,7 +958,6 @@ function init(args) {
|
|
|
894
958
|
|
|
895
959
|
await settings.set('totpEnabled', true);
|
|
896
960
|
|
|
897
|
-
let authData = await settings.get('authData');
|
|
898
961
|
if (authData) {
|
|
899
962
|
authData.passwordVersion = Date.now();
|
|
900
963
|
await settings.set('authData', authData);
|
|
@@ -929,12 +992,15 @@ function init(args) {
|
|
|
929
992
|
|
|
930
993
|
payload: Joi.object({
|
|
931
994
|
type: Joi.string().valid('totp').description('The type of the two-factor authentication method').required(),
|
|
932
|
-
code: Joi.string().min(6).max(6).description('6-digit TOTP code').required()
|
|
995
|
+
code: Joi.string().min(6).max(6).description('6-digit TOTP code').required(),
|
|
996
|
+
password: Joi.string().max(256).empty('').description('The current account password')
|
|
933
997
|
})
|
|
934
998
|
}
|
|
935
999
|
}
|
|
936
1000
|
});
|
|
1001
|
+
}
|
|
937
1002
|
|
|
1003
|
+
function registerPostAccountTfaDisable(server) {
|
|
938
1004
|
server.route({
|
|
939
1005
|
method: 'POST',
|
|
940
1006
|
path: '/admin/account/tfa/disable',
|
|
@@ -952,11 +1018,7 @@ function init(args) {
|
|
|
952
1018
|
if (authData && authData.password) {
|
|
953
1019
|
let verified = await verifyCurrentPassword(request, h, authData, request.payload.password);
|
|
954
1020
|
if (!verified.ok) {
|
|
955
|
-
|
|
956
|
-
type: 'danger',
|
|
957
|
-
message: verified.reason === 'rateLimited' ? `Rate limited, please wait and try again` : `Invalid password`
|
|
958
|
-
});
|
|
959
|
-
return h.redirect(`/admin/account/security`);
|
|
1021
|
+
return refuseSecurityAction(request, h, verified);
|
|
960
1022
|
}
|
|
961
1023
|
}
|
|
962
1024
|
|
|
@@ -993,7 +1055,9 @@ function init(args) {
|
|
|
993
1055
|
}
|
|
994
1056
|
}
|
|
995
1057
|
});
|
|
1058
|
+
}
|
|
996
1059
|
|
|
1060
|
+
function registerPostAccountLogoutAll(server) {
|
|
997
1061
|
server.route({
|
|
998
1062
|
method: 'POST',
|
|
999
1063
|
path: '/admin/account/logout-all',
|
|
@@ -1036,39 +1100,16 @@ function init(args) {
|
|
|
1036
1100
|
}
|
|
1037
1101
|
}
|
|
1038
1102
|
});
|
|
1103
|
+
}
|
|
1039
1104
|
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
const passkeyCredentialSchema = Joi.object({
|
|
1043
|
-
id: Joi.string()
|
|
1044
|
-
.max(512)
|
|
1045
|
-
.pattern(/^[A-Za-z0-9_-]+$/)
|
|
1046
|
-
.required(),
|
|
1047
|
-
rawId: Joi.string()
|
|
1048
|
-
.max(512)
|
|
1049
|
-
.pattern(/^[A-Za-z0-9_-]+$/)
|
|
1050
|
-
.required(),
|
|
1051
|
-
response: Joi.object({
|
|
1052
|
-
clientDataJSON: Joi.string().max(16384).required(),
|
|
1053
|
-
attestationObject: Joi.string().max(65536),
|
|
1054
|
-
authenticatorData: Joi.string().max(8192),
|
|
1055
|
-
signature: Joi.string().max(2048),
|
|
1056
|
-
userHandle: Joi.string().max(512).allow(''),
|
|
1057
|
-
publicKey: Joi.string().max(4096),
|
|
1058
|
-
publicKeyAlgorithm: Joi.number().integer()
|
|
1059
|
-
}).required(),
|
|
1060
|
-
type: Joi.string().valid('public-key').required(),
|
|
1061
|
-
authenticatorAttachment: Joi.string().optional(),
|
|
1062
|
-
clientExtensionResults: Joi.object().optional()
|
|
1063
|
-
}).required();
|
|
1064
|
-
|
|
1065
|
-
// Registration: generate options (authenticated)
|
|
1105
|
+
// Registration: generate options (authenticated)
|
|
1106
|
+
function registerPostAccountPasskeysRegisterOptions(server) {
|
|
1066
1107
|
server.route({
|
|
1067
1108
|
method: 'POST',
|
|
1068
1109
|
path: '/admin/account/passkeys/register/options',
|
|
1069
1110
|
async handler(request, h) {
|
|
1070
1111
|
try {
|
|
1071
|
-
let rateLimit = await h.checkRateLimit(`passkey:register:${request.app.ip}`, 1, 10, 60);
|
|
1112
|
+
let rateLimit = await h.checkRateLimit(`passkey:register:${budgetAddress(request.app.ip)}`, 1, 10, 60);
|
|
1072
1113
|
if (!rateLimit.success) {
|
|
1073
1114
|
return h.response({ error: 'Rate limited, please wait and try again' }).code(429);
|
|
1074
1115
|
}
|
|
@@ -1134,14 +1175,16 @@ function init(args) {
|
|
|
1134
1175
|
}
|
|
1135
1176
|
}
|
|
1136
1177
|
});
|
|
1178
|
+
}
|
|
1137
1179
|
|
|
1138
|
-
|
|
1180
|
+
// Registration: verify response (authenticated)
|
|
1181
|
+
function registerPostAccountPasskeysRegisterVerify(server) {
|
|
1139
1182
|
server.route({
|
|
1140
1183
|
method: 'POST',
|
|
1141
1184
|
path: '/admin/account/passkeys/register/verify',
|
|
1142
1185
|
async handler(request, h) {
|
|
1143
1186
|
try {
|
|
1144
|
-
let rateLimit = await h.checkRateLimit(`passkey:register:${request.app.ip}`, 1, 10, 60);
|
|
1187
|
+
let rateLimit = await h.checkRateLimit(`passkey:register:${budgetAddress(request.app.ip)}`, 1, 10, 60);
|
|
1145
1188
|
if (!rateLimit.success) {
|
|
1146
1189
|
return h.response({ error: 'Rate limited, please wait and try again' }).code(429);
|
|
1147
1190
|
}
|
|
@@ -1162,9 +1205,11 @@ function init(args) {
|
|
|
1162
1205
|
// over the challenge namespacing - a future third way to obtain a registration
|
|
1163
1206
|
// challenge would otherwise reopen the bypass. Checked before the challenge is
|
|
1164
1207
|
// consumed, so a mistyped password does not burn the nonce and force the whole
|
|
1165
|
-
// ceremony to be repeated.
|
|
1166
|
-
|
|
1167
|
-
|
|
1208
|
+
// ceremony to be repeated. Through the same per-account budget as the password
|
|
1209
|
+
// change, so a hijacked session gets no second password-guessing surface here
|
|
1210
|
+
let verified = await verifyCurrentPassword(request, h, authData, request.payload.password);
|
|
1211
|
+
if (!verified.ok) {
|
|
1212
|
+
return h.response({ error: verified.message }).code(verified.reason === 'rateLimited' ? 429 : 403);
|
|
1168
1213
|
}
|
|
1169
1214
|
|
|
1170
1215
|
let challenge = await passkeys.consumeChallenge(request.payload.challengeId, passkeys.CHALLENGE_REGISTER);
|
|
@@ -1233,8 +1278,10 @@ function init(args) {
|
|
|
1233
1278
|
}
|
|
1234
1279
|
}
|
|
1235
1280
|
});
|
|
1281
|
+
}
|
|
1236
1282
|
|
|
1237
|
-
|
|
1283
|
+
// Delete passkey (authenticated)
|
|
1284
|
+
function registerPostAccountPasskeysDelete(server) {
|
|
1238
1285
|
server.route({
|
|
1239
1286
|
method: 'POST',
|
|
1240
1287
|
path: '/admin/account/passkeys/delete',
|
|
@@ -1288,8 +1335,10 @@ function init(args) {
|
|
|
1288
1335
|
}
|
|
1289
1336
|
}
|
|
1290
1337
|
});
|
|
1338
|
+
}
|
|
1291
1339
|
|
|
1292
|
-
|
|
1340
|
+
// Authentication: generate options (unauthenticated)
|
|
1341
|
+
function registerPostPasskeyAuthOptions(server) {
|
|
1293
1342
|
server.route({
|
|
1294
1343
|
method: 'POST',
|
|
1295
1344
|
path: '/admin/passkey/auth/options',
|
|
@@ -1299,7 +1348,7 @@ function init(args) {
|
|
|
1299
1348
|
return h.response({ error: 'sso_required' }).code(403);
|
|
1300
1349
|
}
|
|
1301
1350
|
try {
|
|
1302
|
-
let rateLimit = await h.checkRateLimit(`passkey:auth:options:${request.app.ip}`, 1, 10, 60);
|
|
1351
|
+
let rateLimit = await h.checkRateLimit(`passkey:auth:options:${budgetAddress(request.app.ip)}`, 1, 10, 60);
|
|
1303
1352
|
if (!rateLimit.success) {
|
|
1304
1353
|
return h.response({ error: 'Rate limited, please wait and try again' }).code(429);
|
|
1305
1354
|
}
|
|
@@ -1351,8 +1400,10 @@ function init(args) {
|
|
|
1351
1400
|
}
|
|
1352
1401
|
}
|
|
1353
1402
|
});
|
|
1403
|
+
}
|
|
1354
1404
|
|
|
1355
|
-
|
|
1405
|
+
// Authentication: verify response (unauthenticated)
|
|
1406
|
+
function registerPostPasskeyAuthVerify(server) {
|
|
1356
1407
|
server.route({
|
|
1357
1408
|
method: 'POST',
|
|
1358
1409
|
path: '/admin/passkey/auth/verify',
|
|
@@ -1362,7 +1413,7 @@ function init(args) {
|
|
|
1362
1413
|
return h.response({ error: 'sso_required' }).code(403);
|
|
1363
1414
|
}
|
|
1364
1415
|
try {
|
|
1365
|
-
let rateLimit = await h.checkRateLimit(`passkey:auth:verify:${request.app.ip}`, 1, 10, 60);
|
|
1416
|
+
let rateLimit = await h.checkRateLimit(`passkey:auth:verify:${budgetAddress(request.app.ip)}`, 1, 10, 60);
|
|
1366
1417
|
if (!rateLimit.success) {
|
|
1367
1418
|
return h.response({ error: 'Rate limited, please wait and try again' }).code(429);
|
|
1368
1419
|
}
|
|
@@ -1462,9 +1513,11 @@ function init(args) {
|
|
|
1462
1513
|
}
|
|
1463
1514
|
}
|
|
1464
1515
|
});
|
|
1516
|
+
}
|
|
1465
1517
|
|
|
1466
|
-
|
|
1518
|
+
// --- End of Passkey routes ---
|
|
1467
1519
|
|
|
1520
|
+
function registerGetAccountPassword(server) {
|
|
1468
1521
|
server.route({
|
|
1469
1522
|
method: 'GET',
|
|
1470
1523
|
path: '/admin/account/password',
|
|
@@ -1493,7 +1546,9 @@ function init(args) {
|
|
|
1493
1546
|
);
|
|
1494
1547
|
}
|
|
1495
1548
|
});
|
|
1549
|
+
}
|
|
1496
1550
|
|
|
1551
|
+
function registerPostAccountPassword(server) {
|
|
1497
1552
|
server.route({
|
|
1498
1553
|
method: 'POST',
|
|
1499
1554
|
path: '/admin/account/password',
|
|
@@ -1508,9 +1563,7 @@ function init(args) {
|
|
|
1508
1563
|
if (hasExistingPassword) {
|
|
1509
1564
|
let verified = await verifyCurrentPassword(request, h, authData, request.payload.password0);
|
|
1510
1565
|
if (!verified.ok) {
|
|
1511
|
-
let err = new Error(
|
|
1512
|
-
verified.reason === 'rateLimited' ? 'Rate limited, please wait and try again' : 'Failed to verify current password'
|
|
1513
|
-
);
|
|
1566
|
+
let err = new Error(verified.message);
|
|
1514
1567
|
err.details = { password0: err.message };
|
|
1515
1568
|
throw err;
|
|
1516
1569
|
}
|
|
@@ -1658,4 +1711,26 @@ function init(args) {
|
|
|
1658
1711
|
});
|
|
1659
1712
|
}
|
|
1660
1713
|
|
|
1714
|
+
function init(args) {
|
|
1715
|
+
const { server } = args;
|
|
1716
|
+
|
|
1717
|
+
registerGetLogin(server);
|
|
1718
|
+
registerGetLogout(server);
|
|
1719
|
+
registerPostLogin(server);
|
|
1720
|
+
registerGetTotp(server);
|
|
1721
|
+
registerPostTotp(server);
|
|
1722
|
+
registerGetAccountSecurity(server);
|
|
1723
|
+
registerGetAccountPasskeys(server);
|
|
1724
|
+
registerPostAccountTfaEnable(server);
|
|
1725
|
+
registerPostAccountTfaDisable(server);
|
|
1726
|
+
registerPostAccountLogoutAll(server);
|
|
1727
|
+
registerPostAccountPasskeysRegisterOptions(server);
|
|
1728
|
+
registerPostAccountPasskeysRegisterVerify(server);
|
|
1729
|
+
registerPostAccountPasskeysDelete(server);
|
|
1730
|
+
registerPostPasskeyAuthOptions(server);
|
|
1731
|
+
registerPostPasskeyAuthVerify(server);
|
|
1732
|
+
registerGetAccountPassword(server);
|
|
1733
|
+
registerPostAccountPassword(server);
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1661
1736
|
module.exports = init;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The two connection-security checkboxes of the admin account form, for the IMAP and the SMTP
|
|
4
|
+
// section alike: "Allow invalid certificates" (`tls.rejectUnauthorized`) and "Require STARTTLS"
|
|
5
|
+
// (`requireTLS`, see lib/create-imap-client.js and lib/utils/require-tls.js). The schema,
|
|
6
|
+
// rendering and saving are each written once here, because the two sections used to carry their
|
|
7
|
+
// own copies of the same four comparisons. The gateway forms share the STARTTLS field.
|
|
8
|
+
//
|
|
9
|
+
// A value is written only when the effective state changes: an untouched form save must not add
|
|
10
|
+
// keys to the stored connection object, since any imap diff forces a reconnect.
|
|
11
|
+
|
|
12
|
+
const { formBoolean } = require('../schemas');
|
|
13
|
+
|
|
14
|
+
// required unless the stored object says otherwise
|
|
15
|
+
const storedRequireTls = stored => !(stored && stored.requireTLS === false);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The "Require STARTTLS" checkbox of a form, unticked when the field is absent.
|
|
19
|
+
*
|
|
20
|
+
* @returns {Object} joi schema
|
|
21
|
+
*/
|
|
22
|
+
function requireTlsFormField() {
|
|
23
|
+
return formBoolean().default(false).example(true).description('Require STARTTLS when direct TLS is off').label('RequireTLS');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The form fields of the two checkboxes for one section.
|
|
28
|
+
*
|
|
29
|
+
* @param {String} prefix - 'imap' or 'smtp', the form field prefix
|
|
30
|
+
* @returns {Object} joi schemas, to spread into the form's payload schema
|
|
31
|
+
*/
|
|
32
|
+
function securityFormFields(prefix) {
|
|
33
|
+
return {
|
|
34
|
+
[`${prefix}_requireTLS`]: requireTlsFormField(),
|
|
35
|
+
[`${prefix}_tls_ignoreCertErrors`]: formBoolean()
|
|
36
|
+
.default(false)
|
|
37
|
+
.example(false)
|
|
38
|
+
.description('Allow connections to servers with invalid TLS certificates for this account')
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The form values of the two checkboxes for one section.
|
|
44
|
+
*
|
|
45
|
+
* @param {String} prefix - 'imap' or 'smtp', the form field prefix
|
|
46
|
+
* @param {Object} [stored] - the stored connection object
|
|
47
|
+
* @returns {Object} `<prefix>_tls_ignoreCertErrors` and `<prefix>_requireTLS`
|
|
48
|
+
*/
|
|
49
|
+
function securityFormValues(prefix, stored) {
|
|
50
|
+
return {
|
|
51
|
+
[`${prefix}_tls_ignoreCertErrors`]: !!(stored && stored.tls && stored.tls.rejectUnauthorized === false),
|
|
52
|
+
[`${prefix}_requireTLS`]: storedRequireTls(stored)
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Applies the two checkboxes of a submitted form to the update of one section.
|
|
58
|
+
*
|
|
59
|
+
* @param {Object} payload - the validated form payload
|
|
60
|
+
* @param {String} prefix - 'imap' or 'smtp'
|
|
61
|
+
* @param {Object} [stored] - the stored connection object
|
|
62
|
+
* @param {Object} target - the object the section's update keys are collected on
|
|
63
|
+
* @param {Object} tls - the tls object being built for the update (the stored one, or empty)
|
|
64
|
+
*/
|
|
65
|
+
function applySecurityForm(payload, prefix, stored, target, tls) {
|
|
66
|
+
if (payload[`${prefix}_tls_ignoreCertErrors`] !== (tls.rejectUnauthorized === false)) {
|
|
67
|
+
tls.rejectUnauthorized = !payload[`${prefix}_tls_ignoreCertErrors`];
|
|
68
|
+
}
|
|
69
|
+
if (payload[`${prefix}_requireTLS`] !== storedRequireTls(stored)) {
|
|
70
|
+
target.requireTLS = payload[`${prefix}_requireTLS`];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = { requireTlsFormField, securityFormFields, securityFormValues, applySecurityForm };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Parsers for the admin form textareas that hold one entry per line. Dependency-free, so any
|
|
4
|
+
// lib/ui-routes module can use them without pulling in route-helpers.js. A missing field parses
|
|
5
|
+
// as an empty list, so a handler updating a stored value checks the field was sent first.
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Parses the "Custom headers" textarea of the webhook forms, one `Name: value` per line, into
|
|
9
|
+
* the `{ key, value }` list the webhooksCustomHeaders setting stores. A line without a colon is
|
|
10
|
+
* a header with an empty value. A missing field parses as no headers.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} [text] - the submitted textarea value
|
|
13
|
+
* @returns {Array<{key: string, value: string}>}
|
|
14
|
+
*/
|
|
15
|
+
function parseCustomHeaders(text) {
|
|
16
|
+
return (text || '')
|
|
17
|
+
.split(/[\r\n]+/)
|
|
18
|
+
.map(header => header.trim())
|
|
19
|
+
.filter(header => header)
|
|
20
|
+
.map(line => {
|
|
21
|
+
let sep = line.indexOf(':');
|
|
22
|
+
if (sep >= 0) {
|
|
23
|
+
return {
|
|
24
|
+
key: line.substring(0, sep).trim(),
|
|
25
|
+
value: line.substring(sep + 1).trim()
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
key: line,
|
|
30
|
+
value: ''
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Splits the whitespace separated scope list of the OAuth2 app form. A missing field parses as
|
|
37
|
+
* an empty list.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} [text] - the submitted textarea value
|
|
40
|
+
* @returns {string[]}
|
|
41
|
+
*/
|
|
42
|
+
function parseScopeList(text) {
|
|
43
|
+
return (text || '').split(/\s+/).filter(scope => scope);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = { parseCustomHeaders, parseScopeList };
|
|
@@ -145,6 +145,11 @@ function init(args) {
|
|
|
145
145
|
threadInfo.heapUsed = bytesFormatter.format(threadInfo.heapUsed).replace(/BB$/, 'GB');
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
// Longest delay over the collector's last window; a thread's first reading has none yet
|
|
149
|
+
if (!threadInfo.isUnresponsive && typeof threadInfo.eventLoopDelay?.max === 'number') {
|
|
150
|
+
threadInfo.eventLoopDelayMax = Math.round(threadInfo.eventLoopDelay.max);
|
|
151
|
+
}
|
|
152
|
+
|
|
148
153
|
// Email (sync) workers own account assignment, but the count field is absent
|
|
149
154
|
// when a worker currently syncs none - show an explicit 0 instead of a blank.
|
|
150
155
|
if (threadInfo.type === 'imap' && typeof threadInfo.accounts !== 'number') {
|
|
@@ -190,7 +190,8 @@ async function init(args) {
|
|
|
190
190
|
return renderError(h, 'This authorization request names a different server as its resource, so it was not meant for this instance.');
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
// The registration is not refreshed on a render (anyone can open the link, and that
|
|
194
|
+
// let a registration nobody approved outlive the pending-client cap), only on approval
|
|
194
195
|
|
|
195
196
|
// The `scope` parameter is a hint for the starting position of the form, never a
|
|
196
197
|
// grant: a client asking for `mcp` is asking for mail access, so the mail section
|
|
@@ -322,6 +323,9 @@ async function init(args) {
|
|
|
322
323
|
});
|
|
323
324
|
}
|
|
324
325
|
|
|
326
|
+
// Approved by an authenticated admin: the registration earns its full lifetime now
|
|
327
|
+
await touchClient(client.client_id);
|
|
328
|
+
|
|
325
329
|
const code = await createAuthorizationCode({
|
|
326
330
|
clientId: client.client_id,
|
|
327
331
|
redirectUri: request.payload.redirect_uri,
|