emailengine-app 2.77.0 → 2.78.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/.github/workflows/test.yml +80 -0
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +31 -0
- package/bin/emailengine.js +1 -1
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +1 -1
- package/lib/account/expected-identity.js +88 -0
- package/lib/account.js +75 -26
- package/lib/api-reference/format.js +14 -0
- package/lib/api-reference/index.js +24 -7
- package/lib/api-reference/model.js +4 -2
- package/lib/api-routes/account-routes.js +19 -2
- package/lib/api-routes/behavior-notes.js +3 -0
- package/lib/append-list.js +3 -14
- package/lib/arf-detect.js +23 -1
- package/lib/autodetect-imap-settings.js +40 -16
- package/lib/base32.js +30 -0
- package/lib/bounce-detect.js +182 -62
- package/lib/egress-filter.js +89 -8
- package/lib/email-client/base-client.js +8 -72
- package/lib/email-client/gmail-client.js +3 -3
- package/lib/email-client/imap/listing-diff.js +3 -3
- package/lib/email-client/imap/mailbox.js +5 -69
- package/lib/email-client/imap-client.js +3 -2
- package/lib/email-client/message-builder.js +13 -13
- package/lib/email-client/outlook-client.js +1 -1
- package/lib/export.js +1 -1
- package/lib/gateway.js +1 -1
- package/lib/get-raw-email.js +1 -1
- package/lib/imapproxy/imap-core/lib/imap-connection.js +2 -2
- package/lib/imapproxy/imap-core/lib/imap-server.js +2 -2
- package/lib/imapproxy/imap-server.js +13 -3
- package/lib/license-beacon.js +1 -1
- package/lib/llm-pre-process.js +1 -1
- package/lib/msgpack.js +62 -0
- package/lib/oauth/decode-jwt-payload.js +39 -0
- package/lib/oauth/outlook-identity.js +61 -0
- package/lib/oauth/retry-setup.js +38 -0
- package/lib/oauth2-apps.js +1 -1
- package/lib/outbox.js +66 -3
- package/lib/pre-process.js +1 -1
- package/lib/read-env-value.js +37 -0
- package/lib/schemas.js +12 -0
- package/lib/templates.js +1 -1
- package/lib/tokens.js +1 -1
- package/lib/tools.js +117 -48
- package/lib/totp.js +67 -0
- package/lib/ui-routes/account-routes.js +91 -15
- package/lib/ui-routes/admin-config-routes.js +2 -7
- package/lib/ui-routes/auth-routes.js +6 -24
- package/lib/ui-routes/reference-routes.js +8 -5
- package/lib/ui-routes/route-helpers.js +28 -0
- package/lib/utils/is-email.js +34 -0
- package/lib/utils/to-camel-case.js +17 -0
- package/lib/webhook-egress.js +37 -0
- package/lib/webhooks.js +1 -1
- package/package.json +22 -24
- package/sbom.json +1 -0
- package/server.js +1 -1
- package/static/css/flyonui.css +1 -1
- package/static/css/public.css +3 -0
- package/static/css/src/app.tailwind.css +23 -0
- package/static/js/app.js +69 -0
- package/static/js/reference.js +286 -1
- package/static/licenses.html +656 -1558
- package/translations/README.md +64 -0
- package/translations/de.mo +0 -0
- package/translations/de.po +164 -120
- package/translations/en.po +200 -161
- package/translations/et.mo +0 -0
- package/translations/et.po +163 -120
- package/translations/fr.mo +0 -0
- package/translations/fr.po +163 -120
- package/translations/ja.mo +0 -0
- package/translations/ja.po +163 -120
- package/translations/messages.pot +76 -46
- package/translations/nl.mo +0 -0
- package/translations/nl.po +164 -120
- package/translations/pl.mo +0 -0
- package/translations/pl.po +163 -120
- package/views/account-identity-error.hbs +34 -0
- package/views/accounts/edit.hbs +1 -0
- package/views/accounts/register/imap.hbs +12 -2
- package/views/layout/app.hbs +29 -5
- package/views/oauth-scope-error.hbs +1 -1
- package/views/partials/reference/nav.hbs +36 -9
- package/views/partials/reference/operation.hbs +1 -1
- package/views/partials/reference/schema-node.hbs +1 -1
- package/views/partials/reference/token-alert.hbs +35 -10
- package/views/reference/index.hbs +1 -1
- package/workers/api.js +157 -87
- package/workers/imap.js +1 -1
- package/workers/submit.js +1 -1
- package/workers/webhooks.js +2 -13
|
@@ -34,8 +34,16 @@ const {
|
|
|
34
34
|
readEnvValue,
|
|
35
35
|
failAction
|
|
36
36
|
} = require('../tools');
|
|
37
|
-
const {
|
|
38
|
-
|
|
37
|
+
const {
|
|
38
|
+
settingsSchema,
|
|
39
|
+
accountSchemas,
|
|
40
|
+
accountIdSchema,
|
|
41
|
+
defaultAccountTypeSchema,
|
|
42
|
+
ACCOUNT_DISPLAY_STATES,
|
|
43
|
+
signedFormBlobFields: signedBlobFields
|
|
44
|
+
} = require('../schemas');
|
|
45
|
+
const { formatAccountData, cachedTemplates, identityErrorView, ACCOUNT_STATE_DISPLAY } = require('./route-helpers');
|
|
46
|
+
const { matchesExpectedIdentity, resolveExpectedIdentity } = require('../account/expected-identity');
|
|
39
47
|
|
|
40
48
|
const { REDIS_PREFIX, DEFAULT_PAGE_SIZE, NONCE_BYTES, MAX_FORM_TTL, MAX_FORM_PROBE_ATTEMPTS } = consts;
|
|
41
49
|
|
|
@@ -358,7 +366,7 @@ function init(args) {
|
|
|
358
366
|
|
|
359
367
|
accountData.notifyFrom = data.notifyFrom || new Date().toISOString();
|
|
360
368
|
|
|
361
|
-
for (let key of ['redirectUrl', 'n', 't']) {
|
|
369
|
+
for (let key of ['redirectUrl', 'expectedEmail', 'n', 't']) {
|
|
362
370
|
if (!accountData._meta) {
|
|
363
371
|
accountData._meta = {};
|
|
364
372
|
}
|
|
@@ -408,6 +416,8 @@ function init(args) {
|
|
|
408
416
|
return h.redirect(authorizeUrl);
|
|
409
417
|
}
|
|
410
418
|
|
|
419
|
+
const expectedEmail = await resolveFormExpectation(data);
|
|
420
|
+
|
|
411
421
|
return h.view(
|
|
412
422
|
'accounts/register/imap',
|
|
413
423
|
{
|
|
@@ -416,7 +426,10 @@ function init(args) {
|
|
|
416
426
|
data: request.payload.data,
|
|
417
427
|
sig: request.payload.sig,
|
|
418
428
|
|
|
419
|
-
|
|
429
|
+
// A pinned link fixes the address, so prefill from the expectation rather than from the
|
|
430
|
+
// editable hint and mark it read-only. Cosmetic - the endpoints below enforce it.
|
|
431
|
+
email: expectedEmail || data.email,
|
|
432
|
+
emailPinned: !!expectedEmail,
|
|
420
433
|
name: data.name
|
|
421
434
|
}
|
|
422
435
|
},
|
|
@@ -656,6 +669,54 @@ function init(args) {
|
|
|
656
669
|
return data;
|
|
657
670
|
};
|
|
658
671
|
|
|
672
|
+
// The expectation that applies to a parsed form blob (lib/account/expected-identity.js owns the
|
|
673
|
+
// precedence and the lazy Redis fallback).
|
|
674
|
+
const resolveFormExpectation = data => resolveExpectedIdentity(redis, { account: data.account, blobExpectation: data.expectedEmail });
|
|
675
|
+
|
|
676
|
+
// Expected identity gate for the IMAP arm, mirroring the one the OAuth callback applies in
|
|
677
|
+
// workers/api.js.
|
|
678
|
+
//
|
|
679
|
+
// The evidence here is only the address typed into the form. Working credentials do not prove that
|
|
680
|
+
// the address belongs to the mailbox behind them, so this enforces "the account is registered under
|
|
681
|
+
// the expected address" and nothing stronger - which is exactly what the field documents. Without it
|
|
682
|
+
// the constraint would be trivially sidestepped by choosing the IMAP tab on a form that also offers
|
|
683
|
+
// OAuth2.
|
|
684
|
+
//
|
|
685
|
+
// Returns { expectedEmail, matched } rather than throwing so the caller can name the address that was
|
|
686
|
+
// actually used when it reports the rejection.
|
|
687
|
+
const checkExpectedIdentity = async (data, submittedEmail) => {
|
|
688
|
+
const expectedEmail = await resolveFormExpectation(data);
|
|
689
|
+
return { expectedEmail, matched: !expectedEmail || matchesExpectedIdentity(expectedEmail, [submittedEmail]) };
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
// Stop the flow with a way back rather than a redirect to the calling application: entering the wrong
|
|
693
|
+
// address is correctable, and the hosted form only ever redirects on success. The OAuth arm renders
|
|
694
|
+
// the same view (workers/api.js), differing only in where "try again" points.
|
|
695
|
+
//
|
|
696
|
+
// type=imap keeps the user on the arm they already chose: without it /accounts/new re-asks the
|
|
697
|
+
// provider question and offers OAuth apps they passed over. The signed blob is still unspent (the
|
|
698
|
+
// nonce is claimed only on success), so the link works, and the form it returns to prefills the
|
|
699
|
+
// pinned address read-only.
|
|
700
|
+
const renderIdentityError = (request, h, expectedEmail, actualEmail) =>
|
|
701
|
+
identityErrorView(request, h, {
|
|
702
|
+
expectedEmail,
|
|
703
|
+
actualEmail,
|
|
704
|
+
retryUrl: `/accounts/new?data=${encodeURIComponent(request.payload.data)}&sig=${encodeURIComponent(request.payload.sig)}&type=imap`
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
// have to use HTML redirect, otherwise samesite=strict cookies are not passed on
|
|
708
|
+
const renderRedirect = (request, h, httpRedirectUrl) =>
|
|
709
|
+
h.view(
|
|
710
|
+
'redirect',
|
|
711
|
+
{
|
|
712
|
+
pageTitleFull: request.app.gt.gettext('Email Account Setup'),
|
|
713
|
+
httpRedirectUrl
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
layout: 'public'
|
|
717
|
+
}
|
|
718
|
+
);
|
|
719
|
+
|
|
659
720
|
server.route({
|
|
660
721
|
method: 'POST',
|
|
661
722
|
path: '/accounts/new/imap',
|
|
@@ -663,7 +724,14 @@ function init(args) {
|
|
|
663
724
|
async handler(request, h) {
|
|
664
725
|
// Bound outbound autodiscovery per issued blob (shared cap with the connection tester) so a
|
|
665
726
|
// leaked signed link cannot drive unlimited outbound probes to arbitrary domains.
|
|
666
|
-
await authorizeSignedProbe(request.payload, request.app.gt, request.logger);
|
|
727
|
+
const data = await authorizeSignedProbe(request.payload, request.app.gt, request.logger);
|
|
728
|
+
|
|
729
|
+
// Reject a pinned link early, before autodiscovery runs against the submitted domain, so the
|
|
730
|
+
// user finds out before typing a password. The create endpoint below is the authoritative check.
|
|
731
|
+
const { expectedEmail, matched } = await checkExpectedIdentity(data, request.payload.email);
|
|
732
|
+
if (!matched) {
|
|
733
|
+
return renderIdentityError(request, h, expectedEmail, request.payload.email);
|
|
734
|
+
}
|
|
667
735
|
|
|
668
736
|
let serverSettings;
|
|
669
737
|
try {
|
|
@@ -909,6 +977,13 @@ function init(args) {
|
|
|
909
977
|
async handler(request, h) {
|
|
910
978
|
const data = await parseSignedFormData(redis, request.payload, request.app.gt, { requireNonce: true });
|
|
911
979
|
|
|
980
|
+
// Before the nonce claim below, so a rejected attempt does not consume the setup link and the
|
|
981
|
+
// "try again" link on the error page still works.
|
|
982
|
+
const { expectedEmail, matched } = await checkExpectedIdentity(data, request.payload.email);
|
|
983
|
+
if (!matched) {
|
|
984
|
+
return renderIdentityError(request, h, expectedEmail, request.payload.email);
|
|
985
|
+
}
|
|
986
|
+
|
|
912
987
|
const accountData = {
|
|
913
988
|
account: data.account || null,
|
|
914
989
|
name: request.payload.name || data.name,
|
|
@@ -946,6 +1021,11 @@ function init(args) {
|
|
|
946
1021
|
accountData.subconnections = data.subconnections;
|
|
947
1022
|
}
|
|
948
1023
|
|
|
1024
|
+
if (expectedEmail) {
|
|
1025
|
+
// Pin the account so later setups are checked even from a link that carries no expectation.
|
|
1026
|
+
accountData.expectedEmail = expectedEmail;
|
|
1027
|
+
}
|
|
1028
|
+
|
|
949
1029
|
const accountObject = new Account({ redis, call, secret: await getSecret() });
|
|
950
1030
|
|
|
951
1031
|
// Claim the single-use nonce BEFORE creating the account so a concurrent double-submit or
|
|
@@ -1000,16 +1080,7 @@ function init(args) {
|
|
|
1000
1080
|
httpRedirectUrl = `/admin/accounts/${result.account}`;
|
|
1001
1081
|
}
|
|
1002
1082
|
|
|
1003
|
-
return h
|
|
1004
|
-
'redirect',
|
|
1005
|
-
{
|
|
1006
|
-
pageTitleFull: request.app.gt.gettext('Email Account Setup'),
|
|
1007
|
-
httpRedirectUrl
|
|
1008
|
-
},
|
|
1009
|
-
{
|
|
1010
|
-
layout: 'public'
|
|
1011
|
-
}
|
|
1012
|
-
);
|
|
1083
|
+
return renderRedirect(request, h, httpRedirectUrl);
|
|
1013
1084
|
},
|
|
1014
1085
|
options: {
|
|
1015
1086
|
auth: false,
|
|
@@ -1766,6 +1837,9 @@ function init(args) {
|
|
|
1766
1837
|
account: request.params.account,
|
|
1767
1838
|
name: request.payload.name || '',
|
|
1768
1839
|
email: request.payload.email,
|
|
1840
|
+
// Empty clears the pin (Account.update hdel's it), which is the only way an operator
|
|
1841
|
+
// can unblock a legitimate mailbox migration on a pinned account.
|
|
1842
|
+
expectedEmail: request.payload.expectedEmail || null,
|
|
1769
1843
|
proxy: request.payload.proxy,
|
|
1770
1844
|
smtpEhloName: request.payload.smtpEhloName,
|
|
1771
1845
|
webhooks: request.payload.webhooks
|
|
@@ -1967,6 +2041,8 @@ function init(args) {
|
|
|
1967
2041
|
name: Joi.string().empty('').max(256).example('John Smith').description('Account Name'),
|
|
1968
2042
|
email: Joi.string().email().required().example('user@example.com').label('Email').description('Your account email'),
|
|
1969
2043
|
|
|
2044
|
+
expectedEmail: accountSchemas.expectedEmail,
|
|
2045
|
+
|
|
1970
2046
|
proxy: settingsSchema.proxyUrl,
|
|
1971
2047
|
smtpEhloName: settingsSchema.smtpEhloName,
|
|
1972
2048
|
|
|
@@ -22,7 +22,7 @@ const getSecret = require('../get-secret');
|
|
|
22
22
|
const timezonesList = require('timezones-list').default;
|
|
23
23
|
const { redis, submitQueue, notifyQueue, documentsQueue } = require('../db');
|
|
24
24
|
const { getByteSize, formatByteSize, getDuration, failAction, readEnvValue, readEnvList, httpAgent } = require('../tools');
|
|
25
|
-
const {
|
|
25
|
+
const { validateWebhookTarget } = require('../webhook-egress');
|
|
26
26
|
const { sendWebhookRequest } = require('../webhook-request');
|
|
27
27
|
const { llmPreProcess } = require('../llm-pre-process');
|
|
28
28
|
const { documentStoreFeatureEnabled } = require('../document-store');
|
|
@@ -55,11 +55,6 @@ const MAX_PAYLOAD_TIMEOUT = getDuration(readEnvValue('EENGINE_MAX_PAYLOAD_TIMEOU
|
|
|
55
55
|
|
|
56
56
|
const ADMIN_ACCESS_ADDRESSES = readEnvList('EENGINE_ADMIN_ACCESS_ADDRESSES');
|
|
57
57
|
|
|
58
|
-
// Must match the policy the webhooks worker enforces on real deliveries, including the null that
|
|
59
|
-
// tells sendWebhookRequest to keep following redirects when the policy is off
|
|
60
|
-
const WEBHOOK_EGRESS_POLICY = normalizePolicy(readEnvValue('EENGINE_WEBHOOK_EGRESS_POLICY'));
|
|
61
|
-
const validateWebhookTarget = WEBHOOK_EGRESS_POLICY === POLICY_OFF ? null : target => assertAllowedUrl(target, { policy: WEBHOOK_EGRESS_POLICY });
|
|
62
|
-
|
|
63
58
|
const IMAP_INDEXERS = [
|
|
64
59
|
{
|
|
65
60
|
id: 'full',
|
|
@@ -1088,7 +1083,7 @@ return true;`
|
|
|
1088
1083
|
}
|
|
1089
1084
|
}),
|
|
1090
1085
|
headers,
|
|
1091
|
-
dispatcher: httpAgent.
|
|
1086
|
+
dispatcher: httpAgent.webhook,
|
|
1092
1087
|
validateTarget: validateWebhookTarget
|
|
1093
1088
|
});
|
|
1094
1089
|
duration = Date.now() - start;
|
|
@@ -12,8 +12,7 @@ const Joi = require('joi');
|
|
|
12
12
|
const crypto = require('crypto');
|
|
13
13
|
const pbkdf2 = require('@phc/pbkdf2');
|
|
14
14
|
const QRCode = require('qrcode');
|
|
15
|
-
const
|
|
16
|
-
const base32 = require('base32.js');
|
|
15
|
+
const { generateTotpSeed, verifyTotp, generateTotpUrl } = require('../totp');
|
|
17
16
|
const {
|
|
18
17
|
generateRegistrationOptions,
|
|
19
18
|
verifyRegistrationResponse,
|
|
@@ -424,12 +423,7 @@ function init(args) {
|
|
|
424
423
|
return h.redirect(`/admin/login`);
|
|
425
424
|
}
|
|
426
425
|
|
|
427
|
-
let verified =
|
|
428
|
-
secret: base32.encode(Buffer.from(totpSeed)),
|
|
429
|
-
encoding: 'base32',
|
|
430
|
-
token: request.payload.code,
|
|
431
|
-
window: TOTP_WINDOW_SIZE
|
|
432
|
-
});
|
|
426
|
+
let verified = verifyTotp(totpSeed, request.payload.code, { window: TOTP_WINDOW_SIZE });
|
|
433
427
|
|
|
434
428
|
if (!verified) {
|
|
435
429
|
let err = new Error('Failed to verify login');
|
|
@@ -569,12 +563,7 @@ function init(args) {
|
|
|
569
563
|
|
|
570
564
|
let totpSeed = await settings.get('totpSeed');
|
|
571
565
|
if (!totpSeed) {
|
|
572
|
-
|
|
573
|
-
length: 20,
|
|
574
|
-
name: username
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
totpSeed = secret.ascii;
|
|
566
|
+
totpSeed = generateTotpSeed();
|
|
578
567
|
await settings.set('totpSeed', totpSeed);
|
|
579
568
|
}
|
|
580
569
|
|
|
@@ -582,10 +571,8 @@ function init(args) {
|
|
|
582
571
|
// create QR code
|
|
583
572
|
const serviceUrl = (await settings.get('serviceUrl')) || '';
|
|
584
573
|
|
|
585
|
-
let otpauth_url =
|
|
586
|
-
|
|
587
|
-
// label is part of URL and speakeasy as of v2.0.0 does not encode special characters
|
|
588
|
-
label: encodeURIComponent(serviceUrl.replace(/^https?:\/\/|\/$/g, '')),
|
|
574
|
+
let otpauth_url = generateTotpUrl(totpSeed, {
|
|
575
|
+
label: serviceUrl.replace(/^https?:\/\/|\/$/g, ''),
|
|
589
576
|
issuer: 'EmailEngine'
|
|
590
577
|
});
|
|
591
578
|
|
|
@@ -665,12 +652,7 @@ function init(args) {
|
|
|
665
652
|
return h.redirect(`/admin/account/security`);
|
|
666
653
|
}
|
|
667
654
|
|
|
668
|
-
let verified =
|
|
669
|
-
secret: base32.encode(Buffer.from(totpSeed)),
|
|
670
|
-
encoding: 'base32',
|
|
671
|
-
token: request.payload.code,
|
|
672
|
-
window: TOTP_WINDOW_SIZE
|
|
673
|
-
});
|
|
655
|
+
let verified = verifyTotp(totpSeed, request.payload.code, { window: TOTP_WINDOW_SIZE });
|
|
674
656
|
|
|
675
657
|
if (!verified) {
|
|
676
658
|
await request.flash({ type: 'danger', message: `Invalid verification code` });
|
|
@@ -27,6 +27,11 @@ const TEMP_TOKEN_TTL = 60 * 60 * 1000;
|
|
|
27
27
|
// can never be deleted by clearing the field.
|
|
28
28
|
const TEMP_TOKEN_DESCRIPTION = 'Temporary token for the API reference';
|
|
29
29
|
|
|
30
|
+
// Opts every reference page into the layout's second navigation column, rendered flush
|
|
31
|
+
// against the main sidebar (views/layout/app.hbs). The label names it where the column
|
|
32
|
+
// cannot be shown as a column - below lg it collapses to a single row carrying this text.
|
|
33
|
+
const SECONDARY_NAV = { secondaryNav: 'reference/nav', secondaryNavLabel: 'Endpoints' };
|
|
34
|
+
|
|
30
35
|
function init(args) {
|
|
31
36
|
const { server } = args;
|
|
32
37
|
|
|
@@ -36,9 +41,7 @@ function init(args) {
|
|
|
36
41
|
async handler(request, h) {
|
|
37
42
|
const view = await getIndexView(request);
|
|
38
43
|
|
|
39
|
-
|
|
40
|
-
// rendered flush against the main sidebar (views/layout/app.hbs)
|
|
41
|
-
return h.view('reference/index', Object.assign({ pageTitle: 'API Reference', menuReference: true, secondaryNav: 'reference/nav' }, view), {
|
|
44
|
+
return h.view('reference/index', Object.assign({ pageTitle: 'API Reference', menuReference: true, ...SECONDARY_NAV }, view), {
|
|
42
45
|
layout: 'app'
|
|
43
46
|
});
|
|
44
47
|
}
|
|
@@ -53,7 +56,7 @@ function init(args) {
|
|
|
53
56
|
async handler(request, h) {
|
|
54
57
|
const view = await getNavView(request);
|
|
55
58
|
|
|
56
|
-
return h.view('reference/token', Object.assign({ pageTitle: 'Access token', menuReference: true,
|
|
59
|
+
return h.view('reference/token', Object.assign({ pageTitle: 'Access token', menuReference: true, ...SECONDARY_NAV }, view), {
|
|
57
60
|
layout: 'app'
|
|
58
61
|
});
|
|
59
62
|
}
|
|
@@ -69,7 +72,7 @@ function init(args) {
|
|
|
69
72
|
throw Boom.notFound('Unknown endpoint group');
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
return h.view('reference/tag', Object.assign({ pageTitle: `${view.tag.name} API`, menuReference: true,
|
|
75
|
+
return h.view('reference/tag', Object.assign({ pageTitle: `${view.tag.name} API`, menuReference: true, ...SECONDARY_NAV }, view), {
|
|
73
76
|
layout: 'app'
|
|
74
77
|
});
|
|
75
78
|
},
|
|
@@ -336,8 +336,36 @@ function jsonErrorPayload(err) {
|
|
|
336
336
|
return { success: false, error: err.code || 'Error', message: err.message };
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
+
// The "wrong account" page, shown when a setup link pinned to one address is completed as another.
|
|
340
|
+
// Rendered from both arms of the hosted form - the OAuth2 callback in workers/api.js and the IMAP arm in
|
|
341
|
+
// ./account-routes.js - which live in different workers, so the view name, the layout and the refusal
|
|
342
|
+
// status are kept here rather than written out twice. Only `retryUrl` is arm-specific: the OAuth arm
|
|
343
|
+
// sends the user back to the provider, the IMAP arm back to the form.
|
|
344
|
+
//
|
|
345
|
+
// 403 rather than the 200 that the sibling views/oauth-scope-error.hbs returns: this is a refused
|
|
346
|
+
// request, the surrounding refusals in the same flow already answer 403, and both call sites are plain
|
|
347
|
+
// form navigations, so the browser still renders the page.
|
|
348
|
+
function identityErrorView(request, h, { expectedEmail, actualEmail, retryUrl }) {
|
|
349
|
+
return h
|
|
350
|
+
.view(
|
|
351
|
+
'account-identity-error',
|
|
352
|
+
{
|
|
353
|
+
pageTitleFull: request.app.gt.gettext('Email Account Setup'),
|
|
354
|
+
templateLocale: request.app.locale,
|
|
355
|
+
expectedEmail,
|
|
356
|
+
actualEmail,
|
|
357
|
+
retryUrl
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
layout: 'public'
|
|
361
|
+
}
|
|
362
|
+
)
|
|
363
|
+
.code(403);
|
|
364
|
+
}
|
|
365
|
+
|
|
339
366
|
module.exports = {
|
|
340
367
|
jsonErrorPayload,
|
|
368
|
+
identityErrorView,
|
|
341
369
|
OPEN_AI_MODELS,
|
|
342
370
|
cachedTemplates,
|
|
343
371
|
getOpenAiModels,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Joi = require('joi');
|
|
4
|
+
|
|
5
|
+
// Built once. joi schemas are immutable and meant to be reused, and compiling this per call measured
|
|
6
|
+
// ~5x slower - which matters because unserializeAccountData() calls isEmail() for every OAuth2 account
|
|
7
|
+
// that has no stored email, and the account listing maps that over every row of a page.
|
|
8
|
+
const emailSchema = Joi.object({
|
|
9
|
+
email: Joi.string().email().required()
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const validateOptions = {
|
|
13
|
+
abortEarly: false,
|
|
14
|
+
stripUnknown: true,
|
|
15
|
+
convert: true
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Syntactic check only - it says the string is shaped like an address, never that the address is real
|
|
19
|
+
// or that whoever supplied it controls it. Trust decisions belong to the caller.
|
|
20
|
+
//
|
|
21
|
+
// Lives here rather than in lib/tools.js so the pure modules that need it (lib/oauth/outlook-identity.js)
|
|
22
|
+
// do not have to require tools, which pulls in settings and a Redis connection. lib/tools.js re-exports
|
|
23
|
+
// this function, so every existing caller is unaffected.
|
|
24
|
+
function isEmail(str) {
|
|
25
|
+
const { error, value } = emailSchema.validate({ email: str }, validateOptions);
|
|
26
|
+
|
|
27
|
+
if (error) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return value.email;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = { isEmail };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Lives here rather than in lib/tools.js so that pure modules can use it: tools.js opens Redis,
|
|
4
|
+
// which hangs a unit test that only wants to parse a message. tools.js re-exports it, so the
|
|
5
|
+
// existing `require('../tools')` consumers are unaffected.
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Converts a kebab-case header name into the camelCase key used in payloads,
|
|
9
|
+
* eg. "final-recipient" into "finalRecipient"
|
|
10
|
+
* @param {String} key Header name
|
|
11
|
+
* @returns {String} camelCased key
|
|
12
|
+
*/
|
|
13
|
+
function toCamelCase(key) {
|
|
14
|
+
return key.replace(/-(.)/g, (m, c) => c.toUpperCase());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = { toCamelCase };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Owns the webhook egress policy: where it is read from, what "off" means, and the two forms the
|
|
4
|
+
// rest of the system consumes it in. Previously each consumer resolved the environment variable
|
|
5
|
+
// itself and re-derived the off-switch, which meant the pre-check and the connect-time binding
|
|
6
|
+
// could disagree about what was configured - the same split-brain the binding exists to prevent.
|
|
7
|
+
|
|
8
|
+
const { readEnvValue } = require('./read-env-value');
|
|
9
|
+
const { assertAllowedUrl, createEgressLookup, normalizePolicy, POLICY_OFF } = require('./egress-filter');
|
|
10
|
+
|
|
11
|
+
// Which destinations webhook deliveries may reach. An account-scoped API token can set both the
|
|
12
|
+
// webhook URL and its custom headers, so without this the least-privileged credential in the
|
|
13
|
+
// system can aim EmailEngine at anything its host can route to. Defaults to blocking the
|
|
14
|
+
// link-local range (cloud instance metadata); `private` also blocks RFC1918 and friends, `off`
|
|
15
|
+
// disables the check and restores redirect following. See lib/egress-filter.js
|
|
16
|
+
const WEBHOOK_EGRESS_POLICY = normalizePolicy(readEnvValue('EENGINE_WEBHOOK_EGRESS_POLICY'));
|
|
17
|
+
|
|
18
|
+
const policyEnabled = WEBHOOK_EGRESS_POLICY !== POLICY_OFF;
|
|
19
|
+
|
|
20
|
+
// Built once rather than per delivery. Null when the policy is off, which is also what tells
|
|
21
|
+
// sendWebhookRequest() to keep following redirects.
|
|
22
|
+
const validateWebhookTarget = policyEnabled ? target => assertAllowedUrl(target, { policy: WEBHOOK_EGRESS_POLICY }) : null;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Builds the connect-time half of the guard, for use as an undici Agent's `connect.lookup`.
|
|
26
|
+
*
|
|
27
|
+
* @returns {Function|null} A lookup enforcing the policy, or null when the policy is off
|
|
28
|
+
*/
|
|
29
|
+
function createWebhookLookup() {
|
|
30
|
+
return policyEnabled ? createEgressLookup(WEBHOOK_EGRESS_POLICY) : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = {
|
|
34
|
+
WEBHOOK_EGRESS_POLICY,
|
|
35
|
+
validateWebhookTarget,
|
|
36
|
+
createWebhookLookup
|
|
37
|
+
};
|
package/lib/webhooks.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { randomUUID: uuid } = require('crypto');
|
|
4
4
|
const { redis, notifyQueue } = require('./db');
|
|
5
|
-
const msgpack = require('
|
|
5
|
+
const msgpack = require('./msgpack');
|
|
6
6
|
const logger = require('./logger');
|
|
7
7
|
const { REDIS_PREFIX, MESSAGE_NEW_NOTIFY } = require('./consts');
|
|
8
8
|
const { SubScript } = require('./sub-script');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "emailengine-app",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.78.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"productTitle": "EmailEngine",
|
|
6
6
|
"description": "Email Sync Engine",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
},
|
|
51
51
|
"homepage": "https://emailengine.app/",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@bull-board/api": "8.
|
|
54
|
-
"@bull-board/hapi": "8.
|
|
53
|
+
"@bull-board/api": "8.6.0",
|
|
54
|
+
"@bull-board/hapi": "8.6.0",
|
|
55
55
|
"@elastic/elasticsearch": "8.15.3",
|
|
56
56
|
"@hapi/accept": "6.0.3",
|
|
57
57
|
"@hapi/bell": "13.1.0",
|
|
@@ -61,28 +61,29 @@
|
|
|
61
61
|
"@hapi/hapi": "21.4.10",
|
|
62
62
|
"@hapi/inert": "7.1.2",
|
|
63
63
|
"@hapi/vision": "7.0.3",
|
|
64
|
+
"@msgpack/msgpack": "3.1.3",
|
|
64
65
|
"@phc/pbkdf2": "1.1.14",
|
|
65
66
|
"@postalsys/bounce-classifier": "3.0.0",
|
|
66
|
-
"@postalsys/certs": "1.0.
|
|
67
|
+
"@postalsys/certs": "1.0.17",
|
|
67
68
|
"@postalsys/ee-client": "1.7.0",
|
|
68
|
-
"@postalsys/email-ai-tools": "1.13.
|
|
69
|
-
"@postalsys/email-content": "0.1.
|
|
70
|
-
"@postalsys/email-text-tools": "2.4.
|
|
69
|
+
"@postalsys/email-ai-tools": "1.13.17",
|
|
70
|
+
"@postalsys/email-content": "0.1.3",
|
|
71
|
+
"@postalsys/email-text-tools": "2.4.12",
|
|
71
72
|
"@postalsys/gettext": "4.1.1",
|
|
72
73
|
"@postalsys/joi-messages": "1.0.5",
|
|
73
|
-
"@postalsys/templates": "2.0.
|
|
74
|
-
"@sentry/node": "10.
|
|
74
|
+
"@postalsys/templates": "2.0.2",
|
|
75
|
+
"@sentry/node": "10.70.0",
|
|
75
76
|
"@simplewebauthn/browser": "13.3.0",
|
|
76
77
|
"@simplewebauthn/server": "13.3.2",
|
|
77
|
-
"@zone-eu/mailsplit": "5.4.
|
|
78
|
+
"@zone-eu/mailsplit": "5.4.15",
|
|
78
79
|
"@zone-eu/wild-config": "1.7.6",
|
|
79
80
|
"ace-builds": "1.44.0",
|
|
80
|
-
"base32.js": "0.1.0",
|
|
81
81
|
"bullmq": "5.81.3",
|
|
82
82
|
"compare-versions": "6.1.1",
|
|
83
83
|
"dotenv": "17.4.2",
|
|
84
84
|
"encoding-japanese": "2.2.0",
|
|
85
85
|
"exponential-backoff": "3.1.3",
|
|
86
|
+
"fast-xml-parser": "5.10.1",
|
|
86
87
|
"gettext-parser": "7.0.1",
|
|
87
88
|
"handlebars": "4.7.9",
|
|
88
89
|
"hapi-auth-bearer-token": "8.0.0",
|
|
@@ -91,33 +92,30 @@
|
|
|
91
92
|
"html-to-text": "10.0.0",
|
|
92
93
|
"ical.js": "1.5.0",
|
|
93
94
|
"iconv-lite": "0.7.3",
|
|
94
|
-
"imapflow": "1.
|
|
95
|
+
"imapflow": "1.7.0",
|
|
95
96
|
"ioredfour": "1.4.2",
|
|
96
97
|
"ioredis": "5.11.1",
|
|
97
|
-
"ipaddr.js": "2.
|
|
98
|
+
"ipaddr.js": "2.5.0",
|
|
98
99
|
"joi": "18.2.3",
|
|
99
100
|
"libbase64": "1.3.0",
|
|
100
|
-
"libmime": "5.4.
|
|
101
|
+
"libmime": "5.4.2",
|
|
101
102
|
"libqp": "2.1.1",
|
|
102
|
-
"mailparser": "3.9.
|
|
103
|
+
"mailparser": "3.9.15",
|
|
103
104
|
"marked": "15.0.12",
|
|
104
105
|
"minimist": "1.2.8",
|
|
105
|
-
"msgpack5": "6.0.2",
|
|
106
106
|
"murmurhash": "2.0.1",
|
|
107
|
-
"nanoid": "3.3.
|
|
108
|
-
"nodemailer": "9.0.
|
|
107
|
+
"nanoid": "3.3.18",
|
|
108
|
+
"nodemailer": "9.0.5",
|
|
109
109
|
"pino": "10.3.1",
|
|
110
110
|
"prom-client": "15.1.3",
|
|
111
111
|
"psl": "1.15.0",
|
|
112
|
-
"pubface": "1.1.
|
|
112
|
+
"pubface": "1.1.6",
|
|
113
113
|
"punycode.js": "2.3.1",
|
|
114
114
|
"qrcode": "1.5.4",
|
|
115
|
-
"smtp-server": "3.19.
|
|
115
|
+
"smtp-server": "3.19.3",
|
|
116
116
|
"socks": "2.8.9",
|
|
117
|
-
"speakeasy": "2.0.0",
|
|
118
117
|
"timezones-list": "3.1.0",
|
|
119
|
-
"undici": "7.29.0"
|
|
120
|
-
"xml2js": "0.6.2"
|
|
118
|
+
"undici": "7.29.0"
|
|
121
119
|
},
|
|
122
120
|
"devDependencies": {
|
|
123
121
|
"@eslint/js": "10.0.1",
|
|
@@ -129,7 +127,7 @@
|
|
|
129
127
|
"acorn-walk": "8.3.5",
|
|
130
128
|
"chai": "4.5.0",
|
|
131
129
|
"eerawlog": "1.5.5",
|
|
132
|
-
"eslint": "10.8.
|
|
130
|
+
"eslint": "10.8.1",
|
|
133
131
|
"flyonui": "2.4.1",
|
|
134
132
|
"pino-pretty": "13.1.3",
|
|
135
133
|
"prettier": "3.9.6",
|