emailengine-app 2.79.8 → 2.79.9
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 +20 -0
- package/DOCKER_DEPLOYMENT.md +6 -7
- package/Dockerfile +35 -11
- package/config/default.toml +2 -1
- package/copy-static-files.sh +23 -5
- package/data/google-crawlers.json +1 -1
- package/lib/account.js +26 -1
- package/lib/api-routes/bull-board-routes.js +3 -2
- package/lib/api-routes/route-helpers.js +8 -0
- package/lib/auth-token.js +73 -2
- package/lib/autodetect-imap-settings.js +33 -25
- package/lib/consts.js +8 -1
- package/lib/egress-fetch.js +133 -0
- package/lib/export.js +35 -2
- package/lib/handlebars-helpers.js +129 -0
- package/lib/imap-proxy-auth.js +41 -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 +9 -10
- package/lib/openapi/index.js +3 -0
- package/lib/outbox.js +28 -3
- package/lib/rate-limit.js +23 -4
- package/lib/schemas.js +10 -3
- package/lib/security-headers.js +396 -0
- package/lib/sentry.js +36 -4
- package/lib/smtp-auth.js +86 -7
- package/lib/tools.js +265 -120
- package/lib/ui-routes/account-routes.js +4 -3
- package/lib/ui-routes/export-routes.js +4 -0
- package/lib/ui-routes/mcp-consent-routes.js +7 -0
- package/lib/ui-routes/network-config-routes.js +4 -3
- package/lib/ui-routes/route-helpers.js +24 -8
- package/lib/ui-routes/smtp-test-routes.js +7 -0
- package/lib/webhook-egress.js +5 -0
- package/package.json +21 -24
- package/sbom.json +1 -1
- package/server.js +37 -36
- 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/ee-client.js +256 -102
- package/static/js/public.js +7 -0
- package/static/js/ui.js +32 -0
- package/static/licenses.html +331 -291
- package/static/vendor/simplewebauthn/browser.min.js +2 -2
- package/translations/messages.pot +203 -157
- 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 -1
- 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 -1
- 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/template_form.hbs +2 -2
- package/views/partials/test_send.hbs +7 -4
- package/views/partials/theme_init.hbs +1 -1
- 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 +42 -112
- package/workers/export.js +1 -5
- package/workers/imap.js +1 -3
- package/workers/smtp.js +12 -43
- 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/workers/api.js
CHANGED
|
@@ -35,7 +35,7 @@ const {
|
|
|
35
35
|
hasEnvValue,
|
|
36
36
|
getBoolean,
|
|
37
37
|
loadTlsConfig,
|
|
38
|
-
|
|
38
|
+
httpAgent,
|
|
39
39
|
resolveOAuthErrorStatus,
|
|
40
40
|
constantTimeEqual,
|
|
41
41
|
verifyServiceSignature,
|
|
@@ -117,6 +117,8 @@ const {
|
|
|
117
117
|
|
|
118
118
|
const registerApiRoutes = require('../lib/api-routes');
|
|
119
119
|
const bullBoardRoutes = require('../lib/api-routes/bull-board-routes');
|
|
120
|
+
const { securityHeadersExt, attachSecurityContext, isAdminPath, isMachineRoute, isSecureOrigin, CSP_MODES } = require('../lib/security-headers');
|
|
121
|
+
const { registerHandlebarsHelpers } = require('../lib/handlebars-helpers');
|
|
120
122
|
|
|
121
123
|
const {
|
|
122
124
|
imapSchema,
|
|
@@ -203,6 +205,16 @@ const API_TLS = hasEnvValue('EENGINE_API_TLS') ? getBoolean(readEnvValue('EENGIN
|
|
|
203
205
|
// Merge TLS settings from config params and environment
|
|
204
206
|
loadTlsConfig(API_TLS, 'EENGINE_API_TLS_');
|
|
205
207
|
|
|
208
|
+
// How the Content-Security-Policy is delivered: enforce (default), report-only, or off.
|
|
209
|
+
// An unknown value falls back to enforce, and says so once
|
|
210
|
+
const CSP_MODE_CONFIGURED = String(hasEnvValue('EENGINE_CSP_MODE') ? readEnvValue('EENGINE_CSP_MODE') : config.api.cspMode || '')
|
|
211
|
+
.trim()
|
|
212
|
+
.toLowerCase();
|
|
213
|
+
const CSP_MODE = CSP_MODES.includes(CSP_MODE_CONFIGURED) ? CSP_MODE_CONFIGURED : 'enforce';
|
|
214
|
+
if (CSP_MODE_CONFIGURED && CSP_MODE_CONFIGURED !== CSP_MODE) {
|
|
215
|
+
logger.warn({ msg: 'Unknown Content-Security-Policy mode, enforcing the policy', configured: CSP_MODE_CONFIGURED, cspMode: CSP_MODE });
|
|
216
|
+
}
|
|
217
|
+
|
|
206
218
|
// Per-worker thread metadata. With multiple API workers (EENGINE_WORKERS_API > 1) the
|
|
207
219
|
// main thread assigns each one an index and whether to bind with SO_REUSEPORT. Only
|
|
208
220
|
// worker 0 runs singleton maintenance tasks (e.g. TLS certificate renewal).
|
|
@@ -460,9 +472,7 @@ parentPort.on('message', message => {
|
|
|
460
472
|
}
|
|
461
473
|
|
|
462
474
|
if (message && message.cmd === 'settings') {
|
|
463
|
-
//
|
|
464
|
-
maybeReloadHttpProxyAgent(message.data);
|
|
465
|
-
// ...and the API reference's memoized serviceUrl, which its code samples embed
|
|
475
|
+
// the API reference memoizes serviceUrl, which its code samples embed
|
|
466
476
|
clearServiceUrlCache();
|
|
467
477
|
|
|
468
478
|
// The first admin password is saved by whichever API worker served the form, and only
|
|
@@ -483,98 +493,7 @@ const init = async () => {
|
|
|
483
493
|
|
|
484
494
|
gt.setLocale((await settings.get('locale')) || 'en');
|
|
485
495
|
|
|
486
|
-
handlebars
|
|
487
|
-
let params = args.slice(1, args.length - 1);
|
|
488
|
-
|
|
489
|
-
let locale = params.shift();
|
|
490
|
-
|
|
491
|
-
let localGt = locale ? gt.useLocale(locale) : gt;
|
|
492
|
-
|
|
493
|
-
let translated = localGt.gettext(args[0]);
|
|
494
|
-
if (params.length) {
|
|
495
|
-
translated = util.format(translated, ...params);
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
return new handlebars.SafeString(translated);
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
// HTML-escape a value for safe interpolation into an otherwise-unescaped context - e.g. a
|
|
502
|
-
// dynamic `%s` argument to the SafeString-returning `_` helper. Returns a plain string so
|
|
503
|
-
// the surrounding markup stays live while the value itself is entity-escaped.
|
|
504
|
-
handlebars.registerHelper('escapeHtml', value => handlebars.escapeExpression(value));
|
|
505
|
-
|
|
506
|
-
// Translate Bootstrap-era color names emitted by server code (flash types,
|
|
507
|
-
// systemAlerts levels) into the FlyonUI color vocabulary used by the admin
|
|
508
|
-
// theme, so templates interpolate a single closed set of class suffixes
|
|
509
|
-
// (which the stylesheet safelists). Single translation point - producers
|
|
510
|
-
// keep using "danger" etc.
|
|
511
|
-
handlebars.registerHelper('eeColor', value => (value === 'danger' ? 'error' : value || 'neutral'));
|
|
512
|
-
|
|
513
|
-
// Percent-encode a value for interpolation into a URL path segment. Handlebars escapes for
|
|
514
|
-
// HTML, which leaves "#", "/", "?" and "%" untouched - and an account ID is free text, so
|
|
515
|
-
// href="/admin/accounts/{{account}}" resolves somewhere else entirely for an ID carrying one.
|
|
516
|
-
handlebars.registerHelper('urlpart', value => encodeURIComponent(value === null || value === undefined ? '' : value));
|
|
517
|
-
|
|
518
|
-
// Join string fragments in subexpressions, e.g. building composed partial
|
|
519
|
-
// hash values: text=(concat "Up to " (formatInteger n locale) " lines")
|
|
520
|
-
handlebars.registerHelper('concat', (...args) => args.slice(0, -1).join(''));
|
|
521
|
-
|
|
522
|
-
// Ternary for subexpressions: placeholder=(when hasPass "set..." "")
|
|
523
|
-
handlebars.registerHelper('when', (cond, truthyValue, falsyValue) => (cond ? truthyValue : typeof falsyValue === 'string' ? falsyValue : ''));
|
|
524
|
-
|
|
525
|
-
handlebars.registerHelper('isodate', time => new Date(Number(time)).toISOString());
|
|
526
|
-
|
|
527
|
-
handlebars.registerHelper('ngettext', (msgid, plural, count) => util.format(gt.ngettext(msgid, plural, count), count));
|
|
528
|
-
|
|
529
|
-
handlebars.registerHelper('equals', function (compareVal, baseVal, options) {
|
|
530
|
-
if (baseVal === compareVal) {
|
|
531
|
-
return options.fn(this);
|
|
532
|
-
}
|
|
533
|
-
return options.inverse(this);
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
handlebars.registerHelper('inc', (nr, inc) => Number(nr) + Number(inc));
|
|
537
|
-
|
|
538
|
-
handlebars.registerHelper('json', payload => {
|
|
539
|
-
let res;
|
|
540
|
-
try {
|
|
541
|
-
res = typeof payload === 'undefined' ? 'undefined' : JSON.stringify(payload, false, 2);
|
|
542
|
-
} catch (err) {
|
|
543
|
-
res = util.inspect(payload, false, 4, false);
|
|
544
|
-
}
|
|
545
|
-
// SECURITY: return a plain string (NOT a SafeString) so Handlebars HTML-escapes the
|
|
546
|
-
// output. `payload` can carry attacker-controlled data (e.g. inbound email fields in
|
|
547
|
-
// webhook / pre-processing error logs); wrapping it in a SafeString allowed a stored
|
|
548
|
-
// XSS via a </textarea> breakout in the error-log views (security review H1). In the
|
|
549
|
-
// <textarea> render contexts this is display-identical (the browser decodes entities).
|
|
550
|
-
return res;
|
|
551
|
-
});
|
|
552
|
-
|
|
553
|
-
handlebars.registerHelper('lastVal', (value, separator) => {
|
|
554
|
-
separator = separator || '/';
|
|
555
|
-
|
|
556
|
-
let res = (value || '').toString().split(separator).pop();
|
|
557
|
-
|
|
558
|
-
return new handlebars.SafeString(res);
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
handlebars.registerHelper('formatInteger', (intVal, locale) => {
|
|
562
|
-
if (isNaN(intVal)) {
|
|
563
|
-
// ignore non-numbers
|
|
564
|
-
return intVal;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
locale = (locale || 'en_US').replace(/_/g, '-');
|
|
568
|
-
|
|
569
|
-
let formatter;
|
|
570
|
-
try {
|
|
571
|
-
formatter = new Intl.NumberFormat(locale, {});
|
|
572
|
-
} catch (err) {
|
|
573
|
-
formatter = new Intl.NumberFormat('en-US', {});
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
return formatter.format(intVal);
|
|
577
|
-
});
|
|
496
|
+
registerHandlebarsHelpers(handlebars, { gt });
|
|
578
497
|
|
|
579
498
|
// Base Hapi options shared by both the default and SO_REUSEPORT binding paths
|
|
580
499
|
const serverOptions = {
|
|
@@ -656,6 +575,9 @@ const init = async () => {
|
|
|
656
575
|
//directoryUrl: 'https://acme-staging-v02.api.letsencrypt.org/directory',
|
|
657
576
|
},
|
|
658
577
|
|
|
578
|
+
// long-lived client, see LiveDispatcher in lib/tools.js
|
|
579
|
+
dispatcher: httpAgent.live,
|
|
580
|
+
|
|
659
581
|
logger: logger.child({ sub: 'acme' }),
|
|
660
582
|
|
|
661
583
|
encryptFn: async value => {
|
|
@@ -805,7 +727,11 @@ const init = async () => {
|
|
|
805
727
|
|
|
806
728
|
// Both settings are needed on every request and neither depends on the other, so they are
|
|
807
729
|
// read in a single HMGET rather than two serialized round trips
|
|
808
|
-
let { enableApiProxy, disableTokens } = await settings.getMulti('enableApiProxy', 'disableTokens');
|
|
730
|
+
let { enableApiProxy, disableTokens, serviceUrl } = await settings.getMulti('enableApiProxy', 'disableTokens', 'serviceUrl');
|
|
731
|
+
|
|
732
|
+
// Before anything can render a view (the allowlist refusal below does), so the nonce
|
|
733
|
+
// the template stamps on its scripts is the one the response header carries
|
|
734
|
+
attachSecurityContext(request, { secureOrigin: isSecureOrigin(serviceUrl) });
|
|
809
735
|
|
|
810
736
|
// check if client IP is resolved from X-Forwarded-For or not
|
|
811
737
|
request.app.ip = resolveClientIp({
|
|
@@ -839,7 +765,7 @@ const init = async () => {
|
|
|
839
765
|
request.flash = async message => await flash(redis, request, message);
|
|
840
766
|
|
|
841
767
|
if (ADMIN_ACCESS_ADDRESSES && ADMIN_ACCESS_ADDRESSES.length) {
|
|
842
|
-
if (request.path
|
|
768
|
+
if (isAdminPath(request.path) && !matchIp(request.app.ip, ADMIN_ACCESS_ADDRESSES)) {
|
|
843
769
|
logger.info({
|
|
844
770
|
msg: 'Blocked access from unlisted IP address',
|
|
845
771
|
remoteAddress: request.app.ip,
|
|
@@ -1258,22 +1184,17 @@ const init = async () => {
|
|
|
1258
1184
|
await server.register(Cookie);
|
|
1259
1185
|
await server.register(Bell);
|
|
1260
1186
|
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
let serviceUrl = await settings.get('serviceUrl');
|
|
1264
|
-
if (serviceUrl) {
|
|
1265
|
-
let parsedUrl = new URL(serviceUrl);
|
|
1266
|
-
secureCookie = parsedUrl.protocol === 'https:';
|
|
1267
|
-
}
|
|
1268
|
-
} catch (err) {
|
|
1269
|
-
// skip
|
|
1270
|
-
}
|
|
1187
|
+
// the signal HSTS keys on too, so the cookies and the header agree on what "https" means
|
|
1188
|
+
let secureCookie = isSecureOrigin(await settings.get('serviceUrl'));
|
|
1271
1189
|
|
|
1272
1190
|
server.state('locale', {
|
|
1273
1191
|
ttl: null,
|
|
1274
1192
|
encoding: 'base64json',
|
|
1275
1193
|
clearInvalid: true,
|
|
1276
|
-
path: '/'
|
|
1194
|
+
path: '/',
|
|
1195
|
+
// Same signal as the session and CSRF cookies. hapi's default is Secure, which a browser
|
|
1196
|
+
// drops on a plain-http instance, so the chosen locale never stuck there
|
|
1197
|
+
isSecure: secureCookie
|
|
1277
1198
|
});
|
|
1278
1199
|
|
|
1279
1200
|
// The version an SSO login stamps into its session, so the checks that end a session later can
|
|
@@ -2940,7 +2861,7 @@ const init = async () => {
|
|
|
2940
2861
|
skip: (request /*, h*/) => {
|
|
2941
2862
|
let tags = (request.route && request.route.settings && request.route.settings.tags) || [];
|
|
2942
2863
|
|
|
2943
|
-
if (
|
|
2864
|
+
if (isMachineRoute(tags)) {
|
|
2944
2865
|
return true;
|
|
2945
2866
|
}
|
|
2946
2867
|
|
|
@@ -3164,6 +3085,8 @@ const init = async () => {
|
|
|
3164
3085
|
const isAuthenticated = !!(request.auth && request.auth.isAuthenticated);
|
|
3165
3086
|
|
|
3166
3087
|
return {
|
|
3088
|
+
// the per-request CSP nonce every inline <script> carries (lib/security-headers.js)
|
|
3089
|
+
cspNonce: request.app.cspNonce,
|
|
3167
3090
|
pageBrandName: pageBrandName || 'EmailEngine',
|
|
3168
3091
|
values: request.payload || {},
|
|
3169
3092
|
errors: (request.error && request.error.details) || {},
|
|
@@ -3249,7 +3172,9 @@ const init = async () => {
|
|
|
3249
3172
|
const routeTags = (request.route && request.route.settings && request.route.settings.tags) || [];
|
|
3250
3173
|
|
|
3251
3174
|
// `external` covers the MCP endpoint and its OAuth routes: machine-facing surfaces whose
|
|
3252
|
-
// clients expect JSON errors, never the admin HTML error page
|
|
3175
|
+
// clients expect JSON errors, never the admin HTML error page. Narrower than
|
|
3176
|
+
// isMachineRoute() on purpose: that one also covers `static`, and a browser following a
|
|
3177
|
+
// link to a missing asset is better served the themed error page than a JSON body
|
|
3253
3178
|
const wantsJsonError = routeTags.includes('api') || routeTags.includes('external');
|
|
3254
3179
|
|
|
3255
3180
|
if (request.errorInfo && wantsJsonError) {
|
|
@@ -3281,6 +3206,10 @@ const init = async () => {
|
|
|
3281
3206
|
|
|
3282
3207
|
server.ext('onPreResponse', preResponse);
|
|
3283
3208
|
|
|
3209
|
+
// After preResponse on purpose: it replaces an error response with the rendered error page
|
|
3210
|
+
// or a JSON body, and the headers have to land on whatever is actually sent
|
|
3211
|
+
server.ext('onPreResponse', securityHeadersExt({ cspMode: CSP_MODE }));
|
|
3212
|
+
|
|
3284
3213
|
server.ext('onPostAuth', async (request, h) => {
|
|
3285
3214
|
if (request.requireTotp) {
|
|
3286
3215
|
// The password step is done and only the second factor is missing, so the session
|
|
@@ -3322,7 +3251,8 @@ const init = async () => {
|
|
|
3322
3251
|
return h.response(renderedMetrics).type('text/plain');
|
|
3323
3252
|
},
|
|
3324
3253
|
options: {
|
|
3325
|
-
|
|
3254
|
+
// external: a Prometheus scraper wants JSON errors and no CSRF or page policy
|
|
3255
|
+
tags: ['scope:metrics', 'external'],
|
|
3326
3256
|
auth: {
|
|
3327
3257
|
strategy: 'api-token',
|
|
3328
3258
|
mode: 'required'
|
package/workers/export.js
CHANGED
|
@@ -17,7 +17,7 @@ const {
|
|
|
17
17
|
DEFAULT_EXPORT_MAX_MESSAGES,
|
|
18
18
|
DEFAULT_EXPORT_MAX_SIZE
|
|
19
19
|
} = require('../lib/consts');
|
|
20
|
-
const { getDuration, readEnvValue, threadStats
|
|
20
|
+
const { getDuration, readEnvValue, threadStats } = require('../lib/tools');
|
|
21
21
|
const { webhooks: Webhooks } = require('../lib/webhooks');
|
|
22
22
|
const settings = require('../lib/settings');
|
|
23
23
|
const {
|
|
@@ -975,10 +975,6 @@ parentPort.on('message', message => {
|
|
|
975
975
|
.then(response => parentPort.postMessage({ cmd: 'resp', mid: message.mid, response }))
|
|
976
976
|
.catch(err => parentPort.postMessage({ cmd: 'resp', mid: message.mid, error: err.message, code: err.code, statusCode: err.statusCode }));
|
|
977
977
|
}
|
|
978
|
-
|
|
979
|
-
if (message && message.cmd === 'settings') {
|
|
980
|
-
maybeReloadHttpProxyAgent(message.data);
|
|
981
|
-
}
|
|
982
978
|
});
|
|
983
979
|
|
|
984
980
|
logger.info({ msg: 'Started Export worker thread', version: packageData.version });
|
package/workers/imap.js
CHANGED
|
@@ -7,7 +7,7 @@ const logger = require('../lib/logger');
|
|
|
7
7
|
|
|
8
8
|
const { REDIS_PREFIX } = require('../lib/consts');
|
|
9
9
|
|
|
10
|
-
const { getDuration, getBoolean, emitChangeEvent, readEnvValue, hasEnvValue, threadStats
|
|
10
|
+
const { getDuration, getBoolean, emitChangeEvent, readEnvValue, hasEnvValue, threadStats } = require('../lib/tools');
|
|
11
11
|
|
|
12
12
|
const { initSentry } = require('../lib/sentry');
|
|
13
13
|
initSentry('imap');
|
|
@@ -874,8 +874,6 @@ class ConnectionHandler {
|
|
|
874
874
|
|
|
875
875
|
switch (message.cmd) {
|
|
876
876
|
case 'settings':
|
|
877
|
-
maybeReloadHttpProxyAgent(message.data);
|
|
878
|
-
|
|
879
877
|
if (message.data && message.data.logs) {
|
|
880
878
|
for (let [account, accountObject] of this.accounts) {
|
|
881
879
|
// update log handling
|
package/workers/smtp.js
CHANGED
|
@@ -6,8 +6,8 @@ const packageData = require('../package.json');
|
|
|
6
6
|
const config = require('@zone-eu/wild-config');
|
|
7
7
|
const logger = require('../lib/logger');
|
|
8
8
|
|
|
9
|
-
const { getDuration, emitChangeEvent, readEnvValue, threadStats, loadTlsConfig, getByteSize } = require('../lib/tools');
|
|
10
|
-
const { createSmtpAuthHandler } = require('../lib/smtp-auth');
|
|
9
|
+
const { getDuration, emitChangeEvent, readEnvValue, threadStats, loadTlsConfig, assertTlsCredentials, getByteSize, httpAgent } = require('../lib/tools');
|
|
10
|
+
const { createSmtpAuthHandler, createSmtpAccountResolver } = require('../lib/smtp-auth');
|
|
11
11
|
|
|
12
12
|
const { initSentry } = require('../lib/sentry');
|
|
13
13
|
initSentry('smtp');
|
|
@@ -15,7 +15,6 @@ initSentry('smtp');
|
|
|
15
15
|
const { SMTPServer } = require('smtp-server');
|
|
16
16
|
const util = require('util');
|
|
17
17
|
const { redis } = require('../lib/db');
|
|
18
|
-
const { Account } = require('../lib/account');
|
|
19
18
|
const getSecret = require('../lib/get-secret');
|
|
20
19
|
const { collectMessage } = require('../lib/smtp-message-processor');
|
|
21
20
|
const settings = require('../lib/settings');
|
|
@@ -113,46 +112,11 @@ for (let level of ['trace', 'debug', 'info', 'warn', 'error', 'fatal']) {
|
|
|
113
112
|
};
|
|
114
113
|
}
|
|
115
114
|
|
|
116
|
-
// Authentication
|
|
117
|
-
// without booting this worker. The shared ACCOUNT_CACHE and call() are injected
|
|
118
|
-
//
|
|
115
|
+
// Authentication and account resolution live in lib/smtp-auth.js so they can be unit tested
|
|
116
|
+
// without booting this worker. The shared ACCOUNT_CACHE and call() are injected so onAuth
|
|
117
|
+
// caches the Account that the resolver hands to the submission.
|
|
119
118
|
const onAuth = createSmtpAuthHandler({ accountCache: ACCOUNT_CACHE, call });
|
|
120
|
-
|
|
121
|
-
async function checkAccountData(session, messageMeta) {
|
|
122
|
-
let accountObject;
|
|
123
|
-
|
|
124
|
-
if (!session.eeAuthEnabled && messageMeta.requestedAccount) {
|
|
125
|
-
// load account data
|
|
126
|
-
accountObject = new Account({ account: messageMeta.requestedAccount, redis, call, secret: await getSecret() });
|
|
127
|
-
let accountData;
|
|
128
|
-
try {
|
|
129
|
-
// throws if unknown user
|
|
130
|
-
accountData = await accountObject.loadAccountData();
|
|
131
|
-
if (accountData) {
|
|
132
|
-
ACCOUNT_CACHE.set(session, accountObject);
|
|
133
|
-
logger.debug({ msg: 'Resolved requested account', account: messageMeta.requestedAccount });
|
|
134
|
-
}
|
|
135
|
-
} catch (err) {
|
|
136
|
-
logger.warn({ msg: 'Failed to resolve requested account', account: messageMeta.requestedAccount, err });
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
accountObject = ACCOUNT_CACHE.get(session);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!session.eeAuthEnabled && !messageMeta.requestedAccount && !accountObject) {
|
|
143
|
-
let err = new Error('Sender account ID not provided, can not send mail');
|
|
144
|
-
err.responseCode = 451;
|
|
145
|
-
throw err;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (!accountObject) {
|
|
149
|
-
let err = new Error('Failed to load account');
|
|
150
|
-
err.responseCode = 451;
|
|
151
|
-
throw err;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return accountObject;
|
|
155
|
-
}
|
|
119
|
+
const resolveAccount = createSmtpAccountResolver({ accountCache: ACCOUNT_CACHE, call });
|
|
156
120
|
|
|
157
121
|
async function init() {
|
|
158
122
|
let server;
|
|
@@ -174,6 +138,9 @@ async function init() {
|
|
|
174
138
|
|
|
175
139
|
environment: 'ee',
|
|
176
140
|
|
|
141
|
+
// long-lived client, see LiveDispatcher in lib/tools.js
|
|
142
|
+
dispatcher: httpAgent.live,
|
|
143
|
+
|
|
177
144
|
logger: logger.child({ sub: 'acme' }),
|
|
178
145
|
|
|
179
146
|
encryptFn: async value => {
|
|
@@ -239,7 +206,7 @@ async function init() {
|
|
|
239
206
|
throw err;
|
|
240
207
|
}
|
|
241
208
|
|
|
242
|
-
let accountObject = await
|
|
209
|
+
let accountObject = await resolveAccount(session, messageMeta);
|
|
243
210
|
|
|
244
211
|
let payload = {
|
|
245
212
|
envelope: {
|
|
@@ -309,6 +276,8 @@ async function init() {
|
|
|
309
276
|
serverOptions.key = certificateData.privateKey;
|
|
310
277
|
}
|
|
311
278
|
}
|
|
279
|
+
|
|
280
|
+
assertTlsCredentials(serverOptions, 'The SMTP server');
|
|
312
281
|
} else {
|
|
313
282
|
serverOptions.disabledCommands = ['STARTTLS'];
|
|
314
283
|
serverOptions.hideSTARTTLS = true;
|
package/workers/submit.js
CHANGED
|
@@ -7,7 +7,7 @@ const config = require('@zone-eu/wild-config');
|
|
|
7
7
|
const logger = require('../lib/logger');
|
|
8
8
|
|
|
9
9
|
const { REDIS_PREFIX } = require('../lib/consts');
|
|
10
|
-
const { getDuration, readEnvValue, threadStats
|
|
10
|
+
const { getDuration, readEnvValue, threadStats } = require('../lib/tools');
|
|
11
11
|
const { webhooks: Webhooks } = require('../lib/webhooks');
|
|
12
12
|
const settings = require('../lib/settings');
|
|
13
13
|
|
|
@@ -19,7 +19,7 @@ const { redis, queueConf, submitQueue } = require('../lib/db');
|
|
|
19
19
|
const { Worker, UnrecoverableError } = require('bullmq');
|
|
20
20
|
const { Account } = require('../lib/account');
|
|
21
21
|
const getSecret = require('../lib/get-secret');
|
|
22
|
-
const
|
|
22
|
+
const { decodeQueueEntry } = require('../lib/outbox');
|
|
23
23
|
|
|
24
24
|
const { EMAIL_FAILED_NOTIFY } = require('../lib/consts');
|
|
25
25
|
|
|
@@ -179,7 +179,10 @@ const submitWorker = new Worker(
|
|
|
179
179
|
|
|
180
180
|
let queueEntry;
|
|
181
181
|
try {
|
|
182
|
-
|
|
182
|
+
// Rejects a value that decodes to something other than a map as well, otherwise the
|
|
183
|
+
// job metadata assignment below throws a TypeError against it and the entry is retried
|
|
184
|
+
// as a failed delivery instead of being dropped as the corrupt entry it is
|
|
185
|
+
queueEntry = decodeQueueEntry(queueEntryBuf);
|
|
183
186
|
} catch (err) {
|
|
184
187
|
logger.error({ msg: 'Failed to parse queued email entry', job: job.id, account: job.data.account, queueId: job.data.queueId, err });
|
|
185
188
|
try {
|
|
@@ -190,11 +193,6 @@ const submitWorker = new Worker(
|
|
|
190
193
|
return;
|
|
191
194
|
}
|
|
192
195
|
|
|
193
|
-
if (!queueEntry) {
|
|
194
|
-
//could be expired?
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
196
|
let accountObject = new Account({ account: job.data.account, redis, call, secret: await getSecret() });
|
|
199
197
|
|
|
200
198
|
logger.trace({
|
|
@@ -508,10 +506,6 @@ parentPort.on('message', message => {
|
|
|
508
506
|
parentPort.postMessage(Object.assign({ cmd: 'resp', mid: message.mid }, packRpcError(err)));
|
|
509
507
|
});
|
|
510
508
|
}
|
|
511
|
-
|
|
512
|
-
if (message && message.cmd === 'settings') {
|
|
513
|
-
maybeReloadHttpProxyAgent(message.data);
|
|
514
|
-
}
|
|
515
509
|
});
|
|
516
510
|
|
|
517
511
|
logger.info({ msg: 'Started SMTP submission worker thread', version: packageData.version });
|
package/workers/webhooks.js
CHANGED
|
@@ -10,16 +10,7 @@ const { webhooks: Webhooks } = require('../lib/webhooks');
|
|
|
10
10
|
|
|
11
11
|
const { GooglePubSub } = require('../lib/oauth/pubsub/google');
|
|
12
12
|
|
|
13
|
-
const {
|
|
14
|
-
readEnvValue,
|
|
15
|
-
threadStats,
|
|
16
|
-
getDuration,
|
|
17
|
-
httpAgent,
|
|
18
|
-
getServiceSecret,
|
|
19
|
-
maybeReloadHttpProxyAgent,
|
|
20
|
-
redactUrlCredentials,
|
|
21
|
-
splitUrlCredentials
|
|
22
|
-
} = require('../lib/tools');
|
|
13
|
+
const { readEnvValue, threadStats, getDuration, httpAgent, getServiceSecret, redactUrlCredentials, splitUrlCredentials } = require('../lib/tools');
|
|
23
14
|
const { sendWebhookRequest } = require('../lib/webhook-request');
|
|
24
15
|
const { willBeFinalAttempt, isFinalFailedAttempt } = require('../lib/delivery-error');
|
|
25
16
|
const { validateWebhookTarget } = require('../lib/webhook-egress');
|
|
@@ -198,10 +189,6 @@ parentPort.on('message', message => {
|
|
|
198
189
|
});
|
|
199
190
|
});
|
|
200
191
|
}
|
|
201
|
-
|
|
202
|
-
if (message && message.cmd === 'settings') {
|
|
203
|
-
maybeReloadHttpProxyAgent(message.data);
|
|
204
|
-
}
|
|
205
192
|
});
|
|
206
193
|
|
|
207
194
|
const notifyWorker = new Worker(
|
|
@@ -518,7 +505,9 @@ const notifyWorker = new Worker(
|
|
|
518
505
|
event: job.name,
|
|
519
506
|
message: err.message,
|
|
520
507
|
time: Date.now(),
|
|
521
|
-
|
|
508
|
+
// stored without credentials: the flag is read back through the
|
|
509
|
+
// webhook route listing, the account page and the settings API
|
|
510
|
+
url: redactUrlCredentials(customRoute.targetUrl),
|
|
522
511
|
code: err.code,
|
|
523
512
|
statusCode: err.statusCode
|
|
524
513
|
})
|
|
@@ -531,7 +520,7 @@ const notifyWorker = new Worker(
|
|
|
531
520
|
event: job.name,
|
|
532
521
|
message: err.message,
|
|
533
522
|
time: Date.now(),
|
|
534
|
-
url:
|
|
523
|
+
url: redactedWebhooks,
|
|
535
524
|
code: err.code,
|
|
536
525
|
statusCode: err.statusCode
|
|
537
526
|
})
|
|
@@ -541,7 +530,7 @@ const notifyWorker = new Worker(
|
|
|
541
530
|
event: job.name,
|
|
542
531
|
message: err.message,
|
|
543
532
|
time: Date.now(),
|
|
544
|
-
url:
|
|
533
|
+
url: redactedWebhooks,
|
|
545
534
|
code: err.code,
|
|
546
535
|
statusCode: err.statusCode
|
|
547
536
|
});
|
|
Binary file
|
|
Binary file
|
package/static/front/index.html
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en" class="h-100">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
|
|
6
|
-
<meta name="description" content="EmailEngine" />
|
|
7
|
-
<title>EmailEngine Set-up</title>
|
|
8
|
-
<link
|
|
9
|
-
rel="stylesheet"
|
|
10
|
-
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css"
|
|
11
|
-
integrity="sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn"
|
|
12
|
-
crossorigin="anonymous"
|
|
13
|
-
/>
|
|
14
|
-
</head>
|
|
15
|
-
|
|
16
|
-
<body class="d-flex flex-column h-100">
|
|
17
|
-
<main role="main" class="flex-shrink-0">
|
|
18
|
-
<div class="container mt-4">
|
|
19
|
-
<div class="d-flex">
|
|
20
|
-
<img src="./EmailEngine_logo_horiz.png" style="display: block; max-height: 80px; max-width: 100%" />
|
|
21
|
-
</div>
|
|
22
|
-
|
|
23
|
-
<div class="row mt-4">
|
|
24
|
-
<div class="col-12 col-sm-12 col-md-12 col-lg-8">
|
|
25
|
-
<p>
|
|
26
|
-
EmailEngine is an email client software designed for applications, not individual users. It connects to users' email servers and
|
|
27
|
-
translates REST API requests from the app into IMAP and SMTP commands, or into Gmail API or Microsoft Graph API requests.
|
|
28
|
-
Additionally, it sends webhooks to notify the app of events such as new or deleted emails.
|
|
29
|
-
</p>
|
|
30
|
-
|
|
31
|
-
<div class="mt-4 alert alert-info">
|
|
32
|
-
To continue setting up your EmailEngine installation, log in to your server using SSH:<br />
|
|
33
|
-
<kbd style="display: block; padding: 1.2rem; margin-top: 1rem">$ ssh root@<span id="hostname">example.com</span></kbd>
|
|
34
|
-
</div>
|
|
35
|
-
</div>
|
|
36
|
-
</div>
|
|
37
|
-
</div>
|
|
38
|
-
</main>
|
|
39
|
-
|
|
40
|
-
<footer class="footer mt-auto py-3">
|
|
41
|
-
<div class="container">
|
|
42
|
-
<div class="row">
|
|
43
|
-
<div class="col-sm-8">
|
|
44
|
-
EmailEngine
|
|
45
|
-
<span class="text-muted">© 2020-<span id="curyear">2025</span></span>
|
|
46
|
-
Postal Systems OÜ.
|
|
47
|
-
</div>
|
|
48
|
-
</div>
|
|
49
|
-
</div>
|
|
50
|
-
</footer>
|
|
51
|
-
|
|
52
|
-
<script>
|
|
53
|
-
document.getElementById('hostname').textContent = window.location.hostname;
|
|
54
|
-
document.getElementById('curyear').textContent = new Date().getFullYear();
|
|
55
|
-
</script>
|
|
56
|
-
</body>
|
|
57
|
-
</html>
|
package/static/front/logo.png
DELETED
|
Binary file
|