emailengine-app 2.79.7 → 2.79.8
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 +17 -0
- package/DOCKER_DEPLOYMENT.md +2 -0
- package/bin/emailengine.js +29 -13
- package/config/default.toml +13 -3
- package/data/google-crawlers.json +7 -1
- package/docker-compose.yml +12 -3
- package/install.sh +2 -0
- package/lib/api-routes/account-routes.js +14 -3
- package/lib/api-routes/mailbox-routes.js +4 -1
- package/lib/api-routes/message-routes.js +6 -5
- package/lib/api-routes/outbox-routes.js +7 -4
- package/lib/api-routes/settings-routes.js +34 -25
- package/lib/api-routes/stats-routes.js +8 -1
- package/lib/api-routes/submit-routes.js +2 -1
- package/lib/api-routes/template-routes.js +3 -2
- package/lib/bounce-detect.js +45 -0
- package/lib/consts.js +5 -1
- package/lib/egress-filter.js +39 -4
- package/lib/email-client/base-client.js +274 -24
- package/lib/email-client/gmail/gmail-api.js +15 -7
- package/lib/email-client/gmail-client.js +121 -64
- package/lib/email-client/imap/mailbox.js +18 -59
- package/lib/email-client/imap-client.js +53 -29
- package/lib/email-client/notification-handler.js +11 -2
- package/lib/email-client/outlook/graph-api.js +106 -90
- package/lib/email-client/outlook-client.js +222 -106
- package/lib/generate-text-preview.js +10 -5
- package/lib/headers-rewriter.js +1 -1
- package/lib/llm-pre-process.js +4 -1
- package/lib/mcp/json-schema.js +50 -2
- package/lib/outbox.js +22 -5
- package/lib/pre-process.js +4 -1
- package/lib/rewrite-text-nodes.js +12 -1
- package/lib/schemas.js +27 -5
- package/lib/settings.js +19 -1
- package/lib/sso.js +13 -3
- package/lib/submit-progress.js +29 -0
- package/lib/templates.js +11 -0
- package/lib/tools.js +96 -53
- package/lib/ui-routes/account-routes.js +70 -11
- package/lib/ui-routes/admin-config-routes.js +7 -21
- package/lib/ui-routes/admin-entities-routes.js +42 -12
- package/lib/ui-routes/auth-routes.js +87 -28
- package/lib/ui-routes/dashboard-routes.js +1 -1
- package/lib/ui-routes/internals-routes.js +2 -0
- package/lib/ui-routes/mcp-consent-routes.js +5 -2
- package/lib/ui-routes/network-config-routes.js +2 -2
- package/lib/ui-routes/oauth-config-routes.js +12 -1
- package/lib/ui-routes/route-helpers.js +41 -6
- package/lib/ui-routes/settings-page.js +10 -0
- package/lib/ui-routes/suppression-list-routes.js +16 -5
- package/lib/ui-routes/unsubscribe-routes.js +22 -3
- package/lib/webhooks.js +14 -2
- package/package.json +11 -11
- package/sbom.json +1 -1
- package/server.js +63 -35
- package/static/css/flyonui.css +1 -1
- package/static/licenses.html +17 -17
- package/translations/messages.pot +49 -49
- package/views/account/passkeys.hbs +8 -0
- package/views/account/password.hbs +11 -0
- package/views/account/security.hbs +18 -7
- package/views/accounts/account.hbs +6 -1
- package/views/accounts/register/imap-server.hbs +10 -2
- package/views/config/ai.hbs +2 -0
- package/views/config/branding.hbs +2 -0
- package/views/config/email-processing.hbs +2 -0
- package/views/config/imap-proxy.hbs +2 -0
- package/views/config/logging.hbs +3 -1
- package/views/config/mcp.hbs +2 -0
- package/views/config/network.hbs +2 -0
- package/views/config/oauth/app.hbs +2 -2
- package/views/config/security.hbs +2 -0
- package/views/config/service.hbs +2 -0
- package/views/config/smtp.hbs +2 -0
- package/views/config/webhooks.hbs +2 -0
- package/views/error.hbs +6 -0
- package/views/layout/app.hbs +6 -3
- package/views/layout/login.hbs +1 -1
- package/views/layout/prompt.hbs +1 -1
- package/views/layout/public.hbs +1 -1
- package/views/legal.hbs +1 -1
- package/views/partials/filter_editor_js.hbs +1 -1
- package/views/partials/oauth_form.hbs +5 -5
- package/views/partials/ui/env-managed-alert.hbs +19 -0
- package/views/partials/webhook_form.hbs +1 -1
- package/views/unsubscribe.hbs +6 -0
- package/workers/api.js +137 -63
- package/workers/imap.js +32 -3
- package/workers/smtp.js +7 -0
- package/workers/submit.js +25 -1
- package/workers/webhooks.js +13 -17
- package/lib/reconnection-manager.js +0 -106
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
<div class="modal-footer justify-between">
|
|
44
44
|
<div>
|
|
45
45
|
<select class="select" id="select-predefined-payload">
|
|
46
|
-
<option>{{#if selectPlaceholder}}{{selectPlaceholder}}{{else}}
|
|
46
|
+
<option>{{#if selectPlaceholder}}{{selectPlaceholder}}{{else}}Select a predefined payload{{/if}}</option>
|
|
47
47
|
</select>
|
|
48
48
|
</div>
|
|
49
49
|
{{> ui/btn label="Close" variant="neutral" style="soft" overlay="#setPayloadModal"}}
|
|
@@ -248,7 +248,7 @@ Read about setting up {{providerData.comment}} from <a href="{{providerData.tuto
|
|
|
248
248
|
|
|
249
249
|
{{#each azureClouds}}
|
|
250
250
|
<option value="{{id}}" {{#if selected}}selected{{/if}}>{{name}}{{#if
|
|
251
|
-
description}}
|
|
251
|
+
description}} -
|
|
252
252
|
{{description}}{{/if}}</option>
|
|
253
253
|
{{/each}}
|
|
254
254
|
</select>
|
|
@@ -329,7 +329,7 @@ Read about setting up {{providerData.comment}} from <a href="{{providerData.tuto
|
|
|
329
329
|
|
|
330
330
|
{{#each azureClouds}}
|
|
331
331
|
<option value="{{id}}" {{#if selected}}selected{{/if}}>{{name}}{{#if
|
|
332
|
-
description}}
|
|
332
|
+
description}} -
|
|
333
333
|
{{description}}{{/if}}</option>
|
|
334
334
|
{{/each}}
|
|
335
335
|
</select>
|
|
@@ -648,12 +648,12 @@ Read about setting up {{providerData.comment}} from <a href="{{providerData.tuto
|
|
|
648
648
|
<select class="select w-full{{#if errors.pubSubApp}} is-invalid{{/if}}" id="pubSubApp"
|
|
649
649
|
name="pubSubApp" {{#unless baseScopesApi}}disabled{{/unless}}>
|
|
650
650
|
|
|
651
|
-
<option value="">
|
|
651
|
+
<option value="">Select the service account for your project</option>
|
|
652
652
|
|
|
653
653
|
{{#each pubSubApps}}
|
|
654
654
|
<option value="{{id}}" data-project="{{googleProjectId}}" {{#if selected}}selected{{/if}} {{#unless
|
|
655
655
|
baseScopesApi}}disabled{{/unless}}>{{name}}{{#if
|
|
656
|
-
description}}
|
|
656
|
+
description}} -
|
|
657
657
|
{{description}}{{/if}} [{{googleProjectId}}]</option>
|
|
658
658
|
{{/each}}
|
|
659
659
|
|
|
@@ -787,7 +787,7 @@ Read about setting up {{providerData.comment}} from <a href="{{providerData.tuto
|
|
|
787
787
|
|
|
788
788
|
<div class="card-body">
|
|
789
789
|
<input type="hidden" name="baseScopes" value="api" />
|
|
790
|
-
<p><strong>MS Graph API</strong>
|
|
790
|
+
<p><strong>MS Graph API</strong> - This app uses Microsoft Graph API with application permissions
|
|
791
791
|
(client credentials). Requires <code>Mail.ReadWrite</code>, <code>Mail.Send</code>, and
|
|
792
792
|
<code>User.Read.All</code> application permissions with admin consent in Entra.</p>
|
|
793
793
|
</div>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{{!--
|
|
2
|
+
ui/env-managed-alert - notice for the settings pages registered through
|
|
3
|
+
lib/ui-routes/settings-page.js, naming the form fields whose values the EENGINE_SETTINGS
|
|
4
|
+
environment variable re-applies on every boot. A value saved for one of them holds only
|
|
5
|
+
until the next restart, and without this the page would show the save succeeding.
|
|
6
|
+
Renders nothing when the page has no such field. The inputs stay enabled on purpose -
|
|
7
|
+
a disabled control drops out of the POST and would silently strip its value from the
|
|
8
|
+
save - so the notice is the whole treatment.
|
|
9
|
+
{{> ui/env-managed-alert}}
|
|
10
|
+
Reads `envManagedKeys` (array of field names) from the page context; registerSettingsPage
|
|
11
|
+
sets it on every render of the page.
|
|
12
|
+
--}}
|
|
13
|
+
{{#if envManagedKeys.length}}
|
|
14
|
+
{{#> ui/alert-banner variant="info" icon="icon-[tabler--info-circle]" title="Some fields are set by the environment"}}
|
|
15
|
+
<div>The following settings come from the <code>EENGINE_SETTINGS</code> environment variable and are re-applied on
|
|
16
|
+
every restart. A value saved here is used until the next restart, then reverts to the environment value:
|
|
17
|
+
{{#each envManagedKeys}}<code>{{this}}</code>{{#unless @last}}, {{/unless}}{{/each}}.</div>
|
|
18
|
+
{{/ui/alert-banner}}
|
|
19
|
+
{{/if}}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
{{> ui/form-field id="inputDescription" name="description" label="Description" value=values.description error=errors.description hint="Description for this routing."}}
|
|
9
9
|
|
|
10
|
-
{{> ui/form-field id="inputTargetUrl" name="targetUrl" type="url" label="Target URL" value=values.targetUrl error=errors.targetUrl
|
|
10
|
+
{{> ui/form-field id="inputTargetUrl" name="targetUrl" type="url" label="Target URL" value=values.targetUrl error=errors.targetUrl placeholder='URL like "https://myservice.com/imap/webhooks"' hint="Webhook target URL for this routing. Leave empty to deliver to the default webhook URL from the Webhooks settings."}}
|
|
11
11
|
|
|
12
12
|
{{> ui/checkbox id="enabled" label="Enable this webhook route" checked=values.enabled error=errors.enabled hint="Webhook routes are not enabled by default."}}
|
|
13
13
|
|
package/views/unsubscribe.hbs
CHANGED
|
@@ -59,6 +59,7 @@ focus ring on) the corner close button --}}
|
|
|
59
59
|
|
|
60
60
|
<h1>{{_ "Unsubscribe" templateLocale }}</h1>
|
|
61
61
|
|
|
62
|
+
{{#if values.sig}}
|
|
62
63
|
<div class="ee-narrow">
|
|
63
64
|
<form method="post" action="/unsubscribe/address">
|
|
64
65
|
<input type="hidden" name="crumb" value="{{crumb}}" />
|
|
@@ -76,6 +77,11 @@ focus ring on) the corner close button --}}
|
|
|
76
77
|
</div>
|
|
77
78
|
</form>
|
|
78
79
|
</div>
|
|
80
|
+
{{else}}
|
|
81
|
+
{{!-- A submit whose signed payload did not verify (or a malformed one) leaves nothing
|
|
82
|
+
trustworthy to put in the form, and an empty form would only fail again --}}
|
|
83
|
+
<p>{{_ "This link is not valid. Use the unsubscribe link from the email you received." templateLocale }}</p>
|
|
84
|
+
{{/if}}
|
|
79
85
|
|
|
80
86
|
{{/if}}
|
|
81
87
|
|
package/workers/api.js
CHANGED
|
@@ -124,6 +124,7 @@ const {
|
|
|
124
124
|
oauth2Schema,
|
|
125
125
|
accountIdSchema,
|
|
126
126
|
apiHeadersSchema,
|
|
127
|
+
headerTimeoutSchema,
|
|
127
128
|
oauth2ProviderSchema: OAuth2ProviderSchema,
|
|
128
129
|
accountTypeSchema: AccountTypeSchema
|
|
129
130
|
} = require('../lib/schemas');
|
|
@@ -402,6 +403,11 @@ function publishChangeEvent(data) {
|
|
|
402
403
|
}
|
|
403
404
|
}
|
|
404
405
|
|
|
406
|
+
// The Hapi server, published by init() once the session strategy is registered and the boot-time
|
|
407
|
+
// default has been decided, so the authData branch of the settings dispatcher below cannot set a
|
|
408
|
+
// strategy that does not exist yet or race the boot-time server.auth.default() call
|
|
409
|
+
let sessionAuthServer = null;
|
|
410
|
+
|
|
405
411
|
parentPort.on('message', message => {
|
|
406
412
|
if (message && message.cmd === 'resp' && message.mid && callQueue.has(message.mid)) {
|
|
407
413
|
let { resolve, reject, timer } = callQueue.get(message.mid);
|
|
@@ -458,6 +464,17 @@ parentPort.on('message', message => {
|
|
|
458
464
|
maybeReloadHttpProxyAgent(message.data);
|
|
459
465
|
// ...and the API reference's memoized serviceUrl, which its code samples embed
|
|
460
466
|
clearServiceUrlCache();
|
|
467
|
+
|
|
468
|
+
// The first admin password is saved by whichever API worker served the form, and only
|
|
469
|
+
// that worker's server gets the default strategy in-process (lib/ui-routes/auth-routes.js).
|
|
470
|
+
// The same handler broadcasts a settings change carrying the authData key, so with
|
|
471
|
+
// EENGINE_WORKERS_API > 1 the other workers stop serving /admin open here instead of at
|
|
472
|
+
// the next restart. hapi refuses a second default, hence the guard, which also covers
|
|
473
|
+
// the sender.
|
|
474
|
+
if (message.data && message.data.authData && sessionAuthServer && !sessionAuthServer.auth.settings.default) {
|
|
475
|
+
sessionAuthServer.auth.default('session');
|
|
476
|
+
logger.info({ msg: 'Admin session authentication enabled after the first password was set' });
|
|
477
|
+
}
|
|
461
478
|
}
|
|
462
479
|
});
|
|
463
480
|
|
|
@@ -574,7 +591,12 @@ const init = async () => {
|
|
|
574
591
|
messages: joiLocales,
|
|
575
592
|
convert: true,
|
|
576
593
|
errors: {
|
|
577
|
-
|
|
594
|
+
// Resolved per request from request.app.locale, which onPreAuth sets and
|
|
595
|
+
// hapi exposes to joi as the $app.request context. A locale with no
|
|
596
|
+
// joi catalog falls through to joi's own English messages. This has to be
|
|
597
|
+
// a reference: the route settings are shared by every request on the
|
|
598
|
+
// route, so writing the locale into them races concurrent requests
|
|
599
|
+
language: Joi.ref('$app.request.locale')
|
|
578
600
|
}
|
|
579
601
|
},
|
|
580
602
|
headers: apiHeadersSchema
|
|
@@ -770,21 +792,9 @@ const init = async () => {
|
|
|
770
792
|
request.app.gt = gt;
|
|
771
793
|
}
|
|
772
794
|
|
|
773
|
-
//
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
const locale = request.app.locale || 'en';
|
|
777
|
-
|
|
778
|
-
// Create new validation options for this request
|
|
779
|
-
const validationOptions = Object.assign({}, request.route.settings.validate.options, {
|
|
780
|
-
errors: {
|
|
781
|
-
language: locale
|
|
782
|
-
}
|
|
783
|
-
});
|
|
784
|
-
|
|
785
|
-
// Apply to this request only
|
|
786
|
-
request.route.settings.validate.options = validationOptions;
|
|
787
|
-
}
|
|
795
|
+
// Validation errors pick their language up from request.app.locale through the
|
|
796
|
+
// errors.language reference in the server-wide route defaults (see serverOptions), so
|
|
797
|
+
// nothing per request is written into the shared route settings here
|
|
788
798
|
|
|
789
799
|
return h.continue;
|
|
790
800
|
});
|
|
@@ -817,7 +827,12 @@ const init = async () => {
|
|
|
817
827
|
// the outer request (lib/mcp/inject.js), so the IPC round trip is not paid twice for
|
|
818
828
|
// one answer that cannot differ within a request.
|
|
819
829
|
if (!request.app.licenseInfo) {
|
|
820
|
-
|
|
830
|
+
// This runs before route validation, so the header is still the raw string here. The
|
|
831
|
+
// route schema decides what it accepts (a bad value is that route's 400 later); a value
|
|
832
|
+
// it would refuse is ignored rather than handed to the timer, where a non-number or an
|
|
833
|
+
// overflow collapses to a 1 ms timeout and a 500 before validation ever runs.
|
|
834
|
+
const { error: timeoutError, value: requestTimeout } = headerTimeoutSchema.validate(request.headers['x-ee-timeout']);
|
|
835
|
+
request.app.licenseInfo = await call({ cmd: 'license', timeout: timeoutError ? undefined : requestTimeout });
|
|
821
836
|
}
|
|
822
837
|
|
|
823
838
|
// flash notifications
|
|
@@ -966,11 +981,16 @@ const init = async () => {
|
|
|
966
981
|
// only repeat it
|
|
967
982
|
tokenData = await tokens.get(token, false, { log: !request.app.mcpInternal, remoteAddress: request.app.ip });
|
|
968
983
|
} catch (err) {
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
984
|
+
// A thrown Boom reaches the client the way the scope and permission refusals
|
|
985
|
+
// below do (hapi-auth-bearer-token does not catch it), so the reason travels as a
|
|
986
|
+
// machine-readable code - UnknownToken, ExpiredToken, InvalidToken - while the
|
|
987
|
+
// message stays the generic one the scheme itself would have sent. The scheme
|
|
988
|
+
// name keeps the WWW-Authenticate header the plugin's own refusal carries.
|
|
989
|
+
let error = Boom.unauthorized('Bad token', 'Bearer');
|
|
990
|
+
if (err.code) {
|
|
991
|
+
error.output.payload.code = err.code;
|
|
992
|
+
}
|
|
993
|
+
throw error;
|
|
974
994
|
}
|
|
975
995
|
|
|
976
996
|
// Bind the token hash (id) to the request logger so it is included in the per-request
|
|
@@ -1200,7 +1220,10 @@ const init = async () => {
|
|
|
1200
1220
|
error.output.payload.ttl = Math.ceil(rateLimit.ttl);
|
|
1201
1221
|
error.output.headers = {
|
|
1202
1222
|
'X-RateLimit-Limit': rateLimit.allowed,
|
|
1203
|
-
'X-RateLimit-Reset': Math.ceil(rateLimit.ttl)
|
|
1223
|
+
'X-RateLimit-Reset': Math.ceil(rateLimit.ttl),
|
|
1224
|
+
// The conventional header for a 429, so a generic HTTP client backs
|
|
1225
|
+
// off without knowing about the ttl field in the body
|
|
1226
|
+
'Retry-After': Math.ceil(rateLimit.ttl)
|
|
1204
1227
|
};
|
|
1205
1228
|
throw error;
|
|
1206
1229
|
} else {
|
|
@@ -1368,12 +1391,20 @@ const init = async () => {
|
|
|
1368
1391
|
// break the registered callback URL) disables the SSO button instead of failing mid-flow.
|
|
1369
1392
|
let getServiceRedirectUrl = async () => new URL((await settings.get('serviceUrl')) || `http://${API_HOST}${API_PORT !== 80 ? `:${API_PORT}` : ''}`);
|
|
1370
1393
|
let serviceOriginUnchanged = async redirectUrl => (await getServiceRedirectUrl()).origin === redirectUrl.origin;
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1394
|
+
// A sign-in the IdP denied, or the user cancelled, comes back as an unauthenticated try-mode
|
|
1395
|
+
// request. It gets the same flash-and-redirect the allow-list denial in the OIDC handler
|
|
1396
|
+
// uses, so the user lands on the login form with a way to try again rather than on the
|
|
1397
|
+
// generic error page with bell's raw message. The reason goes to the log only. ?sso_denied=1
|
|
1398
|
+
// stops a forced instance from auto-redirecting straight back into the flow.
|
|
1399
|
+
let ssoFailureRedirect = async (request, h, method) => {
|
|
1400
|
+
request.logger.warn({
|
|
1401
|
+
msg: 'SSO login failed',
|
|
1402
|
+
method,
|
|
1403
|
+
reason: (request.auth.error && request.auth.error.message) || 'unknown',
|
|
1404
|
+
remoteAddress: request.app.ip
|
|
1405
|
+
});
|
|
1406
|
+
await request.flash({ type: 'danger', message: 'Single sign-on failed or was cancelled. Please try again' });
|
|
1407
|
+
return h.redirect('/admin/login?sso_denied=1');
|
|
1377
1408
|
};
|
|
1378
1409
|
|
|
1379
1410
|
if (USE_OKTA_AUTH) {
|
|
@@ -1398,10 +1429,28 @@ const init = async () => {
|
|
|
1398
1429
|
method: ['GET', 'POST'],
|
|
1399
1430
|
path: '/admin/login/okta',
|
|
1400
1431
|
async handler(request, h) {
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1432
|
+
if (!request.auth.isAuthenticated) {
|
|
1433
|
+
return ssoFailureRedirect(request, h, 'okta');
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
let profile = (request.auth.credentials && request.auth.credentials.profile) || {};
|
|
1437
|
+
|
|
1438
|
+
// The same minimal shape the OIDC branch below stores, for the same reasons: the
|
|
1439
|
+
// full bell credentials carry the access and refresh tokens, the callback query
|
|
1440
|
+
// and the raw userinfo document, none of which the session validator reads, and
|
|
1441
|
+
// all of which would sit in the browser's cookie for the life of the session.
|
|
1442
|
+
setAdminSession(request, {
|
|
1443
|
+
provider: 'okta',
|
|
1444
|
+
profile: {
|
|
1445
|
+
id: profile.id,
|
|
1446
|
+
username: profile.username,
|
|
1447
|
+
displayName: profile.displayName,
|
|
1448
|
+
email: profile.email
|
|
1449
|
+
},
|
|
1450
|
+
passwordVersion: await sessionPasswordVersion()
|
|
1451
|
+
});
|
|
1452
|
+
|
|
1453
|
+
request.logger.info({ msg: 'Admin login successful', user: profile.username || 'unknown', method: 'okta', remoteAddress: request.app.ip });
|
|
1405
1454
|
return h.redirect('/admin');
|
|
1406
1455
|
},
|
|
1407
1456
|
options: {
|
|
@@ -1463,7 +1512,9 @@ const init = async () => {
|
|
|
1463
1512
|
method: ['GET', 'POST'],
|
|
1464
1513
|
path: '/admin/login/oidc',
|
|
1465
1514
|
async handler(request, h) {
|
|
1466
|
-
|
|
1515
|
+
if (!request.auth.isAuthenticated) {
|
|
1516
|
+
return ssoFailureRedirect(request, h, 'oidc');
|
|
1517
|
+
}
|
|
1467
1518
|
|
|
1468
1519
|
let profile = (request.auth.credentials && request.auth.credentials.profile) || {};
|
|
1469
1520
|
|
|
@@ -1547,6 +1598,10 @@ const init = async () => {
|
|
|
1547
1598
|
server.auth.default('session');
|
|
1548
1599
|
}
|
|
1549
1600
|
|
|
1601
|
+
// From here on a first password set on another API worker switches the session strategy on
|
|
1602
|
+
// through the settings dispatcher (see the authData branch there)
|
|
1603
|
+
sessionAuthServer = server;
|
|
1604
|
+
|
|
1550
1605
|
await server.register({
|
|
1551
1606
|
plugin: hapiPino,
|
|
1552
1607
|
options: {
|
|
@@ -2270,40 +2325,44 @@ const init = async () => {
|
|
|
2270
2325
|
method: 'GET',
|
|
2271
2326
|
path: '/oauth',
|
|
2272
2327
|
async handler(request, h) {
|
|
2273
|
-
|
|
2274
|
-
|
|
2328
|
+
// The mailbox owner sees these on the public error page, in the same locale as the
|
|
2329
|
+
// rest of the setup flow. The pending setup is still unspent at this point (its state
|
|
2330
|
+
// entry is claimed only below), so opening the setup link again is a valid retry.
|
|
2331
|
+
if (request.query.error === 'access_denied') {
|
|
2332
|
+
let error = Boom.badRequest(
|
|
2333
|
+
request.app.gt.gettext('The sign-in was cancelled or the requested access was not granted. Open the account setup link again to retry.')
|
|
2334
|
+
);
|
|
2335
|
+
if (request.query.error_description) {
|
|
2336
|
+
error.output.payload.details = [String(request.query.error_description)];
|
|
2337
|
+
}
|
|
2275
2338
|
throw error;
|
|
2276
2339
|
}
|
|
2277
2340
|
|
|
2278
|
-
if (
|
|
2279
|
-
|
|
2280
|
-
let error = Boom.boomify(new Error(`Oauth failed: no code received`), { statusCode: 400 });
|
|
2281
|
-
throw error;
|
|
2341
|
+
if (request.query.error) {
|
|
2342
|
+
throw Boom.badRequest(util.format(request.app.gt.gettext('Sign-in with the email provider failed: %s'), request.query.error));
|
|
2282
2343
|
}
|
|
2283
2344
|
|
|
2284
|
-
if (
|
|
2285
|
-
|
|
2286
|
-
throw error;
|
|
2345
|
+
if (!request.query.code) {
|
|
2346
|
+
throw Boom.badRequest(request.app.gt.gettext('Sign-in with the email provider failed: no authorization code was received'));
|
|
2287
2347
|
}
|
|
2288
2348
|
|
|
2289
2349
|
// Validate nonce format: 16 bytes base64url encoded = 21-22 characters
|
|
2290
2350
|
// Also accept base64 encoding (+, /, =) for backward compatibility with old cached nonces
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
throw Boom.badRequest('Oauth failed: invalid state format');
|
|
2351
|
+
if (!/^account:add:[A-Za-z0-9_\-+/]{21,22}={0,2}$/.test(request.query.state)) {
|
|
2352
|
+
throw Boom.badRequest(request.app.gt.gettext('Sign-in with the email provider failed: the request state is not valid'));
|
|
2294
2353
|
}
|
|
2295
2354
|
|
|
2296
2355
|
let [[, accountData]] = await redis.multi().get(`${REDIS_PREFIX}${request.query.state}`).del(`${REDIS_PREFIX}${request.query.state}`).exec();
|
|
2297
2356
|
if (!accountData) {
|
|
2298
|
-
|
|
2299
|
-
|
|
2357
|
+
throw Boom.badRequest(
|
|
2358
|
+
request.app.gt.gettext('The account setup session has expired or was already used. Open the account setup link again to retry.')
|
|
2359
|
+
);
|
|
2300
2360
|
}
|
|
2301
2361
|
|
|
2302
2362
|
try {
|
|
2303
2363
|
accountData = JSON.parse(accountData);
|
|
2304
2364
|
} catch (E) {
|
|
2305
|
-
|
|
2306
|
-
throw error;
|
|
2365
|
+
throw Boom.badRequest(request.app.gt.gettext('Sign-in with the email provider failed: the stored setup session is not valid'));
|
|
2307
2366
|
}
|
|
2308
2367
|
|
|
2309
2368
|
if (!accountData.account) {
|
|
@@ -3099,6 +3158,11 @@ const init = async () => {
|
|
|
3099
3158
|
systemAlerts = systemAlerts.filter(alert => alert.level === 'danger');
|
|
3100
3159
|
}
|
|
3101
3160
|
|
|
3161
|
+
// Whether the requester holds a session at all, so a public page (the hosted form's
|
|
3162
|
+
// error page, for one) can tell a mailbox owner from an admin without reading
|
|
3163
|
+
// authData, which describes the instance rather than the requester
|
|
3164
|
+
const isAuthenticated = !!(request.auth && request.auth.isAuthenticated);
|
|
3165
|
+
|
|
3102
3166
|
return {
|
|
3103
3167
|
pageBrandName: pageBrandName || 'EmailEngine',
|
|
3104
3168
|
values: request.payload || {},
|
|
@@ -3108,6 +3172,10 @@ const init = async () => {
|
|
|
3108
3172
|
licenseDetails,
|
|
3109
3173
|
trialPossible: !tract,
|
|
3110
3174
|
authData,
|
|
3175
|
+
isAuthenticated,
|
|
3176
|
+
// The dashboard is an admin destination: a link to it belongs on a page only for
|
|
3177
|
+
// a requester who holds an admin session, or on an instance with no admin login
|
|
3178
|
+
showDashboardLink: isAuthenticated || !(authData && authData.enabled),
|
|
3111
3179
|
packageData,
|
|
3112
3180
|
systemAlerts,
|
|
3113
3181
|
embeddedTemplateHeader,
|
|
@@ -3139,14 +3207,16 @@ const init = async () => {
|
|
|
3139
3207
|
response = assertPreconditionResult;
|
|
3140
3208
|
}
|
|
3141
3209
|
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3210
|
+
// On error responses too: a client pacing itself by these headers needs them most on
|
|
3211
|
+
// the request that failed, and the JSON error path below copies output.headers over
|
|
3212
|
+
if (request.app.rateLimitHeaders) {
|
|
3213
|
+
const headers = response.isBoom ? response.output.headers : response.headers;
|
|
3214
|
+
for (let key of Object.keys(request.app.rateLimitHeaders)) {
|
|
3215
|
+
headers[key] = request.app.rateLimitHeaders[key].toString();
|
|
3148
3216
|
}
|
|
3217
|
+
}
|
|
3149
3218
|
|
|
3219
|
+
if (!response.isBoom) {
|
|
3150
3220
|
return h.continue;
|
|
3151
3221
|
}
|
|
3152
3222
|
|
|
@@ -3167,11 +3237,13 @@ const init = async () => {
|
|
|
3167
3237
|
}
|
|
3168
3238
|
|
|
3169
3239
|
if (error.output && error.output.statusCode === 401 && error.output.headers && /^Bearer/.test(error.output.headers['WWW-Authenticate'])) {
|
|
3170
|
-
// bearer auth failed
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
.code
|
|
3240
|
+
// bearer auth failed. The api-token strategy attaches the refusal reason as a code,
|
|
3241
|
+
// and it is the one field worth carrying into this rebuilt payload
|
|
3242
|
+
let payload = { statusCode: 401, error: 'Unauthorized', message: error.message };
|
|
3243
|
+
if (error.output.payload.code) {
|
|
3244
|
+
payload.code = error.output.payload.code;
|
|
3245
|
+
}
|
|
3246
|
+
return h.response(payload).header('WWW-Authenticate', error.output.headers['WWW-Authenticate']).code(error.output.statusCode);
|
|
3175
3247
|
}
|
|
3176
3248
|
|
|
3177
3249
|
const routeTags = (request.route && request.route.settings && request.route.settings.tags) || [];
|
|
@@ -3211,8 +3283,10 @@ const init = async () => {
|
|
|
3211
3283
|
|
|
3212
3284
|
server.ext('onPostAuth', async (request, h) => {
|
|
3213
3285
|
if (request.requireTotp) {
|
|
3214
|
-
//
|
|
3215
|
-
|
|
3286
|
+
// The password step is done and only the second factor is missing, so the session
|
|
3287
|
+
// goes to the TOTP prompt rather than back to the login form, which would ask for
|
|
3288
|
+
// the password again
|
|
3289
|
+
let url = new URL(`admin/totp`, 'http://localhost');
|
|
3216
3290
|
|
|
3217
3291
|
let nextUrl = (request.query && request.query.next) || (request.payload && request.payload.next) || false;
|
|
3218
3292
|
if (nextUrl) {
|
package/workers/imap.js
CHANGED
|
@@ -305,9 +305,38 @@ class ConnectionHandler {
|
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
// do not wait before returning as it may take forever
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
308
|
+
this.startConnection(account, accountObject, initOpts);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Runs init() without waiting for it. A client that retries its own init() (the API
|
|
313
|
+
* clients, see BaseClient.scheduleInitRetry()) gets another attempt when it fails on
|
|
314
|
+
* something other than a refused credential; a client that was replaced in the meantime
|
|
315
|
+
* is left alone when the timer fires
|
|
316
|
+
* @param {string} account - Account ID
|
|
317
|
+
* @param {Object} accountObject - Account instance holding the connection
|
|
318
|
+
* @param {Object} initOpts - Options passed to init()
|
|
319
|
+
*/
|
|
320
|
+
startConnection(account, accountObject, initOpts) {
|
|
321
|
+
const connection = accountObject.connection;
|
|
322
|
+
|
|
323
|
+
connection
|
|
324
|
+
.init(initOpts)
|
|
325
|
+
.then(() => connection.resetInitRetry())
|
|
326
|
+
.catch(err => {
|
|
327
|
+
logger.error({ msg: 'Failed to initialize account connection', account, err });
|
|
328
|
+
|
|
329
|
+
if (!connection.retriesInit || err.authenticationFailed) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
connection.scheduleInitRetry(() => {
|
|
334
|
+
if (this.accounts.get(account) !== accountObject) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
this.startConnection(account, accountObject, initOpts);
|
|
338
|
+
});
|
|
339
|
+
});
|
|
311
340
|
}
|
|
312
341
|
|
|
313
342
|
async deleteConnection(account) {
|
package/workers/smtp.js
CHANGED
|
@@ -40,6 +40,12 @@ const DEFAULT_EENGINE_TIMEOUT = 10 * 1000;
|
|
|
40
40
|
const MAX_SMTP_MESSAGE_SIZE = getByteSize(readEnvValue('EENGINE_MAX_SMTP_MESSAGE_SIZE') || config.smtp.maxMessageSize) || DEFAULT_MAX_SMTP_MESSAGE_SIZE;
|
|
41
41
|
const EENGINE_TIMEOUT = getDuration(readEnvValue('EENGINE_TIMEOUT') || config.service.commandTimeout) || DEFAULT_EENGINE_TIMEOUT;
|
|
42
42
|
|
|
43
|
+
// Every connection buffers its message in memory up to MAX_SMTP_MESSAGE_SIZE before it is queued,
|
|
44
|
+
// so the concurrent connection count is what bounds this worker's memory. Excess connections are
|
|
45
|
+
// refused with a 421, which any SMTP client retries. The default matches Postfix's smtpd limit.
|
|
46
|
+
const DEFAULT_SMTP_MAX_CLIENTS = 100;
|
|
47
|
+
const SMTP_MAX_CLIENTS = Number(readEnvValue('EENGINE_SMTP_MAX_CLIENTS') || config.smtp.maxClients) || DEFAULT_SMTP_MAX_CLIENTS;
|
|
48
|
+
|
|
43
49
|
const ACCOUNT_CACHE = new WeakMap();
|
|
44
50
|
|
|
45
51
|
let callQueue = new Map();
|
|
@@ -158,6 +164,7 @@ async function init() {
|
|
|
158
164
|
disableReverseLookup: true,
|
|
159
165
|
banner: 'EmailEngine MSA',
|
|
160
166
|
size: MAX_SMTP_MESSAGE_SIZE,
|
|
167
|
+
maxClients: SMTP_MAX_CLIENTS,
|
|
161
168
|
useProxy: await settings.get('smtpServerProxy')
|
|
162
169
|
};
|
|
163
170
|
|
package/workers/submit.js
CHANGED
|
@@ -43,6 +43,7 @@ const SUBMIT_QC = (readEnvValue('EENGINE_SUBMIT_QC') && Number(readEnvValue('EEN
|
|
|
43
43
|
const SUBMIT_DELAY = getDuration(readEnvValue('EENGINE_SUBMIT_DELAY') || config.submitDelay) || null;
|
|
44
44
|
|
|
45
45
|
const { shouldDiscardJob, willBeFinalAttempt, isFinalFailedAttempt } = require('../lib/delivery-error');
|
|
46
|
+
const { isAlreadySent } = require('../lib/submit-progress');
|
|
46
47
|
const { packRpcError, unpackRpcError } = require('../lib/worker-rpc-error');
|
|
47
48
|
|
|
48
49
|
let callQueue = new Map();
|
|
@@ -142,6 +143,29 @@ const submitWorker = new Worker(
|
|
|
142
143
|
job.data.queueId = job.data.qId;
|
|
143
144
|
}
|
|
144
145
|
|
|
146
|
+
// A job re-run after a stall (heartbeat kill, crash, a shutdown drain that could not cover
|
|
147
|
+
// a long SMTP transaction plus the Sent-folder upload) comes back with the progress its
|
|
148
|
+
// previous run stored. Once that says the MTA accepted the message, sending again would
|
|
149
|
+
// deliver a duplicate under the same queueId: the message is done, only the bookkeeping
|
|
150
|
+
// after the 250 was cut short. The catch below covers the same state for a run that got
|
|
151
|
+
// as far as throwing; this covers the run that never got to throw anything.
|
|
152
|
+
if (isAlreadySent(job.progress)) {
|
|
153
|
+
logger.info({
|
|
154
|
+
msg: 'Skipping re-run of an already sent message',
|
|
155
|
+
action: 'submit',
|
|
156
|
+
queue: job.queue.name,
|
|
157
|
+
code: 'result_success',
|
|
158
|
+
job: job.id,
|
|
159
|
+
event: job.name,
|
|
160
|
+
account: job.data.account,
|
|
161
|
+
queueId: job.data.queueId,
|
|
162
|
+
messageId: job.data.messageId,
|
|
163
|
+
progress: job.progress.status,
|
|
164
|
+
attemptsMade: job.attemptsMade
|
|
165
|
+
});
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
145
169
|
let queueEntryBuf = await redis.hgetBuffer(`${REDIS_PREFIX}iaq:${job.data.account}`, job.data.queueId);
|
|
146
170
|
if (!queueEntryBuf) {
|
|
147
171
|
// nothing to do here
|
|
@@ -231,7 +255,7 @@ const submitWorker = new Worker(
|
|
|
231
255
|
} catch (err) {
|
|
232
256
|
try {
|
|
233
257
|
const submitJobEntry = await submitQueue.getJob(job.id);
|
|
234
|
-
if (submitJobEntry &&
|
|
258
|
+
if (submitJobEntry && isAlreadySent(submitJobEntry.progress)) {
|
|
235
259
|
// SMTP transition succeeded, can accept even if the process yielded in error
|
|
236
260
|
logger.trace({
|
|
237
261
|
msg: 'Submitted queued message for delivery',
|
package/workers/webhooks.js
CHANGED
|
@@ -10,7 +10,16 @@ const { webhooks: Webhooks } = require('../lib/webhooks');
|
|
|
10
10
|
|
|
11
11
|
const { GooglePubSub } = require('../lib/oauth/pubsub/google');
|
|
12
12
|
|
|
13
|
-
const {
|
|
13
|
+
const {
|
|
14
|
+
readEnvValue,
|
|
15
|
+
threadStats,
|
|
16
|
+
getDuration,
|
|
17
|
+
httpAgent,
|
|
18
|
+
getServiceSecret,
|
|
19
|
+
maybeReloadHttpProxyAgent,
|
|
20
|
+
redactUrlCredentials,
|
|
21
|
+
splitUrlCredentials
|
|
22
|
+
} = require('../lib/tools');
|
|
14
23
|
const { sendWebhookRequest } = require('../lib/webhook-request');
|
|
15
24
|
const { willBeFinalAttempt, isFinalFailedAttempt } = require('../lib/delivery-error');
|
|
16
25
|
const { validateWebhookTarget } = require('../lib/webhook-egress');
|
|
@@ -24,7 +33,6 @@ const { Worker, UnrecoverableError } = require('bullmq');
|
|
|
24
33
|
const settings = require('../lib/settings');
|
|
25
34
|
|
|
26
35
|
const { REDIS_PREFIX, ACCOUNT_DELETED_NOTIFY, MESSAGE_NEW_NOTIFY } = require('../lib/consts');
|
|
27
|
-
const he = require('he');
|
|
28
36
|
|
|
29
37
|
const { fetch: fetchCmd } = require('undici');
|
|
30
38
|
|
|
@@ -393,21 +401,9 @@ const notifyWorker = new Worker(
|
|
|
393
401
|
'X-EE-Wh-Queued-Time': Math.round(Math.max(0, (Date.now() - job.timestamp) / 1000)) + 's'
|
|
394
402
|
};
|
|
395
403
|
|
|
396
|
-
let parsed =
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
if (parsed.username) {
|
|
400
|
-
username = he.decode(parsed.username);
|
|
401
|
-
parsed.username = '';
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
if (parsed.password) {
|
|
405
|
-
password = he.decode(parsed.password);
|
|
406
|
-
parsed.password = '';
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
if (username || password) {
|
|
410
|
-
headers.Authorization = `Basic ${Buffer.from(he.encode(username || '') + ':' + he.encode(password || '')).toString('base64')}`;
|
|
404
|
+
let { url: parsed, authorization } = splitUrlCredentials(webhooks);
|
|
405
|
+
if (authorization) {
|
|
406
|
+
headers.Authorization = authorization;
|
|
411
407
|
}
|
|
412
408
|
|
|
413
409
|
if (customRoute) {
|