emailengine-app 2.89.0 → 2.91.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/.ncurc.js +19 -8
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +73 -0
- package/Dockerfile +7 -3
- package/ENVIRONMENT.md +24 -23
- package/README.md +1 -1
- package/bin/healthcheck.js +1 -1
- package/copy-static-files.sh +0 -8
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +1 -4
- package/lib/account/field-codec.js +396 -0
- package/lib/account-assignment.js +26 -9
- package/lib/account.js +196 -462
- package/lib/api-routes/account-routes.js +49 -6
- package/lib/api-routes/route-metadata.js +5 -2
- package/lib/api-routes/submit-routes.js +15 -2
- package/lib/api-token-auth.js +342 -274
- package/lib/arf-detect.js +174 -149
- package/lib/attachment-size.js +29 -0
- package/lib/autodetect-imap-settings.js +482 -296
- package/lib/consts.js +5 -5
- package/lib/db.js +1 -4
- package/lib/email-client/base-client.js +907 -780
- package/lib/email-client/gmail-client.js +557 -450
- package/lib/email-client/imap/cid-parts.js +61 -0
- package/lib/email-client/imap/mailbox.js +376 -422
- package/lib/email-client/imap/sync-operations.js +239 -178
- package/lib/email-client/imap-client.js +5 -5
- package/lib/email-client/message-builder.js +4 -5
- package/lib/email-client/new-message-steps.js +168 -2
- package/lib/email-client/outlook/graph-message.js +266 -0
- package/lib/email-client/outlook/subscription-expiry.js +30 -0
- package/lib/email-client/outlook-client.js +652 -808
- package/lib/get-raw-email.js +338 -232
- package/lib/get-secret.js +1 -4
- package/lib/imapproxy/imap-server.js +5 -5
- package/lib/license-subscription.js +60 -0
- package/lib/load-env.js +48 -0
- package/lib/logger-consts.js +37 -1
- package/lib/logger.js +1 -4
- package/lib/mail-probe.js +157 -0
- package/lib/mcp/tools.js +244 -207
- package/lib/metric-values.js +76 -0
- package/lib/metrics.js +320 -0
- package/lib/oauth/gmail.js +39 -120
- package/lib/oauth/http-request.js +195 -0
- package/lib/oauth/mail-ru.js +33 -60
- package/lib/oauth/outlook.js +37 -137
- package/lib/oauth/pubsub/google.js +176 -117
- package/lib/oauth2-apps.js +440 -463
- package/lib/openapi/build-document.js +10 -10
- package/lib/read-env-value.js +31 -7
- package/lib/redis-backend-warnings.js +70 -0
- package/lib/route-descriptors.js +78 -0
- package/lib/schemas.js +10 -1
- package/lib/sentry-integrations.js +299 -0
- package/lib/sentry.js +75 -27
- package/lib/sso-routes.js +249 -0
- package/lib/sso.js +29 -6
- package/lib/tools.js +17 -28
- package/lib/ui-routes/account-edit-form.js +198 -0
- package/lib/ui-routes/account-page.js +241 -0
- package/lib/ui-routes/account-routes.js +46 -349
- package/lib/ui-routes/account-setup.js +1 -1
- package/lib/ui-routes/auth-routes.js +10 -10
- package/lib/ui-routes/provider-signin.js +187 -0
- package/lib/ui-routes/route-helpers.js +1 -1
- package/lib/ui-routes/unsubscribe-routes.js +2 -2
- package/lib/ui-view-context.js +328 -0
- package/lib/utils/public-suffix.js +22 -101
- package/lib/web-safe-html.js +20 -7
- package/lib/worker-metrics.js +82 -0
- package/list-generate.js +2 -5
- package/package.json +28 -24
- package/sbom.json +360 -1030
- package/scripts/refresh-test-tokens.js +1 -1
- package/server.js +400 -677
- package/static/css/flyonui.css +1 -1
- package/static/css/public.css +55 -1
- package/static/css/src/app.tailwind.css +18 -0
- package/static/js/ee-client.js +2619 -645
- package/static/js/ui.js +12 -2
- package/static/licenses.html +224 -764
- package/translations/de.mo +0 -0
- package/translations/de.po +429 -390
- package/translations/en.mo +0 -0
- package/translations/en.po +342 -257
- package/translations/es.mo +0 -0
- package/translations/es.po +440 -395
- package/translations/et.mo +0 -0
- package/translations/et.po +425 -375
- package/translations/fr.mo +0 -0
- package/translations/fr.po +425 -383
- package/translations/it.mo +0 -0
- package/translations/it.po +441 -394
- package/translations/ja.mo +0 -0
- package/translations/ja.po +408 -335
- package/translations/messages.pot +188 -130
- package/translations/nl.mo +0 -0
- package/translations/nl.po +419 -382
- package/translations/pl.mo +0 -0
- package/translations/pl.po +425 -379
- package/translations/sv.mo +0 -0
- package/translations/sv.po +440 -388
- package/translations/tr.mo +0 -0
- package/translations/tr.po +441 -387
- package/views/account-identity-error.hbs +1 -1
- package/views/account-workspace-error.hbs +2 -2
- package/views/accounts/browse.hbs +19 -1
- package/views/accounts/register/imap-server.hbs +22 -7
- package/views/accounts/register/imap.hbs +3 -0
- package/views/accounts/register/index.hbs +1 -27
- package/views/accounts/register/provider-signin.hbs +58 -0
- package/views/oauth-scope-error.hbs +1 -1
- package/views/partials/provider_signin_button.hbs +30 -0
- package/views/queues/index.hbs +1 -1
- package/views/redirect.hbs +1 -1
- package/views/unsubscribe.hbs +6 -6
- package/workers/api.js +20 -451
- package/data/public_suffix_list.dat +0 -16698
package/lib/sentry.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const crypto = require('crypto');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const pathlib = require('path');
|
|
4
6
|
const packageData = require('../package.json');
|
|
5
7
|
const logger = require('./logger');
|
|
6
8
|
const { readEnvValue, httpAgent } = require('./tools');
|
|
@@ -30,7 +32,7 @@ const SENTRY_RELEASE = `${packageData.name}@${packageData.version}`;
|
|
|
30
32
|
// settings change applies to the next event without a restart. Only the two headers Sentry's
|
|
31
33
|
// rate limiting reads are handed back.
|
|
32
34
|
function makeTransport(options) {
|
|
33
|
-
const { createTransport } = require('@sentry/
|
|
35
|
+
const { createTransport } = require('@sentry/core');
|
|
34
36
|
|
|
35
37
|
return createTransport(options, async request => {
|
|
36
38
|
let res = await fetchCmd(options.url, {
|
|
@@ -53,39 +55,85 @@ function makeTransport(options) {
|
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
// The module name Sentry groups a frame under: the path below the last node_modules with dots for
|
|
59
|
+
// slashes, or below the application directory, then the file name without its extension
|
|
60
|
+
// ("@hapi.hapi.lib:server", "lib:tools"). The same rule @sentry/node-core applied.
|
|
61
|
+
function createGetModuleFromFilename(basePath = pathlib.join(__dirname, '..')) {
|
|
62
|
+
const toPosix = value => value.replace(/\\/g, '/');
|
|
63
|
+
const base = toPosix(basePath);
|
|
64
|
+
return filename => {
|
|
65
|
+
if (!filename) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
let { dir, name, ext } = pathlib.posix.parse(toPosix(filename));
|
|
69
|
+
let file = decodeURIComponent(['.js', '.mjs', '.cjs'].includes(ext) ? name : name + ext);
|
|
70
|
+
let index = dir.lastIndexOf('/node_modules');
|
|
71
|
+
if (index > -1) {
|
|
72
|
+
return `${dir.slice(index + 14).replace(/\//g, '.')}:${file}`;
|
|
73
|
+
}
|
|
74
|
+
if (dir.startsWith(base)) {
|
|
75
|
+
let moduleName = dir.slice(base.length + 1).replace(/\//g, '.');
|
|
76
|
+
return moduleName ? `${moduleName}:${file}` : file;
|
|
77
|
+
}
|
|
78
|
+
return file;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The client options EmailEngine starts Sentry with.
|
|
84
|
+
*
|
|
85
|
+
* @param {string} dsn
|
|
86
|
+
* @param {Object} [overrides] Replaces any option, e.g. the transport in the tests
|
|
87
|
+
* @returns {Object}
|
|
88
|
+
*/
|
|
89
|
+
function sentryOptions(dsn, overrides) {
|
|
90
|
+
const { createStackParser, eventFiltersIntegration, functionToStringIntegration, linkedErrorsIntegration } = require('@sentry/core');
|
|
91
|
+
const { nodeStackLineParser } = require('@sentry/core/server');
|
|
92
|
+
const { contextLinesIntegration, nodeContextIntegration, modulesIntegration } = require('./sentry-integrations');
|
|
65
93
|
|
|
66
|
-
|
|
94
|
+
return {
|
|
67
95
|
dsn,
|
|
68
96
|
release: SENTRY_RELEASE,
|
|
97
|
+
environment: readEnvValue('SENTRY_ENVIRONMENT') || 'production',
|
|
69
98
|
transport: makeTransport,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
99
|
+
stackParser: createStackParser(nodeStackLineParser(createGetModuleFromFilename())),
|
|
100
|
+
platform: 'node',
|
|
101
|
+
runtime: { name: 'node', version: process.version },
|
|
102
|
+
serverName: readEnvValue('SENTRY_NAME') || os.hostname(),
|
|
103
|
+
// Error capture only: no tracing ('static' also keeps ServerRuntimeClient from adding its
|
|
104
|
+
// span streaming integration), and none of the integrations that patch http/fetch/console
|
|
105
|
+
// on hot paths. Sentry's own uncaughtException/unhandledRejection handling is left out on
|
|
106
|
+
// purpose - it does not run in worker threads and does not guarantee a process exit, so
|
|
107
|
+
// lib/logger.js owns reporting and exiting instead.
|
|
108
|
+
traceLifecycle: 'static',
|
|
77
109
|
integrations: [
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
110
|
+
eventFiltersIntegration(),
|
|
111
|
+
functionToStringIntegration(),
|
|
112
|
+
linkedErrorsIntegration(),
|
|
113
|
+
contextLinesIntegration(),
|
|
114
|
+
nodeContextIntegration(),
|
|
115
|
+
modulesIntegration()
|
|
84
116
|
],
|
|
85
117
|
initialScope: {
|
|
86
118
|
tags: { worker: workerName }
|
|
87
|
-
}
|
|
88
|
-
|
|
119
|
+
},
|
|
120
|
+
...overrides
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function startSentry(dsn, overrides) {
|
|
125
|
+
// require lazily, the SDK is a few hundred modules in every worker thread, so only pay that
|
|
126
|
+
// cost when error tracking is actually enabled. EmailEngine builds its client from
|
|
127
|
+
// @sentry/core directly: @sentry/node-core, the light Node.js SDK it used before, has no 11.x,
|
|
128
|
+
// and @sentry/node 11 pulls the FSL-licensed Sentry CLI into the tree (see .ncurc.js).
|
|
129
|
+
if (!Sentry) {
|
|
130
|
+
Sentry = require('@sentry/core');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const { ServerRuntimeClient } = require('@sentry/core/server');
|
|
134
|
+
const options = sentryOptions(dsn, overrides);
|
|
135
|
+
Sentry.applySdkMetadata(options, 'node', ['core']);
|
|
136
|
+
Sentry.initAndBind(ServerRuntimeClient, options);
|
|
89
137
|
|
|
90
138
|
logger.notifyError = (err, opts) => {
|
|
91
139
|
let captureContext = {};
|
|
@@ -203,4 +251,4 @@ function initSentry(worker) {
|
|
|
203
251
|
setImmediate(checkSettings);
|
|
204
252
|
}
|
|
205
253
|
|
|
206
|
-
module.exports = { initSentry, makeTransport, licenseTag, SENTRY_RELEASE };
|
|
254
|
+
module.exports = { initSentry, makeTransport, licenseTag, SENTRY_RELEASE, startSentry, createGetModuleFromFilename };
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The admin SSO strategies (Okta through @hapi/bell's built-in provider, generic OIDC through a
|
|
4
|
+
// custom bell provider built by lib/sso.js) and their callback routes. Moved out of workers/api.js,
|
|
5
|
+
// which cannot be required from a test, so that the bell registration can be exercised on a real
|
|
6
|
+
// hapi server (test/sso-routes-test.js). Everything the registration reads from the worker is
|
|
7
|
+
// passed in.
|
|
8
|
+
|
|
9
|
+
const sso = require('./sso');
|
|
10
|
+
const { setAdminSession } = require('./tools');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {Object} SsoContext
|
|
14
|
+
* @property {boolean} secureCookie Whether the cookies are marked Secure
|
|
15
|
+
* @property {() => Promise<string>} getCookiePassword Password bell seals its state cookie with
|
|
16
|
+
* @property {() => Promise<URL>} getServiceRedirectUrl The public base URL the callbacks live under
|
|
17
|
+
* @property {() => Promise<number>} sessionPasswordVersion Stamped into the session, see workers/api.js
|
|
18
|
+
* @property {Object} logger
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
// A sign-in the IdP denied, or the user cancelled, comes back as an unauthenticated try-mode
|
|
22
|
+
// request. It gets the same flash-and-redirect the allow-list denial in the OIDC handler
|
|
23
|
+
// uses, so the user lands on the login form with a way to try again rather than on the
|
|
24
|
+
// generic error page with bell's raw message. The reason goes to the log only. ?sso_denied=1
|
|
25
|
+
// stops a forced instance from auto-redirecting straight back into the flow.
|
|
26
|
+
async function ssoFailureRedirect(request, h, method) {
|
|
27
|
+
request.logger.warn({
|
|
28
|
+
msg: 'SSO login failed',
|
|
29
|
+
method,
|
|
30
|
+
reason: (request.auth.error && request.auth.error.message) || 'unknown',
|
|
31
|
+
remoteAddress: request.app.ip
|
|
32
|
+
});
|
|
33
|
+
await request.flash({ type: 'danger', message: 'Single sign-on failed or was cancelled. Please try again' });
|
|
34
|
+
return h.redirect('/admin/login?sso_denied=1');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// The redirect URL is captured at strategy registration; the validators re-read it from settings
|
|
38
|
+
// so an origin change after startup (which would break the registered callback URL) disables the
|
|
39
|
+
// SSO button instead of failing mid-flow.
|
|
40
|
+
function originGuard(ctx, redirectUrl) {
|
|
41
|
+
return async () => (await ctx.getServiceRedirectUrl()).origin === redirectUrl.origin;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Registers the Okta strategy and its /admin/login/okta callback.
|
|
46
|
+
*
|
|
47
|
+
* @param {Object} server hapi server with @hapi/bell registered
|
|
48
|
+
* @param {SsoContext} ctx
|
|
49
|
+
* @param {{ baseUrl: string, clientId: string, clientSecret: string }} okta
|
|
50
|
+
*/
|
|
51
|
+
async function registerOktaAuth(server, ctx, okta) {
|
|
52
|
+
let redirectUrl = await ctx.getServiceRedirectUrl();
|
|
53
|
+
|
|
54
|
+
server.decorate('toolkit', 'validateOktaConfig', originGuard(ctx, redirectUrl));
|
|
55
|
+
|
|
56
|
+
server.auth.strategy('okta', 'bell', {
|
|
57
|
+
provider: 'okta',
|
|
58
|
+
config: {
|
|
59
|
+
uri: okta.baseUrl
|
|
60
|
+
},
|
|
61
|
+
password: await ctx.getCookiePassword(),
|
|
62
|
+
isSecure: ctx.secureCookie,
|
|
63
|
+
location: redirectUrl.origin,
|
|
64
|
+
|
|
65
|
+
clientId: okta.clientId,
|
|
66
|
+
clientSecret: okta.clientSecret
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
server.route({
|
|
70
|
+
method: ['GET', 'POST'],
|
|
71
|
+
path: '/admin/login/okta',
|
|
72
|
+
async handler(request, h) {
|
|
73
|
+
if (!request.auth.isAuthenticated) {
|
|
74
|
+
return ssoFailureRedirect(request, h, 'okta');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let profile = (request.auth.credentials && request.auth.credentials.profile) || {};
|
|
78
|
+
|
|
79
|
+
// The same minimal shape the OIDC branch below stores, for the same reasons: the
|
|
80
|
+
// full bell credentials carry the access and refresh tokens, the callback query
|
|
81
|
+
// and the raw userinfo document, none of which the session validator reads, and
|
|
82
|
+
// all of which would sit in the browser's cookie for the life of the session.
|
|
83
|
+
setAdminSession(request, {
|
|
84
|
+
provider: 'okta',
|
|
85
|
+
profile: {
|
|
86
|
+
id: profile.id,
|
|
87
|
+
username: profile.username,
|
|
88
|
+
displayName: profile.displayName,
|
|
89
|
+
email: profile.email
|
|
90
|
+
},
|
|
91
|
+
passwordVersion: await ctx.sessionPasswordVersion()
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
request.logger.info({ msg: 'Admin login successful', user: profile.username || 'unknown', method: 'okta', remoteAddress: request.app.ip });
|
|
95
|
+
return h.redirect('/admin');
|
|
96
|
+
},
|
|
97
|
+
options: {
|
|
98
|
+
auth: {
|
|
99
|
+
mode: 'try',
|
|
100
|
+
strategy: 'okta'
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Registers the generic OIDC strategy and its /admin/login/oidc callback.
|
|
108
|
+
*
|
|
109
|
+
* @param {Object} server hapi server with @hapi/bell registered
|
|
110
|
+
* @param {SsoContext} ctx
|
|
111
|
+
* @param {Object} oidc
|
|
112
|
+
* @param {Object} oidc.allowList parseAllowList() result
|
|
113
|
+
* @param {Object} oidc.allowGroups parseGroupList() result
|
|
114
|
+
* @param {() => Promise<Object>} [oidc.fetchDiscovery] Defaults to sso.fetchOidcDiscovery
|
|
115
|
+
* @param {() => Promise<Object>} [oidc.retryDiscovery] Defaults to sso.retryDiscovery
|
|
116
|
+
* @returns {Promise<{ retry: Promise<void>|null }>} The background retry, when the first discovery failed. Wrapped
|
|
117
|
+
* in an object because an async function returning the promise itself would hand the caller its result.
|
|
118
|
+
*/
|
|
119
|
+
async function registerOidcAuth(server, ctx, oidc) {
|
|
120
|
+
let { logger } = ctx;
|
|
121
|
+
let fetchDiscovery = oidc.fetchDiscovery || (() => sso.fetchOidcDiscovery());
|
|
122
|
+
let retryDiscovery =
|
|
123
|
+
oidc.retryDiscovery ||
|
|
124
|
+
(() =>
|
|
125
|
+
sso.retryDiscovery({
|
|
126
|
+
onError: (err, attempt) => logger.debug({ msg: 'OIDC discovery retry failed', issuer: sso.OIDC_ISSUER, attempt, err })
|
|
127
|
+
}));
|
|
128
|
+
|
|
129
|
+
let redirectUrl = await ctx.getServiceRedirectUrl();
|
|
130
|
+
let originUnchanged = originGuard(ctx, redirectUrl);
|
|
131
|
+
|
|
132
|
+
// The discovery document the strategy reads its endpoints from on every sign-in (bell takes
|
|
133
|
+
// functions for them). The strategy and its callback route are registered right away, whether
|
|
134
|
+
// or not discovery has succeeded yet, so nothing is ever added to the route table after the
|
|
135
|
+
// server has started. A failure to fetch the document (IdP outage or misconfig) must NOT take
|
|
136
|
+
// EmailEngine down - password and passkey login plus the REST API have to keep working - so
|
|
137
|
+
// SSO simply stays switched off until a later attempt succeeds: while this is null
|
|
138
|
+
// validateOidcConfig() offers no login button and does not trigger OIDC_FORCED, and a sign-in
|
|
139
|
+
// started anyway fails back to the login form.
|
|
140
|
+
let oidcDiscovery = null;
|
|
141
|
+
|
|
142
|
+
// Registered unconditionally so the login/security views can call it; returns
|
|
143
|
+
// false when discovery failed or the serviceUrl origin drifted from startup.
|
|
144
|
+
server.decorate('toolkit', 'validateOidcConfig', async () => !!oidcDiscovery && (await originUnchanged()));
|
|
145
|
+
|
|
146
|
+
// RP-initiated logout URL for the /admin/logout handler. Returns null unless
|
|
147
|
+
// OIDC_LOGOUT is enabled and the IdP advertised an end_session_endpoint.
|
|
148
|
+
// post_logout_redirect_uri is only sent when OIDC_POST_LOGOUT_REDIRECT_URI is
|
|
149
|
+
// configured (and registered at the IdP); otherwise the IdP shows its own
|
|
150
|
+
// logged-out page, so logout needs no IdP-side configuration.
|
|
151
|
+
server.decorate('toolkit', 'oidcLogoutUrl', idToken => {
|
|
152
|
+
if (!sso.OIDC_LOGOUT || !oidcDiscovery || !oidcDiscovery.end_session_endpoint) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
return sso.buildLogoutUrl(oidcDiscovery.end_session_endpoint, {
|
|
156
|
+
idToken,
|
|
157
|
+
clientId: sso.OIDC_CLIENT_ID,
|
|
158
|
+
postLogoutRedirectUri: sso.OIDC_POST_LOGOUT_REDIRECT_URI || undefined
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
server.auth.strategy('oidc', 'bell', {
|
|
163
|
+
provider: sso.buildOidcBellProvider(() => oidcDiscovery),
|
|
164
|
+
password: await ctx.getCookiePassword(),
|
|
165
|
+
isSecure: ctx.secureCookie,
|
|
166
|
+
location: redirectUrl.origin,
|
|
167
|
+
|
|
168
|
+
clientId: sso.OIDC_CLIENT_ID,
|
|
169
|
+
clientSecret: sso.OIDC_CLIENT_SECRET
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
server.route({
|
|
173
|
+
method: ['GET', 'POST'],
|
|
174
|
+
path: '/admin/login/oidc',
|
|
175
|
+
async handler(request, h) {
|
|
176
|
+
if (!request.auth.isAuthenticated) {
|
|
177
|
+
return ssoFailureRedirect(request, h, 'oidc');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
let profile = (request.auth.credentials && request.auth.credentials.profile) || {};
|
|
181
|
+
|
|
182
|
+
// Enforce the optional email/group allow-lists before establishing the session.
|
|
183
|
+
if (!sso.isAuthorized(profile, oidc.allowList, oidc.allowGroups)) {
|
|
184
|
+
request.logger.warn({
|
|
185
|
+
msg: 'OIDC login denied by allow-list',
|
|
186
|
+
user: profile.username || profile.email || 'unknown',
|
|
187
|
+
groups: profile.groups,
|
|
188
|
+
method: 'oidc',
|
|
189
|
+
remoteAddress: request.app.ip
|
|
190
|
+
});
|
|
191
|
+
await request.flash({ type: 'danger', message: 'Your account is not authorized to access this admin panel' });
|
|
192
|
+
// ?sso_denied=1 stops a forced instance from auto-redirecting back into the
|
|
193
|
+
// OIDC flow before the user can see the error.
|
|
194
|
+
return h.redirect('/admin/login?sso_denied=1');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Store only the minimal profile - not the full bell credentials. OIDC
|
|
198
|
+
// access/refresh tokens (e.g. Keycloak JWTs) can push the iron-sealed
|
|
199
|
+
// `ee` cookie past the ~4KB browser limit and cause a silent login loop.
|
|
200
|
+
// Group names are kept so the per-request authorization re-check works;
|
|
201
|
+
// the id_token is kept only as the logout id_token_hint (RP-initiated logout).
|
|
202
|
+
setAdminSession(request, {
|
|
203
|
+
provider: 'oidc',
|
|
204
|
+
profile: {
|
|
205
|
+
id: profile.id,
|
|
206
|
+
username: profile.username,
|
|
207
|
+
displayName: profile.displayName,
|
|
208
|
+
email: profile.email,
|
|
209
|
+
// Carried so the per-request isAuthorized() re-check enforces email
|
|
210
|
+
// verification the same way the login gate above does.
|
|
211
|
+
emailVerified: profile.emailVerified,
|
|
212
|
+
groups: profile.groups
|
|
213
|
+
},
|
|
214
|
+
passwordVersion: await ctx.sessionPasswordVersion(),
|
|
215
|
+
idToken: (request.auth.artifacts && request.auth.artifacts.id_token) || null
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
request.logger.info({ msg: 'Admin login successful', user: profile.username || 'unknown', method: 'oidc', remoteAddress: request.app.ip });
|
|
219
|
+
return h.redirect('/admin');
|
|
220
|
+
},
|
|
221
|
+
options: {
|
|
222
|
+
auth: {
|
|
223
|
+
mode: 'try',
|
|
224
|
+
strategy: 'oidc'
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
oidcDiscovery = await fetchDiscovery().catch(err => {
|
|
230
|
+
logger.error({ msg: 'OIDC SSO disabled for now: discovery failed, retrying in the background', issuer: sso.OIDC_ISSUER, err });
|
|
231
|
+
return null;
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
if (oidcDiscovery) {
|
|
235
|
+
return { retry: null };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Deliberately not awaited by the caller - this runs for as long as the IdP is unreachable.
|
|
239
|
+
// A later success brings SSO up in place, with no restart and no route added after start.
|
|
240
|
+
let retry = retryDiscovery()
|
|
241
|
+
.then(retriedDoc => {
|
|
242
|
+
oidcDiscovery = retriedDoc;
|
|
243
|
+
logger.info({ msg: 'OIDC SSO enabled after retrying discovery', issuer: sso.OIDC_ISSUER });
|
|
244
|
+
})
|
|
245
|
+
.catch(err => logger.error({ msg: 'OIDC SSO disabled: discovery retry failed', issuer: sso.OIDC_ISSUER, err }));
|
|
246
|
+
return { retry };
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
module.exports = { registerOktaAuth, registerOidcAuth };
|
package/lib/sso.js
CHANGED
|
@@ -363,22 +363,45 @@ function buildLogoutUrl(endSessionEndpoint, options) {
|
|
|
363
363
|
return url.toString();
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
-
|
|
367
|
-
|
|
366
|
+
/**
|
|
367
|
+
* Builds a @hapi/bell custom OAuth2 provider for the OIDC identity provider.
|
|
368
|
+
*
|
|
369
|
+
* The endpoints are read from the discovery document on every sign-in rather than fixed when the
|
|
370
|
+
* strategy is registered (bell takes functions for them since 13.2), so the strategy and its
|
|
371
|
+
* callback route can be registered at boot before discovery has succeeded. Until a document is
|
|
372
|
+
* available a sign-in fails with an error instead of reaching an IdP endpoint; the login button is
|
|
373
|
+
* not offered then anyway (validateOidcConfig()).
|
|
374
|
+
*
|
|
375
|
+
* @param {() => Object|null} getDocument Returns the current validated discovery document, null while
|
|
376
|
+
* discovery has not succeeded
|
|
377
|
+
* @param {Object} [options]
|
|
378
|
+
* @param {string} [options.scopes] Scope override
|
|
379
|
+
* @param {string} [options.groupsClaim] Claim the groups are read from
|
|
380
|
+
*/
|
|
381
|
+
function buildOidcBellProvider(getDocument, options) {
|
|
368
382
|
options = options || {};
|
|
369
383
|
let scopes = parseScopes(options.scopes || OIDC_SCOPES);
|
|
370
384
|
let groupsClaim = options.groupsClaim || OIDC_GROUPS_CLAIM;
|
|
371
|
-
|
|
385
|
+
|
|
386
|
+
let endpoint = name => {
|
|
387
|
+
let doc = getDocument();
|
|
388
|
+
if (!doc || !doc[name]) {
|
|
389
|
+
let err = new Error('OIDC discovery document is not available yet');
|
|
390
|
+
err.code = 'OidcDiscoveryUnavailable';
|
|
391
|
+
throw err;
|
|
392
|
+
}
|
|
393
|
+
return doc[name];
|
|
394
|
+
};
|
|
372
395
|
|
|
373
396
|
return {
|
|
374
397
|
protocol: 'oauth2',
|
|
375
398
|
useParamsAuth: true,
|
|
376
399
|
pkce: 'S256',
|
|
377
|
-
auth:
|
|
378
|
-
token:
|
|
400
|
+
auth: () => endpoint('authorization_endpoint'),
|
|
401
|
+
token: () => endpoint('token_endpoint'),
|
|
379
402
|
scope: scopes,
|
|
380
403
|
profile: async (credentials, params, get) => {
|
|
381
|
-
let userinfo = await get(
|
|
404
|
+
let userinfo = await get(endpoint('userinfo_endpoint'));
|
|
382
405
|
credentials.profile = mapUserinfoProfile(userinfo, groupsClaim);
|
|
383
406
|
}
|
|
384
407
|
};
|
package/lib/tools.js
CHANGED
|
@@ -8,6 +8,7 @@ const { filterEmptyObjectValues } = require('./utils/filter-empty');
|
|
|
8
8
|
const msgpack = require('./msgpack');
|
|
9
9
|
const enumMessageFlags = require('./enum-message-flags');
|
|
10
10
|
const { redisMemoryWarnings } = require('./redis-memory-warnings');
|
|
11
|
+
const { redisBackendWarnings } = require('./redis-backend-warnings');
|
|
11
12
|
const Joi = require('joi');
|
|
12
13
|
const packageData = require('../package.json');
|
|
13
14
|
const { TLS_CERTIFICATE_SETTINGS } = require('./tls/listeners');
|
|
@@ -427,6 +428,14 @@ function resolveHttpProxy(values, readEnv = readEnvValue) {
|
|
|
427
428
|
return null;
|
|
428
429
|
}
|
|
429
430
|
|
|
431
|
+
// The instance-wide proxy that IMAP and SMTP connections take (and the autodiscovery probe, which
|
|
432
|
+
// stands in for one), or null for direct connections. An account's own `proxy` overrides it.
|
|
433
|
+
async function getMailProxyUrl() {
|
|
434
|
+
const proxyUrl = await settings.get('proxyUrl');
|
|
435
|
+
const proxyEnabled = await settings.get('proxyEnabled');
|
|
436
|
+
return proxyEnabled && proxyUrl ? proxyUrl : null;
|
|
437
|
+
}
|
|
438
|
+
|
|
430
439
|
async function _doReloadHttpProxyAgent() {
|
|
431
440
|
let values;
|
|
432
441
|
try {
|
|
@@ -1802,8 +1811,7 @@ module.exports = {
|
|
|
1802
1811
|
// Connect and greeting budget for both probes, in ms
|
|
1803
1812
|
const VERIFY_TIMEOUT = 30 * 1000;
|
|
1804
1813
|
|
|
1805
|
-
let
|
|
1806
|
-
let proxyEnabled = await settings.get('proxyEnabled');
|
|
1814
|
+
let mailProxyUrl = await getMailProxyUrl();
|
|
1807
1815
|
|
|
1808
1816
|
let verifyPromises = [];
|
|
1809
1817
|
|
|
@@ -1836,8 +1844,8 @@ module.exports = {
|
|
|
1836
1844
|
// set up proxy if needed
|
|
1837
1845
|
if (accountData.proxy) {
|
|
1838
1846
|
imapConfig.proxy = accountData.proxy;
|
|
1839
|
-
} else if (
|
|
1840
|
-
imapConfig.proxy =
|
|
1847
|
+
} else if (mailProxyUrl && !imapConfig.proxy) {
|
|
1848
|
+
imapConfig.proxy = mailProxyUrl;
|
|
1841
1849
|
}
|
|
1842
1850
|
|
|
1843
1851
|
if (logger) {
|
|
@@ -1958,8 +1966,8 @@ module.exports = {
|
|
|
1958
1966
|
// set up proxy if needed
|
|
1959
1967
|
if (accountData.proxy) {
|
|
1960
1968
|
smtpConfig.proxy = accountData.proxy;
|
|
1961
|
-
} else if (
|
|
1962
|
-
smtpConfig.proxy =
|
|
1969
|
+
} else if (mailProxyUrl && !smtpConfig.proxy) {
|
|
1970
|
+
smtpConfig.proxy = mailProxyUrl;
|
|
1963
1971
|
}
|
|
1964
1972
|
|
|
1965
1973
|
if (accountData.smtpEhloName) {
|
|
@@ -2302,28 +2310,8 @@ module.exports = {
|
|
|
2302
2310
|
redisSoftware = 'memorydb';
|
|
2303
2311
|
}
|
|
2304
2312
|
|
|
2305
|
-
//
|
|
2306
|
-
|
|
2307
|
-
redisWarnings.push({
|
|
2308
|
-
key: 'elasticache',
|
|
2309
|
-
color: 'danger',
|
|
2310
|
-
title: 'Redis compatibility warning',
|
|
2311
|
-
details: [
|
|
2312
|
-
'EmailEngine is incompatible with Amazon ElastiCache as the database backend.',
|
|
2313
|
-
'Please switch to a standard Redis instance. Using ElastiCache with EmailEngine can result in data loss and some features may not work correctly.'
|
|
2314
|
-
]
|
|
2315
|
-
});
|
|
2316
|
-
}
|
|
2317
|
-
|
|
2318
|
-
// Incompatible backend: Redis Cluster
|
|
2319
|
-
if (redisCluster) {
|
|
2320
|
-
redisWarnings.push({
|
|
2321
|
-
key: 'cluster',
|
|
2322
|
-
color: 'danger',
|
|
2323
|
-
title: 'Redis compatibility warning',
|
|
2324
|
-
details: ['EmailEngine is incompatible with a Redis Cluster setup.', 'Please switch to a standard Redis primary instance.']
|
|
2325
|
-
});
|
|
2326
|
-
}
|
|
2313
|
+
// Redis Cluster and a replica-less ElastiCache node, see lib/redis-backend-warnings.js
|
|
2314
|
+
redisWarnings.push(...redisBackendWarnings(redisInfo));
|
|
2327
2315
|
|
|
2328
2316
|
// Eviction and the maxmemory limit, see lib/redis-memory-warnings.js
|
|
2329
2317
|
redisWarnings.push(...redisMemoryWarnings(redisInfo));
|
|
@@ -3111,6 +3099,7 @@ module.exports = {
|
|
|
3111
3099
|
reloadHttpProxyAgent,
|
|
3112
3100
|
maybeReloadHttpProxyAgent,
|
|
3113
3101
|
resolveHttpProxy,
|
|
3102
|
+
getMailProxyUrl,
|
|
3114
3103
|
createSocksAgent,
|
|
3115
3104
|
|
|
3116
3105
|
LRUCache,
|