emailengine-app 2.79.6 → 2.79.7
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 +15 -0
- package/data/google-crawlers.json +1 -1
- package/lib/consts.js +4 -2
- package/lib/passkeys.js +39 -7
- package/lib/sso.js +47 -4
- package/lib/tools.js +19 -0
- package/lib/ui-routes/account-routes.js +9 -1
- package/lib/ui-routes/auth-routes.js +158 -62
- package/lib/ui-routes/network-config-routes.js +10 -1
- package/package.json +17 -17
- package/sbom.json +1 -1
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +55 -0
- package/static/js/app.js +4 -35
- package/static/js/passkey-register.js +50 -1
- package/static/js/public.js +128 -0
- package/static/js/ui.js +183 -6
- package/static/licenses.html +371 -770
- package/translations/messages.pot +18 -18
- package/views/account/passkeys.hbs +133 -0
- package/views/account/security.hbs +300 -319
- package/views/accounts/account.hbs +84 -114
- package/views/accounts/register/imap-server.hbs +8 -10
- package/views/config/document-store/index.hbs +6 -6
- package/views/config/license.hbs +4 -1
- package/views/config/oauth/app.hbs +1 -1
- package/views/config/oauth/edit.hbs +1 -1
- package/views/config/oauth/new.hbs +1 -1
- package/views/config/webhooks.hbs +7 -6
- package/views/partials/gateway_js.hbs +7 -6
- package/views/partials/ui/btn.hbs +8 -2
- package/views/partials/ui/confirm-modal.hbs +2 -3
- package/views/partials/ui/empty-state.hbs +25 -0
- package/views/partials/webhooks_editor_functions.hbs +5 -5
- package/workers/api.js +56 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.79.7](https://github.com/postalsys/emailengine/compare/v2.79.6...v2.79.7) (2026-08-31)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* bind WebAuthn challenges to the ceremony that minted them ([6b2073b](https://github.com/postalsys/emailengine/commit/6b2073b5c8e50ab75a02d2c6a0f54a43d2c295e6))
|
|
9
|
+
* **deps:** collapse encoding-japanese to a single copy for the CP932 areas ([8ae2109](https://github.com/postalsys/emailengine/commit/8ae21099dd86a3dd9467dc0ca4ead9880e147e27))
|
|
10
|
+
* **deps:** update dependencies and collapse nodemailer to a single copy ([cf814e9](https://github.com/postalsys/emailengine/commit/cf814e9e4c91c4430fce01687ead6bdb38bc3879))
|
|
11
|
+
* retry OIDC discovery instead of disabling SSO for the process lifetime ([dbbbf43](https://github.com/postalsys/emailengine/commit/dbbbf432ed6593b7fd5457e8fc6d2f8d03316ea6))
|
|
12
|
+
* **tls:** renew certificates before they expire, not a month after ([fa150e8](https://github.com/postalsys/emailengine/commit/fa150e87bbe7aa317847f3d676053ecc99dc69f1))
|
|
13
|
+
* **ui:** disable the stored-log download when an account has no logs ([5137b71](https://github.com/postalsys/emailengine/commit/5137b71bbaf9a935b91437a53b7b369237a445a2))
|
|
14
|
+
* **ui:** move the passkey list onto a page of its own ([7cb42c4](https://github.com/postalsys/emailengine/commit/7cb42c4dc1a8ece1468f8754f37cd9f763c97130))
|
|
15
|
+
* **ui:** show a busy state on the buttons that start slow work ([6c63479](https://github.com/postalsys/emailengine/commit/6c6347946bed0c06f836826de0425b328740bf81))
|
|
16
|
+
* **ui:** stop offering to clear stored logs an account does not have ([e02f09a](https://github.com/postalsys/emailengine/commit/e02f09a596b5d0a1f40e37297d86aea7a046b813))
|
|
17
|
+
|
|
3
18
|
## [2.79.6](https://github.com/postalsys/emailengine/compare/v2.79.5...v2.79.6) (2026-08-27)
|
|
4
19
|
|
|
5
20
|
|
package/lib/consts.js
CHANGED
|
@@ -160,8 +160,10 @@ module.exports = {
|
|
|
160
160
|
|
|
161
161
|
REDIS_BATCH_DELETE_SIZE: 1000,
|
|
162
162
|
|
|
163
|
-
//
|
|
164
|
-
|
|
163
|
+
// When renewal becomes due is derived from each certificate's own lifetime by
|
|
164
|
+
// isRenewalDue() in @postalsys/certs, so there is no constant for it here. Let's Encrypt is
|
|
165
|
+
// shortening certificates from 90 days to 64 and then 45, and a fixed threshold is correct
|
|
166
|
+
// for exactly one lifetime. https://letsencrypt.org/2025/12/02/from-90-to-45
|
|
165
167
|
|
|
166
168
|
// do not attempt certificate renewal more often than once in 8 hours
|
|
167
169
|
BLOCK_TLS_RENEW: 8 * 3600 * 1000,
|
package/lib/passkeys.js
CHANGED
|
@@ -7,6 +7,29 @@ const { REDIS_PREFIX, WEBAUTHN_CHALLENGE_TTL } = require('./consts');
|
|
|
7
7
|
|
|
8
8
|
const KEY_PREFIX = `${REDIS_PREFIX}webauthn:`;
|
|
9
9
|
|
|
10
|
+
// A WebAuthn challenge is a bare nonce, and nothing in the signed response the authenticator
|
|
11
|
+
// returns says which ceremony the server minted it for - that binding is the server's job.
|
|
12
|
+
// Registration is gated behind a password confirmation and sign-in deliberately is not, so while
|
|
13
|
+
// both ceremonies drew from one keyspace a nonce minted by the unauthenticated sign-in endpoint
|
|
14
|
+
// could be spent completing a registration, skipping the gate entirely. The purpose is part of the
|
|
15
|
+
// key, so each ceremony can only consume what it minted.
|
|
16
|
+
const CHALLENGE_REGISTER = 'register';
|
|
17
|
+
const CHALLENGE_AUTH = 'auth';
|
|
18
|
+
const CHALLENGE_PURPOSES = new Set([CHALLENGE_REGISTER, CHALLENGE_AUTH]);
|
|
19
|
+
|
|
20
|
+
function assertPurpose(purpose) {
|
|
21
|
+
if (!CHALLENGE_PURPOSES.has(purpose)) {
|
|
22
|
+
// Every caller passes one of the exported constants, so this is a programming error and
|
|
23
|
+
// must not degrade into an unnamespaced key that would restore the bypass
|
|
24
|
+
throw new Error(`Unknown WebAuthn challenge purpose: ${purpose}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function challengeKey(challengeId, purpose) {
|
|
29
|
+
assertPurpose(purpose);
|
|
30
|
+
return `${KEY_PREFIX}challenge:${purpose}:${challengeId}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
10
33
|
// Passkey data does not require encryption at rest. Unlike TOTP seeds or OAuth
|
|
11
34
|
// client secrets (which are shared secrets), passkeys use public-key cryptography.
|
|
12
35
|
// Only the public key is stored here -- the private key never leaves the
|
|
@@ -90,6 +113,9 @@ function credentialKeys(id, user) {
|
|
|
90
113
|
}
|
|
91
114
|
|
|
92
115
|
module.exports = {
|
|
116
|
+
CHALLENGE_REGISTER,
|
|
117
|
+
CHALLENGE_AUTH,
|
|
118
|
+
|
|
93
119
|
async getRpConfig() {
|
|
94
120
|
let serviceUrl = await settings.get('serviceUrl');
|
|
95
121
|
if (!serviceUrl) {
|
|
@@ -99,18 +125,20 @@ module.exports = {
|
|
|
99
125
|
return { rpId: url.hostname, origin: url.origin };
|
|
100
126
|
},
|
|
101
127
|
|
|
102
|
-
async storeChallenge(challenge) {
|
|
128
|
+
async storeChallenge(challenge, purpose) {
|
|
103
129
|
let challengeId = crypto.randomBytes(32).toString('hex');
|
|
104
|
-
await redis.set(
|
|
130
|
+
await redis.set(challengeKey(challengeId, purpose), challenge, 'EX', WEBAUTHN_CHALLENGE_TTL);
|
|
105
131
|
return challengeId;
|
|
106
132
|
},
|
|
107
133
|
|
|
108
|
-
async consumeChallenge(challengeId) {
|
|
134
|
+
async consumeChallenge(challengeId, purpose) {
|
|
135
|
+
// Before the id check, so a caller that forgot the purpose trips the guardrail whatever
|
|
136
|
+
// it passed as an id rather than getting a plausible null back
|
|
137
|
+
assertPurpose(purpose);
|
|
109
138
|
if (!challengeId || typeof challengeId !== 'string') {
|
|
110
139
|
return null;
|
|
111
140
|
}
|
|
112
|
-
let
|
|
113
|
-
let challenge = await redis.getdel(key);
|
|
141
|
+
let challenge = await redis.getdel(challengeKey(challengeId, purpose));
|
|
114
142
|
return challenge || null;
|
|
115
143
|
},
|
|
116
144
|
|
|
@@ -142,8 +170,12 @@ module.exports = {
|
|
|
142
170
|
return hydrateCredential(data);
|
|
143
171
|
},
|
|
144
172
|
|
|
145
|
-
|
|
146
|
-
|
|
173
|
+
// Called after a verified assertion, so it stamps the sign-in time alongside the
|
|
174
|
+
// signature counter. The stamp is what the security page shows as "Last used";
|
|
175
|
+
// credentials registered before it existed carry no field and render as unknown
|
|
176
|
+
// rather than as never used.
|
|
177
|
+
async recordAuthentication(credentialId, newCounter) {
|
|
178
|
+
await redis.hset(`${KEY_PREFIX}cred:${credentialId}`, 'counter', String(newCounter), 'lastUsedAt', new Date().toISOString());
|
|
147
179
|
},
|
|
148
180
|
|
|
149
181
|
async listCredentials(user) {
|
package/lib/sso.js
CHANGED
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
// dotted path (e.g. "realm_access.roles") for IdPs that nest it.
|
|
36
36
|
|
|
37
37
|
const { fetch: fetchCmd } = require('undici');
|
|
38
|
+
const { backOff } = require('exponential-backoff');
|
|
38
39
|
const { readEnvValue, httpAgent, getBoolean } = require('./tools');
|
|
39
40
|
const packageData = require('../package.json');
|
|
40
41
|
|
|
@@ -67,6 +68,13 @@ const USE_OIDC_AUTH = !!(OIDC_ISSUER && OIDC_CLIENT_ID && OIDC_CLIENT_SECRET);
|
|
|
67
68
|
|
|
68
69
|
const DISCOVERY_TIMEOUT = 10 * 1000;
|
|
69
70
|
|
|
71
|
+
// Backoff bounds for retryDiscovery(). Quick at first, because the common failure is
|
|
72
|
+
// an IdP that is merely slower to boot than we are (a shared host restarting both at
|
|
73
|
+
// once, where the IdP can be a minute behind), then doubling to one probe every five
|
|
74
|
+
// minutes so a genuine multi-hour outage costs almost nothing.
|
|
75
|
+
const DISCOVERY_RETRY_MIN = 5 * 1000;
|
|
76
|
+
const DISCOVERY_RETRY_MAX = 5 * 60 * 1000;
|
|
77
|
+
|
|
70
78
|
// `openid` is what makes the request an OIDC request; `profile` and `email`
|
|
71
79
|
// populate the userinfo claims mapped by mapUserinfoProfile().
|
|
72
80
|
const DEFAULT_SCOPES = ['openid', 'profile', 'email'];
|
|
@@ -259,10 +267,13 @@ function mapUserinfoProfile(userinfo, groupsClaim) {
|
|
|
259
267
|
};
|
|
260
268
|
}
|
|
261
269
|
|
|
262
|
-
// Fetch and validate the discovery document for the configured issuer.
|
|
270
|
+
// Fetch and validate the discovery document for the configured issuer. Defaults to the
|
|
263
271
|
// shared RetryAgent (transient DNS/socket retries) with a hard timeout so a
|
|
264
|
-
// slow/unreachable IdP cannot stall API-worker startup indefinitely.
|
|
265
|
-
|
|
272
|
+
// slow/unreachable IdP cannot stall API-worker startup indefinitely. Callers that
|
|
273
|
+
// retry on their own schedule pass a plain dispatcher instead - see retryDiscovery().
|
|
274
|
+
async function fetchOidcDiscovery(options) {
|
|
275
|
+
options = options || {};
|
|
276
|
+
|
|
266
277
|
let url = getDiscoveryUrl(OIDC_ISSUER);
|
|
267
278
|
|
|
268
279
|
let res = await fetchCmd(url, {
|
|
@@ -271,7 +282,7 @@ async function fetchOidcDiscovery() {
|
|
|
271
282
|
'User-Agent': `${packageData.name}/${packageData.version} (+${packageData.homepage})`,
|
|
272
283
|
Accept: 'application/json'
|
|
273
284
|
},
|
|
274
|
-
dispatcher: httpAgent.retry,
|
|
285
|
+
dispatcher: options.dispatcher || httpAgent.retry,
|
|
275
286
|
signal: AbortSignal.timeout(DISCOVERY_TIMEOUT)
|
|
276
287
|
});
|
|
277
288
|
|
|
@@ -283,6 +294,37 @@ async function fetchOidcDiscovery() {
|
|
|
283
294
|
return validateDiscoveryDocument(doc, OIDC_ISSUER);
|
|
284
295
|
}
|
|
285
296
|
|
|
297
|
+
// Keep probing the discovery endpoint until it answers, resolving with the document.
|
|
298
|
+
// Callers use this after a failed startup fetch: discovery is what the bell strategy is
|
|
299
|
+
// built from, so a failure that is never retried leaves SSO switched off for the
|
|
300
|
+
// lifetime of the process - silently, and on a forced instance that looks like the
|
|
301
|
+
// admin panel reverting to password login on its own.
|
|
302
|
+
//
|
|
303
|
+
// Two deliberate departures from a plain fetch-with-retry. It waits before the first
|
|
304
|
+
// attempt, because this continues a fetch that has just failed rather than starting a
|
|
305
|
+
// fresh one. And each probe uses the plain dispatcher instead of the retrying one
|
|
306
|
+
// fetchOidcDiscovery() defaults to: this loop is itself the retry layer, and undici's
|
|
307
|
+
// ladder underneath it would turn every "cheap probe" into five connect attempts
|
|
308
|
+
// holding a socket for the whole 10s timeout.
|
|
309
|
+
async function retryDiscovery(options) {
|
|
310
|
+
options = options || {};
|
|
311
|
+
|
|
312
|
+
let fetchDiscovery = options.fetchDiscovery || (() => fetchOidcDiscovery({ dispatcher: httpAgent.fetch }));
|
|
313
|
+
|
|
314
|
+
return backOff(fetchDiscovery, {
|
|
315
|
+
delayFirstAttempt: true,
|
|
316
|
+
startingDelay: options.minDelay || DISCOVERY_RETRY_MIN,
|
|
317
|
+
maxDelay: options.maxDelay || DISCOVERY_RETRY_MAX,
|
|
318
|
+
numOfAttempts: Infinity,
|
|
319
|
+
retry: (err, attempt) => {
|
|
320
|
+
if (options.onError) {
|
|
321
|
+
options.onError(err, attempt);
|
|
322
|
+
}
|
|
323
|
+
return true;
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
|
|
286
328
|
// Build an OIDC RP-initiated logout URL against the IdP's end_session_endpoint.
|
|
287
329
|
// id_token_hint is included when available so the IdP skips its logout-confirmation
|
|
288
330
|
// prompt; client_id + post_logout_redirect_uri (the latter must be registered at the
|
|
@@ -350,6 +392,7 @@ module.exports = {
|
|
|
350
392
|
validateDiscoveryDocument,
|
|
351
393
|
mapUserinfoProfile,
|
|
352
394
|
fetchOidcDiscovery,
|
|
395
|
+
retryDiscovery,
|
|
353
396
|
buildLogoutUrl,
|
|
354
397
|
buildOidcBellProvider
|
|
355
398
|
};
|
package/lib/tools.js
CHANGED
|
@@ -400,10 +400,29 @@ function cidReferenceRegex() {
|
|
|
400
400
|
return new RegExp(CID_REFERENCE_SOURCE, 'g');
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
+
// Both the SMTP server and the IMAP proxy read the TLS certificate into their server options once,
|
|
404
|
+
// when their worker starts, rather than per handshake, so a newly issued certificate only reaches
|
|
405
|
+
// them through a reload. The list lives here rather than at each call site because the bug this
|
|
406
|
+
// replaces was exactly that: the renewal path reloaded the SMTP server and forgot the IMAP proxy,
|
|
407
|
+
// which then went on offering the expired certificate until something unrelated restarted it.
|
|
408
|
+
async function reloadTlsServers(call, logger, context) {
|
|
409
|
+
for (let cmd of ['smtpReload', 'imapProxyReload']) {
|
|
410
|
+
try {
|
|
411
|
+
await call({ cmd });
|
|
412
|
+
} catch (err) {
|
|
413
|
+
// Caught per command so a server that fails to come back does not cost the other one
|
|
414
|
+
// its new certificate, and so the failure is not reported as an acquisition failure.
|
|
415
|
+
logger.error(Object.assign({ msg: 'Failed to reload server after certificate change', cmd, err }, context || {}));
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
403
420
|
module.exports = {
|
|
404
421
|
// keep the re-export, lib/utils/to-camel-case.js holds it so pure modules can use it too
|
|
405
422
|
toCamelCase,
|
|
406
423
|
|
|
424
|
+
reloadTlsServers,
|
|
425
|
+
|
|
407
426
|
cidReferenceRegex,
|
|
408
427
|
|
|
409
428
|
/**
|
|
@@ -1345,9 +1345,16 @@ function init(args) {
|
|
|
1345
1345
|
}
|
|
1346
1346
|
}
|
|
1347
1347
|
|
|
1348
|
-
|
|
1348
|
+
// Stored entries outlive the logging switch - turning logging off does not clear what
|
|
1349
|
+
// was already collected - so the download control is gated on the entries themselves,
|
|
1350
|
+
// not on whether logging is currently enabled. Both are snapshots taken at render
|
|
1351
|
+
// time, the same as everything else on this page.
|
|
1352
|
+
let [logSettings, storedLogCount] = await Promise.all([settings.get('logs'), redis.llen(accountObject.getLogKey())]);
|
|
1353
|
+
|
|
1354
|
+
let logInfo = logSettings || {
|
|
1349
1355
|
all: false
|
|
1350
1356
|
};
|
|
1357
|
+
let hasStoredLogs = storedLogCount > 0;
|
|
1351
1358
|
|
|
1352
1359
|
accountData.path = [].concat(accountData.path || '*');
|
|
1353
1360
|
if (accountData.path.includes('*')) {
|
|
@@ -1455,6 +1462,7 @@ function init(args) {
|
|
|
1455
1462
|
accountAlert,
|
|
1456
1463
|
accountParked: !!disabledByAuthFailureAt,
|
|
1457
1464
|
logs: logInfo,
|
|
1465
|
+
hasStoredLogs,
|
|
1458
1466
|
smtpError: accountData.smtpStatus && accountData.smtpStatus.status === 'error',
|
|
1459
1467
|
|
|
1460
1468
|
showSmtp: accountData.smtp || (accountData.oauth2 && accountData.oauth2.provider),
|
|
@@ -52,6 +52,73 @@ async function oidcForcedActive(h) {
|
|
|
52
52
|
return !!(sso.OIDC_FORCED && sso.USE_OIDC_AUTH && (await h.validateOidcConfig()));
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// Authenticator transports recorded at registration, turned into the wording and icon the
|
|
56
|
+
// passkey list shows for each entry. 'internal' outranks 'hybrid' because a platform
|
|
57
|
+
// authenticator that can additionally be driven from a phone is still, to the person
|
|
58
|
+
// reading the list, the passkey living on that computer. The icon class is emitted whole
|
|
59
|
+
// and safelisted in app.tailwind.css with the other server-driven icons - this file is not
|
|
60
|
+
// scanned by Tailwind - so that the wording and the icon stay one mapping in one place.
|
|
61
|
+
const SECURITY_KEY_TRANSPORTS = ['usb', 'nfc', 'ble'];
|
|
62
|
+
|
|
63
|
+
function describePasskeyDevice(transports) {
|
|
64
|
+
let list = Array.isArray(transports) ? transports : [];
|
|
65
|
+
|
|
66
|
+
if (list.includes('internal')) {
|
|
67
|
+
return { label: 'Built-in authenticator', icon: 'icon-[tabler--fingerprint]' };
|
|
68
|
+
}
|
|
69
|
+
if (list.includes('hybrid')) {
|
|
70
|
+
return { label: 'Phone or tablet', icon: 'icon-[tabler--device-mobile]' };
|
|
71
|
+
}
|
|
72
|
+
if (list.some(transport => SECURITY_KEY_TRANSPORTS.includes(transport))) {
|
|
73
|
+
return { label: 'Security key', icon: 'icon-[tabler--usb]' };
|
|
74
|
+
}
|
|
75
|
+
return { label: 'Passkey', icon: 'icon-[tabler--key]' };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Normalizes a stored timestamp into the ISO string the client-side .relative-time
|
|
79
|
+
// formatter parses. A value that does not parse becomes null so the cell renders as
|
|
80
|
+
// "unknown" rather than as an empty gap.
|
|
81
|
+
function passkeyTimestamp(value) {
|
|
82
|
+
let date = value ? new Date(value) : null;
|
|
83
|
+
return date && !isNaN(date.getTime()) ? date.toISOString() : null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Single place that knows how a failed password check is interpreted: an absent password and a
|
|
87
|
+
// verify() that throws (which happens only on a malformed stored hash, never on a wrong password)
|
|
88
|
+
// are both failures, never a pass. Sign-in, the password change and both passkey registration
|
|
89
|
+
// steps all come through here, so a change to how the account password is checked - a KDF swap,
|
|
90
|
+
// a dummy verify to flatten timing - lands in one place.
|
|
91
|
+
async function verifyAdminPassword(hash, password, logger) {
|
|
92
|
+
if (!password) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
return await pbkdf2.verify(hash, password);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
logger.error({ msg: 'Failed to verify password hash', err });
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// View model for the security page's passkey list. Only the fields the list renders are
|
|
104
|
+
// exposed - the stored credential also carries the public key, the signature counter and
|
|
105
|
+
// the owning user, none of which belong in a template context.
|
|
106
|
+
async function listPasskeysForView(username) {
|
|
107
|
+
let credentials = await passkeys.listCredentials(username);
|
|
108
|
+
|
|
109
|
+
return credentials.map(credential => {
|
|
110
|
+
let device = describePasskeyDevice(credential.transports);
|
|
111
|
+
return {
|
|
112
|
+
id: credential.id,
|
|
113
|
+
name: credential.name,
|
|
114
|
+
deviceLabel: device.label,
|
|
115
|
+
deviceIcon: device.icon,
|
|
116
|
+
createdAt: passkeyTimestamp(credential.createdAt),
|
|
117
|
+
lastUsedAt: passkeyTimestamp(credential.lastUsedAt)
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
55
122
|
function init(args) {
|
|
56
123
|
const { server } = args;
|
|
57
124
|
|
|
@@ -206,14 +273,7 @@ function init(args) {
|
|
|
206
273
|
}
|
|
207
274
|
|
|
208
275
|
if (authData && authData.password) {
|
|
209
|
-
let valid;
|
|
210
|
-
try {
|
|
211
|
-
valid = await pbkdf2.verify(authData.password, request.payload.password);
|
|
212
|
-
} catch (E) {
|
|
213
|
-
// verify() only throws on a malformed stored hash, not on a wrong password
|
|
214
|
-
request.logger.error({ msg: 'Failed to verify password hash', err: E });
|
|
215
|
-
valid = false;
|
|
216
|
-
}
|
|
276
|
+
let valid = await verifyAdminPassword(authData.password, request.payload.password, request.logger);
|
|
217
277
|
if (!valid) {
|
|
218
278
|
request.logger.warn({ msg: 'Invalid password', user: request.payload.username, method: 'password', remoteAddress: request.app.ip });
|
|
219
279
|
let err = new Error('Failed to authenticate');
|
|
@@ -558,13 +618,16 @@ function init(args) {
|
|
|
558
618
|
return h.redirect(`/admin`);
|
|
559
619
|
}
|
|
560
620
|
|
|
621
|
+
// Single read for everything the page renders from - serviceUrl feeds both the TOTP
|
|
622
|
+
// label and the passkey registration gate
|
|
623
|
+
let { totpEnabled, totpSeed, serviceUrl } = await settings.getMulti('totpEnabled', 'totpSeed', 'serviceUrl');
|
|
624
|
+
|
|
561
625
|
let totp = {
|
|
562
|
-
enabled:
|
|
626
|
+
enabled: totpEnabled || false
|
|
563
627
|
};
|
|
564
628
|
|
|
565
629
|
let username = (request.auth && request.auth.credentials && request.auth.credentials.user) || 'admin';
|
|
566
630
|
|
|
567
|
-
let totpSeed = await settings.get('totpSeed');
|
|
568
631
|
if (!totpSeed) {
|
|
569
632
|
totpSeed = generateTotpSeed();
|
|
570
633
|
await settings.set('totpSeed', totpSeed);
|
|
@@ -572,10 +635,8 @@ function init(args) {
|
|
|
572
635
|
|
|
573
636
|
if (!totp.enabled) {
|
|
574
637
|
// create QR code
|
|
575
|
-
const serviceUrl = (await settings.get('serviceUrl')) || '';
|
|
576
|
-
|
|
577
638
|
let otpauth_url = generateTotpUrl(totpSeed, {
|
|
578
|
-
label: serviceUrl.replace(/^https?:\/\/|\/$/g, ''),
|
|
639
|
+
label: (serviceUrl || '').replace(/^https?:\/\/|\/$/g, ''),
|
|
579
640
|
issuer: 'EmailEngine'
|
|
580
641
|
});
|
|
581
642
|
|
|
@@ -586,20 +647,9 @@ function init(args) {
|
|
|
586
647
|
}
|
|
587
648
|
}
|
|
588
649
|
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
pk.createdAtFormatted = new Date(pk.createdAt).toLocaleDateString('en-US', {
|
|
593
|
-
year: 'numeric',
|
|
594
|
-
month: 'short',
|
|
595
|
-
day: 'numeric'
|
|
596
|
-
});
|
|
597
|
-
} catch (err) {
|
|
598
|
-
pk.createdAtFormatted = pk.createdAt;
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
let serviceUrl = await settings.get('serviceUrl');
|
|
650
|
+
// A count, not the list: this page summarizes passkeys and links to the page that
|
|
651
|
+
// manages them, so one SCARD replaces fetching every credential hash.
|
|
652
|
+
let passkeyCount = await passkeys.countCredentials(username);
|
|
603
653
|
|
|
604
654
|
return h.view(
|
|
605
655
|
'account/security',
|
|
@@ -612,7 +662,7 @@ function init(args) {
|
|
|
612
662
|
username,
|
|
613
663
|
|
|
614
664
|
totp,
|
|
615
|
-
|
|
665
|
+
passkeyCount,
|
|
616
666
|
serviceUrl,
|
|
617
667
|
providers: await ssoProviders(h),
|
|
618
668
|
okta: {
|
|
@@ -640,6 +690,55 @@ function init(args) {
|
|
|
640
690
|
}
|
|
641
691
|
});
|
|
642
692
|
|
|
693
|
+
// Passkeys get a page of their own, the way the password does: the security page above is an
|
|
694
|
+
// inventory of ways into the account, and a credential list that grows to MAX_PASSKEYS_PER_USER
|
|
695
|
+
// rows would take it over. Registering needs an account password, so an instance without one
|
|
696
|
+
// has nothing to show here.
|
|
697
|
+
server.route({
|
|
698
|
+
method: 'GET',
|
|
699
|
+
path: '/admin/account/passkeys',
|
|
700
|
+
async handler(request, h) {
|
|
701
|
+
if (request.auth.artifacts && request.auth.artifacts.provider) {
|
|
702
|
+
return h.redirect(`/admin`);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
let authData = await settings.get('authData');
|
|
706
|
+
if (!authData || !authData.password) {
|
|
707
|
+
return h.redirect('/admin/account/security');
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
let username = (request.auth && request.auth.credentials && request.auth.credentials.user) || 'admin';
|
|
711
|
+
|
|
712
|
+
let [registeredPasskeys, serviceUrl] = await Promise.all([listPasskeysForView(username), settings.get('serviceUrl')]);
|
|
713
|
+
|
|
714
|
+
// Both reasons registration would fail are known here, so the button is disabled with
|
|
715
|
+
// the reason on it instead of letting the ceremony run into a server error.
|
|
716
|
+
let passkeyBlockReason = null;
|
|
717
|
+
if (!serviceUrl) {
|
|
718
|
+
passkeyBlockReason = 'Set a Service URL in configuration before registering passkeys';
|
|
719
|
+
} else if (registeredPasskeys.length >= consts.MAX_PASSKEYS_PER_USER) {
|
|
720
|
+
passkeyBlockReason = `Maximum of ${consts.MAX_PASSKEYS_PER_USER} passkeys reached - remove one to register another`;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
return h.view(
|
|
724
|
+
'account/passkeys',
|
|
725
|
+
{
|
|
726
|
+
pageTitle: 'Passkeys',
|
|
727
|
+
menuAccountSecurity: true,
|
|
728
|
+
activePassword: false,
|
|
729
|
+
disableAuthWarning: true,
|
|
730
|
+
|
|
731
|
+
passkeys: registeredPasskeys,
|
|
732
|
+
passkeyBlockReason,
|
|
733
|
+
serviceUrl
|
|
734
|
+
},
|
|
735
|
+
{
|
|
736
|
+
layout: 'app'
|
|
737
|
+
}
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
|
|
643
742
|
server.route({
|
|
644
743
|
method: 'POST',
|
|
645
744
|
path: '/admin/account/tfa/enable',
|
|
@@ -831,20 +930,6 @@ function init(args) {
|
|
|
831
930
|
return h.response({ error: 'Account password must be configured before registering passkeys' }).code(403);
|
|
832
931
|
}
|
|
833
932
|
|
|
834
|
-
if (!request.payload.password) {
|
|
835
|
-
return h.response({ error: 'Current password is required' }).code(403);
|
|
836
|
-
}
|
|
837
|
-
let valid;
|
|
838
|
-
try {
|
|
839
|
-
valid = await pbkdf2.verify(authData.password, request.payload.password);
|
|
840
|
-
} catch (err) {
|
|
841
|
-
request.logger.error({ msg: 'Failed to verify password for passkey registration', err });
|
|
842
|
-
valid = false;
|
|
843
|
-
}
|
|
844
|
-
if (!valid) {
|
|
845
|
-
return h.response({ error: 'Invalid password' }).code(403);
|
|
846
|
-
}
|
|
847
|
-
|
|
848
933
|
let { rpId, origin } = await passkeys.getRpConfig();
|
|
849
934
|
if (!rpId || !origin) {
|
|
850
935
|
return h.response({ error: 'Service URL must be configured before registering passkeys' }).code(400);
|
|
@@ -857,6 +942,12 @@ function init(args) {
|
|
|
857
942
|
return h.response({ error: 'Maximum number of passkeys reached' }).code(400);
|
|
858
943
|
}
|
|
859
944
|
|
|
945
|
+
// Last, because it is the expensive check: the request is refused for a missing
|
|
946
|
+
// Service URL or a full list without paying for a PBKDF2 verification first
|
|
947
|
+
if (!(await verifyAdminPassword(authData.password, request.payload.password, request.logger))) {
|
|
948
|
+
return h.response({ error: 'Invalid password' }).code(403);
|
|
949
|
+
}
|
|
950
|
+
|
|
860
951
|
let options = await generateRegistrationOptions({
|
|
861
952
|
rpName: 'EmailEngine',
|
|
862
953
|
rpID: rpId,
|
|
@@ -873,7 +964,7 @@ function init(args) {
|
|
|
873
964
|
}
|
|
874
965
|
});
|
|
875
966
|
|
|
876
|
-
let challengeId = await passkeys.storeChallenge(options.challenge);
|
|
967
|
+
let challengeId = await passkeys.storeChallenge(options.challenge, passkeys.CHALLENGE_REGISTER);
|
|
877
968
|
|
|
878
969
|
return h.response({ challengeId, options }).code(200);
|
|
879
970
|
} catch (err) {
|
|
@@ -911,7 +1002,23 @@ function init(args) {
|
|
|
911
1002
|
return h.response({ error: 'Service URL must be configured' }).code(400);
|
|
912
1003
|
}
|
|
913
1004
|
|
|
914
|
-
let
|
|
1005
|
+
let authData = await settings.get('authData');
|
|
1006
|
+
if (!authData || !authData.password) {
|
|
1007
|
+
return h.response({ error: 'Account password must be configured before registering passkeys' }).code(403);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
// The password is confirmed again here, not only when the options were issued:
|
|
1011
|
+
// this is the request that stores a permanent credential, and a check one hop
|
|
1012
|
+
// upstream is only as good as the binding between the two hops. Belt and braces
|
|
1013
|
+
// over the challenge namespacing - a future third way to obtain a registration
|
|
1014
|
+
// challenge would otherwise reopen the bypass. Checked before the challenge is
|
|
1015
|
+
// consumed, so a mistyped password does not burn the nonce and force the whole
|
|
1016
|
+
// ceremony to be repeated.
|
|
1017
|
+
if (!(await verifyAdminPassword(authData.password, request.payload.password, request.logger))) {
|
|
1018
|
+
return h.response({ error: 'Invalid password' }).code(403);
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
let challenge = await passkeys.consumeChallenge(request.payload.challengeId, passkeys.CHALLENGE_REGISTER);
|
|
915
1022
|
if (!challenge) {
|
|
916
1023
|
return h.response({ error: 'Challenge expired or invalid. Please try again.' }).code(400);
|
|
917
1024
|
}
|
|
@@ -930,11 +1037,6 @@ function init(args) {
|
|
|
930
1037
|
let { credential } = verification.registrationInfo;
|
|
931
1038
|
let user = (request.auth && request.auth.credentials && request.auth.credentials.user) || 'admin';
|
|
932
1039
|
|
|
933
|
-
let authData = await settings.get('authData');
|
|
934
|
-
if (!authData || !authData.password) {
|
|
935
|
-
return h.response({ error: 'Account password must be configured before registering passkeys' }).code(403);
|
|
936
|
-
}
|
|
937
|
-
|
|
938
1040
|
let saved = await passkeys.saveCredentialIfUnderLimit(
|
|
939
1041
|
{
|
|
940
1042
|
id: credential.id,
|
|
@@ -974,6 +1076,7 @@ function init(args) {
|
|
|
974
1076
|
},
|
|
975
1077
|
payload: Joi.object({
|
|
976
1078
|
challengeId: Joi.string().hex().length(64).required(),
|
|
1079
|
+
password: Joi.string().max(256).allow('', null).optional().label('Current password'),
|
|
977
1080
|
name: Joi.string().max(100).empty('').default('Unnamed passkey'),
|
|
978
1081
|
credential: passkeyCredentialSchema
|
|
979
1082
|
})
|
|
@@ -1009,7 +1112,7 @@ function init(args) {
|
|
|
1009
1112
|
await request.flash({ type: 'danger', message: 'Failed to remove passkey' });
|
|
1010
1113
|
request.logger.error({ msg: 'Failed to delete passkey', err });
|
|
1011
1114
|
}
|
|
1012
|
-
return h.redirect('/admin/account/
|
|
1115
|
+
return h.redirect('/admin/account/passkeys');
|
|
1013
1116
|
},
|
|
1014
1117
|
options: {
|
|
1015
1118
|
validate: {
|
|
@@ -1022,7 +1125,7 @@ function init(args) {
|
|
|
1022
1125
|
async failAction(request, h, err) {
|
|
1023
1126
|
await request.flash({ type: 'danger', message: 'Failed to remove passkey' });
|
|
1024
1127
|
request.logger.debug({ msg: 'Failed to delete passkey', err });
|
|
1025
|
-
return h.redirect('/admin/account/
|
|
1128
|
+
return h.redirect('/admin/account/passkeys').takeover();
|
|
1026
1129
|
},
|
|
1027
1130
|
|
|
1028
1131
|
payload: Joi.object({
|
|
@@ -1070,7 +1173,7 @@ function init(args) {
|
|
|
1070
1173
|
userVerification: 'required'
|
|
1071
1174
|
});
|
|
1072
1175
|
|
|
1073
|
-
let challengeId = await passkeys.storeChallenge(options.challenge);
|
|
1176
|
+
let challengeId = await passkeys.storeChallenge(options.challenge, passkeys.CHALLENGE_AUTH);
|
|
1074
1177
|
|
|
1075
1178
|
return h.response({ challengeId, options }).code(200);
|
|
1076
1179
|
} catch (err) {
|
|
@@ -1120,7 +1223,7 @@ function init(args) {
|
|
|
1120
1223
|
return h.response({ success: false, error: 'Authentication failed' }).code(400);
|
|
1121
1224
|
}
|
|
1122
1225
|
|
|
1123
|
-
let challenge = await passkeys.consumeChallenge(request.payload.challengeId);
|
|
1226
|
+
let challenge = await passkeys.consumeChallenge(request.payload.challengeId, passkeys.CHALLENGE_AUTH);
|
|
1124
1227
|
if (!challenge) {
|
|
1125
1228
|
request.logger.warn({ msg: 'Passkey auth failed: challenge expired or invalid', method: 'passkey', remoteAddress: request.app.ip });
|
|
1126
1229
|
return h.response({ success: false, error: 'Challenge expired or invalid. Please try again.' }).code(400);
|
|
@@ -1159,7 +1262,7 @@ function init(args) {
|
|
|
1159
1262
|
return h.response({ success: false, error: 'Authentication failed' }).code(400);
|
|
1160
1263
|
}
|
|
1161
1264
|
|
|
1162
|
-
await passkeys.
|
|
1265
|
+
await passkeys.recordAuthentication(storedCredential.id, verification.authenticationInfo.newCounter);
|
|
1163
1266
|
|
|
1164
1267
|
setAdminSession(request, {
|
|
1165
1268
|
user,
|
|
@@ -1264,14 +1367,7 @@ function init(args) {
|
|
|
1264
1367
|
throw err;
|
|
1265
1368
|
}
|
|
1266
1369
|
|
|
1267
|
-
let valid;
|
|
1268
|
-
try {
|
|
1269
|
-
valid = await pbkdf2.verify(authData.password, request.payload.password0);
|
|
1270
|
-
} catch (E) {
|
|
1271
|
-
// verify() only throws on a malformed stored hash, not on a wrong password
|
|
1272
|
-
request.logger.error({ msg: 'Failed to verify password hash', err: E });
|
|
1273
|
-
valid = false;
|
|
1274
|
-
}
|
|
1370
|
+
let valid = await verifyAdminPassword(authData.password, request.payload.password0, request.logger);
|
|
1275
1371
|
if (!valid) {
|
|
1276
1372
|
request.logger.warn({ msg: 'Invalid current password', remoteAddress: request.app.ip });
|
|
1277
1373
|
let err = new Error('Failed to verify current password');
|
|
@@ -13,7 +13,7 @@ const { parentPort } = require('worker_threads');
|
|
|
13
13
|
const settings = require('../settings');
|
|
14
14
|
const { redis } = require('../db');
|
|
15
15
|
const { REDIS_PREFIX } = require('../consts');
|
|
16
|
-
const { failAction, getServiceHostname } = require('../tools');
|
|
16
|
+
const { failAction, getServiceHostname, reloadTlsServers } = require('../tools');
|
|
17
17
|
const { ADDRESS_STRATEGIES, settingsSchema } = require('../schemas');
|
|
18
18
|
const { updatePublicInterfaces } = require('../utils/network');
|
|
19
19
|
const { getServerStatus, cachedTemplates } = require('./route-helpers');
|
|
@@ -362,11 +362,20 @@ function init(args) {
|
|
|
362
362
|
path: '/admin/config/smtp/certificate',
|
|
363
363
|
async handler(request, h) {
|
|
364
364
|
try {
|
|
365
|
+
// What is installed before provisioning, so the reload below fires only when a new
|
|
366
|
+
// certificate actually arrived and repeated clicks do not keep restarting both
|
|
367
|
+
// servers.
|
|
368
|
+
let existingCertificateData = await h.getCertificate();
|
|
369
|
+
|
|
365
370
|
let certificateData = await h.getCertificate(true);
|
|
366
371
|
if (!certificateData) {
|
|
367
372
|
throw new Error(`Failed to provision a ceritifcate`);
|
|
368
373
|
}
|
|
369
374
|
|
|
375
|
+
if (certificateData.fingerprint && certificateData.fingerprint !== (existingCertificateData && existingCertificateData.fingerprint)) {
|
|
376
|
+
await reloadTlsServers(call, request.logger, { domain: certificateData.domain });
|
|
377
|
+
}
|
|
378
|
+
|
|
370
379
|
return {
|
|
371
380
|
success: true,
|
|
372
381
|
domain: certificateData.domain,
|