emailengine-app 2.79.8 → 2.80.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/dependabot.yml +22 -0
- package/.github/workflows/test.yml +39 -0
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +69 -0
- package/DOCKER_DEPLOYMENT.md +6 -7
- package/Dockerfile +35 -11
- package/config/default.toml +7 -2
- package/copy-static-files.sh +23 -5
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +43 -0
- package/lib/account/account-state.js +62 -0
- package/lib/account.js +60 -3
- package/lib/api-routes/account-routes.js +20 -0
- package/lib/api-routes/bull-board-routes.js +3 -2
- package/lib/api-routes/index.js +1 -1
- package/lib/api-routes/route-helpers.js +8 -0
- package/lib/api-routes/settings-routes.js +17 -2
- package/lib/auth-token.js +73 -2
- package/lib/autodetect-imap-settings.js +379 -69
- package/lib/cert-handler.js +62 -0
- package/lib/consts.js +58 -7
- package/lib/db.js +12 -0
- package/lib/egress-fetch.js +145 -0
- package/lib/email-client/base-client.js +234 -66
- package/lib/email-client/credential-errors.js +118 -0
- package/lib/email-client/gmail/gmail-api.js +2 -1
- package/lib/email-client/gmail-client.js +70 -64
- package/lib/email-client/imap/connection-errors.js +52 -0
- package/lib/email-client/imap/listing-diff.js +47 -6
- package/lib/email-client/imap/mailbox.js +457 -379
- package/lib/email-client/imap/subconnection.js +15 -11
- package/lib/email-client/imap/sync-operations.js +46 -59
- package/lib/email-client/imap-client.js +136 -95
- package/lib/email-client/message-builder.js +11 -11
- package/lib/email-client/outlook/graph-api.js +2 -1
- package/lib/email-client/outlook-client.js +219 -106
- package/lib/export.js +35 -2
- package/lib/handlebars-helpers.js +129 -0
- package/lib/imap-proxy-auth.js +96 -21
- package/lib/imapproxy/imap-core/README.md +1 -0
- package/lib/imapproxy/imap-core/lib/tls-options.js +5 -46
- package/lib/imapproxy/imap-server.js +56 -66
- package/lib/lua/h-del-if-equals.lua +39 -0
- package/lib/lua/h-set-if-equals.lua +39 -0
- package/lib/openapi/index.js +3 -0
- package/lib/outbox.js +28 -3
- package/lib/rate-limit.js +23 -4
- package/lib/routes-ui.js +4 -34
- package/lib/schemas.js +42 -3
- package/lib/security-headers.js +411 -0
- package/lib/sentry.js +36 -4
- package/lib/smtp-auth.js +86 -7
- package/lib/tls/context.js +376 -0
- package/lib/tls/der.js +223 -0
- package/lib/tls/provision.js +555 -0
- package/lib/tls/self-signed.js +282 -0
- package/lib/tls/status.js +431 -0
- package/lib/tls/store.js +666 -0
- package/lib/tools.js +337 -147
- package/lib/ui-routes/account-routes.js +47 -33
- package/lib/ui-routes/admin-config-routes.js +22 -1
- package/lib/ui-routes/auth-routes.js +16 -1
- package/lib/ui-routes/export-routes.js +4 -0
- package/lib/ui-routes/internals-routes.js +3 -5
- package/lib/ui-routes/mcp-consent-routes.js +7 -0
- package/lib/ui-routes/network-config-routes.js +58 -48
- package/lib/ui-routes/route-helpers.js +24 -8
- package/lib/ui-routes/smtp-test-routes.js +7 -0
- package/lib/ui-routes/tls-config-routes.js +581 -0
- package/lib/utils/mailbox-path.js +51 -0
- package/lib/utils/severity.js +31 -0
- package/lib/webhook-egress.js +5 -0
- package/package.json +21 -24
- package/sbom.json +1 -1
- package/server.js +53 -36
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +11 -0
- package/static/js/ace/css/ace.css +1462 -0
- package/static/js/ace/css/kuroir-1.png +0 -0
- package/static/js/ace/css/kuroir-2.png +0 -0
- package/static/js/ace/css/main-1.png +0 -0
- package/static/js/ace/css/main-10.svg +4 -0
- package/static/js/ace/css/main-11.svg +5 -0
- package/static/js/ace/css/main-12.svg +4 -0
- package/static/js/ace/css/main-13.png +0 -0
- package/static/js/ace/css/main-14.png +0 -0
- package/static/js/ace/css/main-15.png +0 -0
- package/static/js/ace/css/main-16.png +0 -0
- package/static/js/ace/css/main-17.png +0 -0
- package/static/js/ace/css/main-18.png +0 -0
- package/static/js/ace/css/main-19.png +0 -0
- package/static/js/ace/css/main-2.png +0 -0
- package/static/js/ace/css/main-20.png +0 -0
- package/static/js/ace/css/main-21.png +0 -0
- package/static/js/ace/css/main-22.png +0 -0
- package/static/js/ace/css/main-23.png +0 -0
- package/static/js/ace/css/main-24.png +0 -0
- package/static/js/ace/css/main-25.svg +1 -0
- package/static/js/ace/css/main-26.png +0 -0
- package/static/js/ace/css/main-3.png +0 -0
- package/static/js/ace/css/main-4.png +0 -0
- package/static/js/ace/css/main-5.svg +7 -0
- package/static/js/ace/css/main-6.svg +9 -0
- package/static/js/ace/css/main-7.svg +7 -0
- package/static/js/ace/css/main-8.svg +9 -0
- package/static/js/ace/css/main-9.svg +6 -0
- package/static/js/ace/css/theme/kuroir.css +78 -0
- package/static/js/ace/css/theme/tomorrow_night.css +128 -0
- package/static/js/ace/css/theme/tomorrow_night_eighties.css +128 -0
- package/static/js/ace/css/theme/xcode.css +106 -0
- package/static/js/ace/css/tomorrow_night-1.png +0 -0
- package/static/js/ace/css/tomorrow_night-2.png +0 -0
- package/static/js/ace/css/tomorrow_night_eighties-1.png +0 -0
- package/static/js/ace/css/tomorrow_night_eighties-2.png +0 -0
- package/static/js/ace/css/xcode-1.png +0 -0
- package/static/js/ace/css/xcode-2.png +0 -0
- package/static/js/app.js +34 -0
- package/static/js/ee-client.js +256 -102
- package/static/js/public.js +13 -2
- package/static/js/ui.js +40 -25
- package/static/licenses.html +393 -1282
- package/static/vendor/simplewebauthn/browser.min.js +2 -2
- package/translations/messages.pot +203 -157
- package/views/account/login-redirect.hbs +22 -0
- package/views/accounts/account.hbs +15 -37
- package/views/accounts/browse.hbs +3 -1
- package/views/accounts/edit.hbs +1 -1
- package/views/accounts/register/imap-server.hbs +1 -1
- package/views/config/ai.hbs +1 -1
- package/views/config/branding.hbs +2 -2
- package/views/config/document-store/chat.hbs +1 -1
- package/views/config/document-store/index.hbs +1 -1
- package/views/config/imap-proxy.hbs +1 -4
- package/views/config/license.hbs +1 -1
- package/views/config/mcp.hbs +1 -1
- package/views/config/network.hbs +14 -16
- package/views/config/oauth/app.hbs +2 -2
- package/views/config/service.hbs +1 -1
- package/views/config/smtp.hbs +1 -4
- package/views/config/tls-upload.hbs +81 -0
- package/views/config/tls.hbs +492 -0
- package/views/config/webhooks.hbs +2 -2
- package/views/error.hbs +4 -2
- package/views/internals/index.hbs +1 -1
- package/views/layout/app.hbs +3 -11
- package/views/mcp/authorize.hbs +1 -1
- package/views/partials/ace_assets.hbs +13 -0
- package/views/partials/add_account_modal.hbs +1 -1
- package/views/partials/address_list.hbs +4 -4
- package/views/partials/filter_editor_js.hbs +2 -2
- package/views/partials/gateway_js.hbs +1 -1
- package/views/partials/oauth_form.hbs +1 -1
- package/views/partials/public_theme_init.hbs +1 -1
- package/views/partials/side_menu.hbs +1 -0
- package/views/partials/template_form.hbs +2 -2
- package/views/partials/test_send.hbs +7 -4
- package/views/partials/theme_init.hbs +1 -1
- package/views/partials/tls_security_card.hbs +25 -53
- package/views/partials/ui/alert-banner.hbs +3 -2
- package/views/partials/ui/badge.hbs +6 -2
- package/views/partials/ui/btn.hbs +5 -2
- package/views/partials/ui/details.hbs +2 -2
- package/views/partials/webhooks_editor_functions.hbs +1 -1
- package/views/reference/redirect.hbs +1 -1
- package/views/templates/template.hbs +2 -2
- package/views/tokens/new.hbs +1 -1
- package/views/unsubscribe.hbs +1 -1
- package/views/webhooks/webhook.hbs +2 -2
- package/workers/api.js +131 -242
- package/workers/export.js +1 -5
- package/workers/imap-proxy.js +4 -1
- package/workers/imap.js +1 -3
- package/workers/smtp.js +59 -83
- package/workers/submit.js +6 -12
- package/workers/webhooks.js +6 -17
- package/static/front/EmailEngine_logo_horiz.png +0 -0
- package/static/front/EmailEngine_logo_vert.png +0 -0
- package/static/front/index.html +0 -57
- package/static/front/logo.png +0 -0
- package/static/vendor/handlebars/handlebars.min-v4.7.9.js +0 -29
- package/views/partials/tls_security_js.hbs +0 -64
- package/views/partials/tls_security_modal.hbs +0 -22
|
@@ -224,6 +224,14 @@ function maskSecrets(entry) {
|
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
+
// A failed delivery records the target it was aimed at on the webhook route, the account or
|
|
228
|
+
// the settings. The worker stores it with the credentials already stripped, but a flag written
|
|
229
|
+
// by an older release still carries the raw URL - the same one field over from the masked
|
|
230
|
+
// `targetUrl` / `webhooks` beside it, readable by any token that can list webhook routes.
|
|
231
|
+
if (entry.webhookErrorFlag && typeof entry.webhookErrorFlag === 'object' && entry.webhookErrorFlag.url) {
|
|
232
|
+
entry.webhookErrorFlag.url = maskUrlPassword(entry.webhookErrorFlag.url);
|
|
233
|
+
}
|
|
234
|
+
|
|
227
235
|
return entry;
|
|
228
236
|
}
|
|
229
237
|
|
|
@@ -4,7 +4,8 @@ const Joi = require('joi');
|
|
|
4
4
|
const { QUEUES_BY_NAME } = require('../db');
|
|
5
5
|
const settings = require('../settings');
|
|
6
6
|
const consts = require('../consts');
|
|
7
|
-
const { failAction } = require('../tools');
|
|
7
|
+
const { failAction, maybeReloadTlsCertificates, TLS_MATERIAL_SETTINGS } = require('../tools');
|
|
8
|
+
const { tlsSettingChanged } = require('../tls/store');
|
|
8
9
|
const { queueStats } = require('../queue-stats');
|
|
9
10
|
const Boom = require('@hapi/boom');
|
|
10
11
|
const { handleError, maskSecrets, containsMaskedSecret, isMaskedRoundTrip, MASKED } = require('./route-helpers');
|
|
@@ -32,7 +33,7 @@ settingsOutputSchema.eventTypes = Joi.array()
|
|
|
32
33
|
.label('EventTypesList');
|
|
33
34
|
|
|
34
35
|
async function init(args) {
|
|
35
|
-
const { server, notify, CORS_CONFIG } = args;
|
|
36
|
+
const { server, call, notify, CORS_CONFIG } = args;
|
|
36
37
|
|
|
37
38
|
server.route({
|
|
38
39
|
method: 'GET',
|
|
@@ -117,6 +118,8 @@ async function init(args) {
|
|
|
117
118
|
|
|
118
119
|
async handler(request) {
|
|
119
120
|
let applied = {};
|
|
121
|
+
// Only the keys whose value actually changed, unlike `applied` - see tlsSettingChanged()
|
|
122
|
+
let tlsChanged = [];
|
|
120
123
|
try {
|
|
121
124
|
for (let key of Object.keys(request.payload)) {
|
|
122
125
|
let value = request.payload[key];
|
|
@@ -141,6 +144,10 @@ async function init(args) {
|
|
|
141
144
|
await settings.clear('webhookErrorFlag');
|
|
142
145
|
}
|
|
143
146
|
|
|
147
|
+
if (TLS_MATERIAL_SETTINGS.includes(key) && tlsSettingChanged(key, await settings.get(key), value)) {
|
|
148
|
+
tlsChanged.push(key);
|
|
149
|
+
}
|
|
150
|
+
|
|
144
151
|
await settings.set(key, value);
|
|
145
152
|
applied[key] = value;
|
|
146
153
|
}
|
|
@@ -154,6 +161,14 @@ async function init(args) {
|
|
|
154
161
|
// key fails, the earlier ones are already stored and the other workers still have
|
|
155
162
|
// to reload for them, or they keep running on settings Redis no longer holds.
|
|
156
163
|
notify('settings', applied);
|
|
164
|
+
|
|
165
|
+
// What a listener serves is not carried by that broadcast, and no worker acts on
|
|
166
|
+
// it. Until this was here, an instance switched to "self-signed only" through the
|
|
167
|
+
// API went on offering its Let's Encrypt certificate, and a name added to
|
|
168
|
+
// tlsHostnames was answered with the certificate that predates it, until something
|
|
169
|
+
// restarted the workers. Each command reports its own failure, so this cannot mask
|
|
170
|
+
// the error being thrown out of the catch.
|
|
171
|
+
await maybeReloadTlsCertificates(call, request.logger, tlsChanged, { action: 'settings' });
|
|
157
172
|
}
|
|
158
173
|
|
|
159
174
|
return { updated: Object.keys(applied) };
|
package/lib/auth-token.js
CHANGED
|
@@ -12,6 +12,7 @@ const tokenPermissions = require('./token-permissions');
|
|
|
12
12
|
const tokenAuditLog = require('./token-audit-log');
|
|
13
13
|
const { SURFACE_GRANTS } = require('./api-routes/permission-map');
|
|
14
14
|
const { matchIp } = require('./utils/network');
|
|
15
|
+
const { checkRateLimit, peekRateLimit } = require('./rate-limit');
|
|
15
16
|
|
|
16
17
|
// Reason-specific denial messages, shared verbatim by both auth handlers. The
|
|
17
18
|
// generic "failed to authenticate" fallback and any protocol-specific error
|
|
@@ -20,9 +21,72 @@ const REASON_MESSAGES = {
|
|
|
20
21
|
username: 'Access denied, invalid username',
|
|
21
22
|
scope: 'Access denied, invalid scope',
|
|
22
23
|
ip: 'Access denied, traffic not accepted from this IP',
|
|
23
|
-
permissions: 'Access denied, token permissions do not allow this'
|
|
24
|
+
permissions: 'Access denied, token permissions do not allow this',
|
|
25
|
+
limited: 'Too many failed authentication attempts, try again later'
|
|
24
26
|
};
|
|
25
27
|
|
|
28
|
+
// Failed logins a client address may accumulate against one username before the surface stops
|
|
29
|
+
// answering that pair for the rest of the window. The guard exists for the shared server
|
|
30
|
+
// password, which is operator-chosen with no entropy requirement and was guessable at the full
|
|
31
|
+
// speed of a Redis lookup; the 64-hex API tokens are not guessable at any rate this allows.
|
|
32
|
+
//
|
|
33
|
+
// Keyed on address AND username on purpose. The submission surfaces are typically driven by one
|
|
34
|
+
// application host sending for many accounts, and a single stale credential in that host's
|
|
35
|
+
// configuration must not lock its other accounts out. The username buys an attacker nothing:
|
|
36
|
+
// a guess needs a real account id either way, and each id they know only adds one more budget.
|
|
37
|
+
//
|
|
38
|
+
// Only failures count. A busy sender authenticating on every connection would exhaust an
|
|
39
|
+
// attempt-based budget by itself.
|
|
40
|
+
const AUTH_FAILURE_LIMIT = 20;
|
|
41
|
+
const AUTH_FAILURE_WINDOW = 5 * 60; // seconds
|
|
42
|
+
|
|
43
|
+
const authFailureKey = (remoteAddress, account) => `auth:fail:${remoteAddress || 'unknown'}:${account || ''}`;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Runs a credential check under the client's failed-login budget.
|
|
47
|
+
*
|
|
48
|
+
* Looks before the attempt (a peek, so an accepted login spends nothing) and records only a
|
|
49
|
+
* refusal. Everything `attempt` throws counts as one: the caller decides what belongs inside
|
|
50
|
+
* the budget by what it puts in the function, so a refusal that is about the account rather
|
|
51
|
+
* than the credential (an API-only account on the IMAP proxy) is left outside it.
|
|
52
|
+
*
|
|
53
|
+
* @param {Object} client
|
|
54
|
+
* @param {String} client.remoteAddress - client IP
|
|
55
|
+
* @param {String} client.account - username the client is authenticating as
|
|
56
|
+
* @param {Function} attempt - async () => result; the credential check
|
|
57
|
+
* @param {Function} limitedError - () => Error; the protocol-specific refusal for a spent budget
|
|
58
|
+
* @returns {Promise<*>} whatever `attempt` resolves with
|
|
59
|
+
*/
|
|
60
|
+
async function withAuthFailureBudget({ remoteAddress, account }, attempt, limitedError) {
|
|
61
|
+
const key = authFailureKey(remoteAddress, account);
|
|
62
|
+
|
|
63
|
+
let limit = await peekRateLimit(key, AUTH_FAILURE_LIMIT, AUTH_FAILURE_WINDOW);
|
|
64
|
+
if (!limit.success) {
|
|
65
|
+
logger.warn({
|
|
66
|
+
msg: 'Refusing authentication attempt, failure limit reached',
|
|
67
|
+
remoteAddress,
|
|
68
|
+
account,
|
|
69
|
+
count: limit.count,
|
|
70
|
+
allowed: limit.allowed,
|
|
71
|
+
ttlReset: limit.ttlReset
|
|
72
|
+
});
|
|
73
|
+
throw limitedError();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
return await attempt();
|
|
78
|
+
} catch (err) {
|
|
79
|
+
// Never masks the refusal: a counter that could not be written is logged, and the
|
|
80
|
+
// client still gets the error the attempt raised
|
|
81
|
+
try {
|
|
82
|
+
await checkRateLimit(key, 1, AUTH_FAILURE_LIMIT, AUTH_FAILURE_WINDOW);
|
|
83
|
+
} catch (recordErr) {
|
|
84
|
+
logger.error({ msg: 'Failed to record authentication failure', remoteAddress, account, err: recordErr });
|
|
85
|
+
}
|
|
86
|
+
throw err;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
26
90
|
/**
|
|
27
91
|
* Validates a 64-char hex API token supplied as a server password.
|
|
28
92
|
*
|
|
@@ -152,4 +216,11 @@ async function validateAuthToken({ password, account, requiredScope, remoteAddre
|
|
|
152
216
|
return { authenticated: true, reason: null };
|
|
153
217
|
}
|
|
154
218
|
|
|
155
|
-
module.exports = {
|
|
219
|
+
module.exports = {
|
|
220
|
+
validateAuthToken,
|
|
221
|
+
withAuthFailureBudget,
|
|
222
|
+
authFailureKey,
|
|
223
|
+
AUTH_FAILURE_LIMIT,
|
|
224
|
+
AUTH_FAILURE_WINDOW,
|
|
225
|
+
REASON_MESSAGES
|
|
226
|
+
};
|