emailengine-app 2.90.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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +29 -0
- package/Dockerfile +2 -2
- package/ENVIRONMENT.md +24 -23
- package/README.md +1 -1
- package/data/google-crawlers.json +1 -1
- package/lib/account-assignment.js +26 -9
- package/lib/account.js +38 -9
- package/lib/api-routes/account-routes.js +7 -0
- package/lib/autodetect-imap-settings.js +401 -64
- package/lib/consts.js +4 -0
- package/lib/email-client/imap-client.js +5 -5
- package/lib/email-client/message-builder.js +4 -5
- package/lib/imapproxy/imap-server.js +5 -5
- package/lib/logger-consts.js +37 -1
- package/lib/mail-probe.js +157 -0
- package/lib/oauth/mail-ru.js +9 -2
- package/lib/read-env-value.js +30 -6
- package/lib/redis-backend-warnings.js +70 -0
- package/lib/tools.js +17 -28
- package/lib/ui-routes/account-routes.js +34 -31
- package/lib/ui-routes/account-setup.js +1 -1
- 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/package.json +13 -13
- package/sbom.json +231 -260
- package/server.js +80 -1
- package/static/css/public.css +55 -1
- package/static/licenses.html +126 -148
- 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 +136 -89
- 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/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
|
@@ -16,7 +16,8 @@ const {
|
|
|
16
16
|
readEnvValue,
|
|
17
17
|
emitChangeEvent,
|
|
18
18
|
loadTlsConfig,
|
|
19
|
-
assertTlsCredentials
|
|
19
|
+
assertTlsCredentials,
|
|
20
|
+
getMailProxyUrl
|
|
20
21
|
} = require('../tools');
|
|
21
22
|
const { getLocalAddress } = require('../utils/network');
|
|
22
23
|
|
|
@@ -159,10 +160,9 @@ async function onAuth(auth, session) {
|
|
|
159
160
|
if (accountData.proxy) {
|
|
160
161
|
imapConfig.proxy = accountData.proxy;
|
|
161
162
|
} else {
|
|
162
|
-
let
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
imapConfig.proxy = proxyUrl;
|
|
163
|
+
let mailProxyUrl = await getMailProxyUrl();
|
|
164
|
+
if (mailProxyUrl && !imapConfig.proxy) {
|
|
165
|
+
imapConfig.proxy = mailProxyUrl;
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
|
package/lib/logger-consts.js
CHANGED
|
@@ -45,4 +45,40 @@ const REDACTED_LOG_KEYS = [
|
|
|
45
45
|
'err.input'
|
|
46
46
|
];
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
// An RFC 9110 field name (token). Anything else, such as an entry written as "Name: value", is
|
|
49
|
+
// refused rather than turned into a redaction path that never matches.
|
|
50
|
+
const HEADER_NAME = /^[!#$%&'*+.^_`|~0-9a-z-]+$/;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Turns the EENGINE_LOG_REDACT_HEADERS value into redaction paths for the request headers it lists.
|
|
54
|
+
* Node lowercases incoming header names, so the names are matched lowercase.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} [value] - Comma-separated header names
|
|
57
|
+
* @returns {string[]} pino redaction paths, one per distinct name
|
|
58
|
+
* @throws {Error} code `EnvValueInvalid` for an entry that is not a header name. The message names
|
|
59
|
+
* the position of the entry, never its text: an entry written as "Name: value" carries the very
|
|
60
|
+
* secret the variable exists to keep out of the log.
|
|
61
|
+
*/
|
|
62
|
+
function parseRedactHeaders(value) {
|
|
63
|
+
const names = new Set();
|
|
64
|
+
const entries = (value || '').split(',').map(entry => entry.trim().toLowerCase());
|
|
65
|
+
entries.forEach((name, i) => {
|
|
66
|
+
if (!name) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (!HEADER_NAME.test(name)) {
|
|
70
|
+
const error = new Error(`EENGINE_LOG_REDACT_HEADERS: entry ${i + 1} is not a valid header name`);
|
|
71
|
+
error.code = 'EnvValueInvalid';
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
names.add(name);
|
|
75
|
+
});
|
|
76
|
+
return [...names].map(name => `req.headers["${name}"]`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Read from process.env directly, not through readEnvValue(), because that helper logs through
|
|
80
|
+
// lib/logger.js, which loads this module. The main process resolves the _FILE form into
|
|
81
|
+
// process.env before anything loads the logger (see resolveEnvFiles()), and worker threads inherit it.
|
|
82
|
+
REDACTED_LOG_KEYS.push(...parseRedactHeaders(process.env.EENGINE_LOG_REDACT_HEADERS));
|
|
83
|
+
|
|
84
|
+
module.exports = { REDACTED_LOG_KEYS, TRANSIENT_NETWORK_CODES, parseRedactHeaders };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Checks whether a host runs a mail server, for the last autodiscovery stage: a domain that
|
|
4
|
+
// publishes nothing about its mail is often served by its MX host or an `imap.`/`smtp.` name, and
|
|
5
|
+
// the only way to tell is to connect and see what answers.
|
|
6
|
+
//
|
|
7
|
+
// The probe sends nothing but a TLS ClientHello and reads the first line the server volunteers. It
|
|
8
|
+
// never logs in and never writes to the stream, so a host that is not a mail server sees an
|
|
9
|
+
// ordinary TLS connection that closes.
|
|
10
|
+
|
|
11
|
+
const dns = require('dns').promises;
|
|
12
|
+
const tls = require('tls');
|
|
13
|
+
const { proxyConnection, detachEarlyErrorHandler } = require('imapflow/lib/proxy-connection.js');
|
|
14
|
+
const { assertAllowedUrl, createEgressLookup } = require('./egress-filter');
|
|
15
|
+
const { WEBHOOK_EGRESS_POLICY } = require('./webhook-egress');
|
|
16
|
+
const logger = require('./logger');
|
|
17
|
+
|
|
18
|
+
// Budget of one probe: name lookup, proxy negotiation, handshake and the greeting line. Short
|
|
19
|
+
// enough that the IMAP and the SMTP round of the fallback stage both fit its time budget.
|
|
20
|
+
const PROBE_TIMEOUT = 2 * 1000;
|
|
21
|
+
|
|
22
|
+
// A greeting is one line; a server that sends more than this without a newline is not one
|
|
23
|
+
const MAX_GREETING = 512;
|
|
24
|
+
|
|
25
|
+
// Keyed by port: 993 is IMAP over implicit TLS, 465 is SMTP submission over implicit TLS
|
|
26
|
+
const PROTOCOLS = {
|
|
27
|
+
993: { greeting: /^\* (?:OK|PREAUTH)\b/i, silentIsEnough: false },
|
|
28
|
+
// SMTP servers commonly hold the greeting back for several seconds to catch clients that talk
|
|
29
|
+
// first, longer than this probe waits. A completed handshake with a certificate valid for the
|
|
30
|
+
// name is then the answer on the submission port, where nothing but a mail server listens.
|
|
31
|
+
465: { greeting: /^220[ -]/, silentIsEnough: true }
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const probeLogger = logger.child({ component: 'mail-probe' });
|
|
35
|
+
|
|
36
|
+
const resolveAll = hostname => dns.lookup(hostname, { all: true });
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Opens the TLS connection and checks the certificate against the probed name.
|
|
40
|
+
*
|
|
41
|
+
* The probe's destinations come from the address domain's DNS, which a caller controls, so the
|
|
42
|
+
* autodiscovery egress policy applies. Directly, the policy-bound lookup is also the one the socket
|
|
43
|
+
* connects with, so the addresses vetted are the addresses connected to. Behind a proxy the proxy
|
|
44
|
+
* resolves the name again, so only the up-front check applies - the same rules, and the same
|
|
45
|
+
* limitation, as the HTTP lookups of autodiscovery.
|
|
46
|
+
*/
|
|
47
|
+
async function openTls(host, port, ctx) {
|
|
48
|
+
const policy = ctx.egressPolicy || WEBHOOK_EGRESS_POLICY;
|
|
49
|
+
const resolve = ctx.resolve || resolveAll;
|
|
50
|
+
const tlsOptions = Object.assign({ servername: host }, ctx.tlsOptions || {});
|
|
51
|
+
// Tests point the well-known ports at local servers; production never sets this
|
|
52
|
+
const connectPort = (ctx.ports && ctx.ports[port]) || port;
|
|
53
|
+
|
|
54
|
+
// Up front on both paths: a candidate can be an address literal (an MX or CNAME record may name
|
|
55
|
+
// `127.0.0.1` outright), and net.connect skips the lookup below for a literal
|
|
56
|
+
await assertAllowedUrl(`https://${host}:${connectPort}/`, { policy, resolve });
|
|
57
|
+
|
|
58
|
+
if (!ctx.proxyUrl) {
|
|
59
|
+
return tls.connect(Object.assign({ host, port: connectPort, lookup: createEgressLookup(policy, { resolve }) }, tlsOptions));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const socket = await proxyConnection(probeLogger, ctx.proxyUrl, host, connectPort, { connectionTimeout: ctx.timeout || PROBE_TIMEOUT });
|
|
63
|
+
if (!socket) {
|
|
64
|
+
throw new Error('Unsupported proxy protocol');
|
|
65
|
+
}
|
|
66
|
+
const secure = tls.connect(Object.assign({ socket }, tlsOptions));
|
|
67
|
+
// The TLS socket owns the raw one from here, and the error handler in readGreeting() covers both
|
|
68
|
+
detachEarlyErrorHandler(socket);
|
|
69
|
+
return secure;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Waits for the server's first line on an open TLS socket, and closes it either way.
|
|
74
|
+
*
|
|
75
|
+
* @returns {Promise<boolean>} Whether the line is the protocol's greeting
|
|
76
|
+
*/
|
|
77
|
+
function readGreeting(socket, protocol, timeout, signal) {
|
|
78
|
+
return new Promise(resolve => {
|
|
79
|
+
let settled = false;
|
|
80
|
+
let received = '';
|
|
81
|
+
let handshake = false;
|
|
82
|
+
|
|
83
|
+
const finish = result => {
|
|
84
|
+
if (settled) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
settled = true;
|
|
88
|
+
clearTimeout(timer);
|
|
89
|
+
if (signal) {
|
|
90
|
+
signal.removeEventListener('abort', onAbort);
|
|
91
|
+
}
|
|
92
|
+
socket.destroy();
|
|
93
|
+
resolve(result);
|
|
94
|
+
};
|
|
95
|
+
const onAbort = () => finish(false);
|
|
96
|
+
|
|
97
|
+
// A wall-clock limit rather than the socket's idle timeout, which a server trickling a byte
|
|
98
|
+
// at a time would keep resetting
|
|
99
|
+
const timer = setTimeout(() => finish(handshake && protocol.silentIsEnough), timeout);
|
|
100
|
+
timer.unref();
|
|
101
|
+
|
|
102
|
+
// A blocked address, a refused connection and a certificate that does not cover the name
|
|
103
|
+
// all land here
|
|
104
|
+
socket.on('error', () => finish(false));
|
|
105
|
+
socket.on('close', () => finish(false));
|
|
106
|
+
|
|
107
|
+
if (signal) {
|
|
108
|
+
if (signal.aborted) {
|
|
109
|
+
return finish(false);
|
|
110
|
+
}
|
|
111
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
socket.on('secureConnect', () => {
|
|
115
|
+
handshake = true;
|
|
116
|
+
});
|
|
117
|
+
socket.setEncoding('utf-8');
|
|
118
|
+
socket.on('data', chunk => {
|
|
119
|
+
received += chunk;
|
|
120
|
+
if (received.includes('\n') || received.length > MAX_GREETING) {
|
|
121
|
+
finish(protocol.greeting.test(received));
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Connects to a host over implicit TLS and checks the first line the server sends.
|
|
129
|
+
*
|
|
130
|
+
* @param {string} host - Name to probe
|
|
131
|
+
* @param {number} port - 993 for IMAP, 465 for SMTP
|
|
132
|
+
* @param {Object} [ctx] - `{ signal, proxyUrl }`, plus for tests `resolve` (a `dns.lookup`
|
|
133
|
+
* stand-in answering `[{ address, family }]`), `egressPolicy`, `tlsOptions` (merged into the TLS
|
|
134
|
+
* connect options), `ports` (993/465 mapped to other ports) and `timeout`
|
|
135
|
+
* @returns {Promise<boolean>} Whether a mail server of that protocol answered for the name
|
|
136
|
+
*/
|
|
137
|
+
async function probeMailServer(host, port, ctx) {
|
|
138
|
+
ctx = ctx || {};
|
|
139
|
+
const protocol = PROTOCOLS[port];
|
|
140
|
+
if (!protocol) {
|
|
141
|
+
throw new Error(`No probe for port ${port}`);
|
|
142
|
+
}
|
|
143
|
+
if (ctx.signal && ctx.signal.aborted) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
let socket;
|
|
148
|
+
try {
|
|
149
|
+
socket = await openTls(host, port, ctx);
|
|
150
|
+
} catch (err) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return await readGreeting(socket, protocol, ctx.timeout || PROBE_TIMEOUT, ctx.signal);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
module.exports = { probeMailServer };
|
package/lib/oauth/mail-ru.js
CHANGED
|
@@ -11,8 +11,14 @@ const checkForFlags = err => {
|
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
//
|
|
15
|
-
//
|
|
14
|
+
// Mail.ru answers both an unknown client ID and a wrong secret with the RFC 6749 invalid_client
|
|
15
|
+
// error and the same generic description, so the flag cannot say which of the two is wrong.
|
|
16
|
+
if (err.error === 'invalid_client') {
|
|
17
|
+
return {
|
|
18
|
+
message: 'Mail.ru rejected the OAuth client. Please verify the Client ID and Client Secret of your Mail.ru integration.',
|
|
19
|
+
code: 'MAILRU_INVALID_CLIENT'
|
|
20
|
+
};
|
|
21
|
+
}
|
|
16
22
|
|
|
17
23
|
return false;
|
|
18
24
|
};
|
|
@@ -294,3 +300,4 @@ class MailRuOauth {
|
|
|
294
300
|
|
|
295
301
|
module.exports.MailRuOauth = MailRuOauth;
|
|
296
302
|
module.exports.MAIL_RU_SCOPES = MAIL_RU_SCOPES;
|
|
303
|
+
module.exports.checkForFlags = checkForFlags;
|
package/lib/read-env-value.js
CHANGED
|
@@ -12,6 +12,20 @@ const Fs = require('fs');
|
|
|
12
12
|
let logger;
|
|
13
13
|
const getLogger = () => (logger = logger || require('./logger'));
|
|
14
14
|
|
|
15
|
+
// lib/logger.js reads its configuration (EENGINE_LOG_LEVEL, EENGINE_LOG_REDACT_HEADERS) once, when
|
|
16
|
+
// it loads, and the first record this module writes is what loads it. So while resolveEnvFiles()
|
|
17
|
+
// runs, records are held here and written only after every file has been read: otherwise a file
|
|
18
|
+
// listed before EENGINE_LOG_LEVEL_FILE would build the logger at the default level.
|
|
19
|
+
let heldRecords = null;
|
|
20
|
+
|
|
21
|
+
function log(level, entry) {
|
|
22
|
+
if (heldRecords) {
|
|
23
|
+
heldRecords.push({ level, entry });
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
getLogger()[level](entry);
|
|
27
|
+
}
|
|
28
|
+
|
|
15
29
|
// The keys that lib/db.js and lib/get-secret.js used to resolve through private copies of this
|
|
16
30
|
// function. Those copies stripped a single trailing newline and nothing else, so for a file carrying
|
|
17
31
|
// any other surrounding whitespace the value they produced is not the value this helper produces.
|
|
@@ -67,14 +81,14 @@ function readEnvValue(key) {
|
|
|
67
81
|
// the operator needs to find it, and the value is what the warning exists to protect.
|
|
68
82
|
const legacyValue = contents.replace(/\r?\n$/, '');
|
|
69
83
|
if (LEGACY_UNTRIMMED_KEYS.has(key) && value !== legacyValue) {
|
|
70
|
-
|
|
84
|
+
log('warn', {
|
|
71
85
|
msg: 'Environment value read from file carries whitespace that is now trimmed, so it resolves differently than in earlier releases. Set the variable itself rather than the file to keep the old value, as one given in the environment is used verbatim.',
|
|
72
86
|
key,
|
|
73
87
|
file
|
|
74
88
|
});
|
|
75
89
|
}
|
|
76
90
|
|
|
77
|
-
|
|
91
|
+
log('trace', { msg: 'Loaded environment value from file', key, file });
|
|
78
92
|
return value;
|
|
79
93
|
}
|
|
80
94
|
}
|
|
@@ -97,10 +111,20 @@ function hasEnvValue(key) {
|
|
|
97
111
|
* @throws {Error} code `EnvFileUnreadable` for the first file that can not be read
|
|
98
112
|
*/
|
|
99
113
|
function resolveEnvFiles() {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
114
|
+
heldRecords = [];
|
|
115
|
+
try {
|
|
116
|
+
for (const name of Object.keys(process.env)) {
|
|
117
|
+
const match = /^(EENGINE_[A-Z0-9_]+|REDIS_URL)_FILE$/.exec(name);
|
|
118
|
+
if (match) {
|
|
119
|
+
readEnvValue(match[1]);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} finally {
|
|
123
|
+
// Also when a file can not be read: the records of the files that were read still matter
|
|
124
|
+
const records = heldRecords;
|
|
125
|
+
heldRecords = null;
|
|
126
|
+
for (const { level, entry } of records) {
|
|
127
|
+
log(level, entry);
|
|
104
128
|
}
|
|
105
129
|
}
|
|
106
130
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Dashboard warnings about the kind of Redis server EmailEngine is connected to, derived from INFO.
|
|
4
|
+
// Pure, so the decisions can be tested without a Redis in each configuration.
|
|
5
|
+
//
|
|
6
|
+
// Redis Cluster is refused outright: EmailEngine's queues and Lua scripts touch keys in different hash
|
|
7
|
+
// slots, which a cluster rejects with CROSSSLOT, and a cluster refuses SELECT for any database but 0.
|
|
8
|
+
// That also covers Amazon MemoryDB and ElastiCache with cluster mode or the durability option, which
|
|
9
|
+
// always run as a cluster.
|
|
10
|
+
//
|
|
11
|
+
// Amazon ElastiCache without cluster mode works, but a node that has no replica does not reload its
|
|
12
|
+
// snapshot when AWS replaces it: the new node starts empty and every account is gone until someone
|
|
13
|
+
// restores a backup by hand. A primary with a connected replica fails over instead and keeps its data,
|
|
14
|
+
// so only the replica-less setup is flagged. Multi-AZ failover itself is not visible in INFO.
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Warning about a Redis Cluster backend
|
|
18
|
+
* @param {Object} redisInfo - Parsed INFO output
|
|
19
|
+
* @returns {Object|null} Warning entry, or null
|
|
20
|
+
*/
|
|
21
|
+
function clusterWarning(redisInfo) {
|
|
22
|
+
if (!(Number(redisInfo.cluster_enabled) > 0)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
key: 'cluster',
|
|
28
|
+
color: 'danger',
|
|
29
|
+
title: 'Redis compatibility warning',
|
|
30
|
+
details: ['EmailEngine is incompatible with a Redis Cluster setup.', 'Please switch to a standard Redis primary instance.']
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Warning about an Amazon ElastiCache primary that has no replica to fail over to
|
|
36
|
+
* @param {Object} redisInfo - Parsed INFO output
|
|
37
|
+
* @returns {Object|null} Warning entry, or null
|
|
38
|
+
*/
|
|
39
|
+
function elastiCacheWarning(redisInfo) {
|
|
40
|
+
if (!/Amazon ElastiCache/i.test(redisInfo.os || '') || Number(redisInfo.cluster_enabled) > 0) {
|
|
41
|
+
// not ElastiCache, or a cluster, which clusterWarning() already refuses
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (redisInfo.role !== 'master' || Number(redisInfo.connected_slaves) > 0) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
key: 'elasticache',
|
|
51
|
+
color: 'danger',
|
|
52
|
+
title: 'Amazon ElastiCache without a replica',
|
|
53
|
+
details: [
|
|
54
|
+
'This ElastiCache node has no replica. When AWS replaces a node without one, the new node starts empty, and EmailEngine loses every account until a backup is restored by hand.',
|
|
55
|
+
'Add at least one replica and enable Multi-AZ automatic failover, or switch to a standard Redis instance with persistence enabled.'
|
|
56
|
+
]
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* All backend warnings for the dashboard, in display order
|
|
62
|
+
* @param {Object} redisInfo - Parsed INFO output
|
|
63
|
+
* @returns {Object[]} Warning entries
|
|
64
|
+
*/
|
|
65
|
+
function redisBackendWarnings(redisInfo) {
|
|
66
|
+
redisInfo = redisInfo || {};
|
|
67
|
+
return [elastiCacheWarning(redisInfo), clusterWarning(redisInfo)].filter(Boolean);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = { redisBackendWarnings };
|
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,
|
|
@@ -22,7 +22,8 @@ const { imapMaxIdleTimeFormSchema, imapMaxIdleTimeFormValue } = require('./imap-
|
|
|
22
22
|
const { securityFormFields, securityFormValues } = require('./connection-security-form');
|
|
23
23
|
|
|
24
24
|
const { Gateway } = require('../gateway');
|
|
25
|
-
const {
|
|
25
|
+
const { resolveAppPassword, getAppPassword } = require('../autodetect-imap-settings');
|
|
26
|
+
const { listListedApps, renderProviderSignIn, microsoftSignInNotice, discoverServerSettings } = require('./provider-signin');
|
|
26
27
|
const { atomicIncrement } = require('../redis-operations');
|
|
27
28
|
const { OAUTH_REDIRECT_FORM_DIRECTIVES } = require('../security-headers');
|
|
28
29
|
const { oauth2Apps, oauth2ProviderData, SERVICE_ACCOUNT_PROVIDERS } = require('../oauth2-apps');
|
|
@@ -201,13 +202,13 @@ async function accountFormHandler(request, h) {
|
|
|
201
202
|
// Generate the url that will be used for the consent dialog.
|
|
202
203
|
|
|
203
204
|
let requestPayload = {
|
|
204
|
-
state: `account:add:${nonce}
|
|
205
|
+
state: `account:add:${nonce}`,
|
|
206
|
+
// Prefills the provider's sign-in form. Falls back to the address the visitor typed before
|
|
207
|
+
// the sign-in page offered this application: only a hint, never stored, so it needs no
|
|
208
|
+
// signature. The providers' clients skip an empty one.
|
|
209
|
+
email: accountData.email || request.payload.loginHint
|
|
205
210
|
};
|
|
206
211
|
|
|
207
|
-
if (accountData.email) {
|
|
208
|
-
requestPayload.email = accountData.email;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
212
|
// Service providers use client_credentials - no interactive authorization
|
|
212
213
|
if (SERVICE_ACCOUNT_PROVIDERS.has(oAuth2Client.provider)) {
|
|
213
214
|
throw Boom.badRequest('Application-only OAuth providers do not support interactive authorization');
|
|
@@ -232,7 +233,11 @@ async function accountFormHandler(request, h) {
|
|
|
232
233
|
// editable hint and mark it read-only. Cosmetic - the endpoints below enforce it.
|
|
233
234
|
email: expectedEmail || data.email,
|
|
234
235
|
emailPinned: !!expectedEmail,
|
|
235
|
-
name: data.name
|
|
236
|
+
name: data.name,
|
|
237
|
+
// Reached through a setup link minted for IMAP (`type=imap` on the GET) rather than
|
|
238
|
+
// through the provider picker: the visitor was never offered a choice, and is not
|
|
239
|
+
// sent to one when autodiscovery recognizes an OAuth2 provider
|
|
240
|
+
skipSignIn: request.method === 'get'
|
|
236
241
|
}
|
|
237
242
|
},
|
|
238
243
|
{
|
|
@@ -248,7 +253,10 @@ const firstPageSchema = Joi.object({
|
|
|
248
253
|
...signedBlobFields,
|
|
249
254
|
name: Joi.string().empty('').max(256).example('John Smith').description('Account Name'),
|
|
250
255
|
email: Joi.string().email().required().example('user@example.com').label('Email').description('Your account email'),
|
|
251
|
-
password: Joi.string().max(1024).min(1).required().example('secret').label('Password').description('Your account password')
|
|
256
|
+
password: Joi.string().max(1024).min(1).required().example('secret').label('Password').description('Your account password'),
|
|
257
|
+
// Skips the OAuth2 sign-in page: the setup link was minted for IMAP, or the visitor was already
|
|
258
|
+
// offered the sign-in and chose IMAP. Client-set, and all it chooses is that page.
|
|
259
|
+
skipSignIn: formBoolean().default(false)
|
|
252
260
|
});
|
|
253
261
|
|
|
254
262
|
// Shared IMAP/SMTP connection fields for the hosted form's /imap/test and /imap/server routes, so the
|
|
@@ -712,7 +720,7 @@ function registerPostAccountsNew(server) {
|
|
|
712
720
|
url.searchParams.append('sig', signature);
|
|
713
721
|
}
|
|
714
722
|
|
|
715
|
-
let oauth2apps =
|
|
723
|
+
let oauth2apps = await listListedApps();
|
|
716
724
|
|
|
717
725
|
if (!oauth2apps.length) {
|
|
718
726
|
url.searchParams.append('type', 'imap');
|
|
@@ -773,10 +781,7 @@ function registerGetHostedAccountsNew(server) {
|
|
|
773
781
|
// throws if check fails
|
|
774
782
|
await parseSignedFormData(redis, request.query, request.app.gt);
|
|
775
783
|
|
|
776
|
-
let oauth2apps =
|
|
777
|
-
oauth2apps.forEach(app => {
|
|
778
|
-
app.providerData = oauth2ProviderData(app.provider, app.cloud);
|
|
779
|
-
});
|
|
784
|
+
let oauth2apps = await listListedApps();
|
|
780
785
|
|
|
781
786
|
return h.view(
|
|
782
787
|
'accounts/register/index',
|
|
@@ -856,7 +861,8 @@ function registerPostHostedAccountsNew(server) {
|
|
|
856
861
|
.example('imap')
|
|
857
862
|
.description(
|
|
858
863
|
'Display the form for the specified account type (either "imap" or an OAuth2 app ID) instead of allowing the user to choose'
|
|
859
|
-
)
|
|
864
|
+
),
|
|
865
|
+
loginHint: Joi.string().email().empty('').max(256).description('Address to prefill on the OAuth2 provider sign-in form')
|
|
860
866
|
})
|
|
861
867
|
}
|
|
862
868
|
}
|
|
@@ -880,18 +886,7 @@ function registerPostHostedImap(server) {
|
|
|
880
886
|
return renderIdentityError(request, h, expectedEmail, request.payload.email);
|
|
881
887
|
}
|
|
882
888
|
|
|
883
|
-
|
|
884
|
-
try {
|
|
885
|
-
// The password the user just typed is passed along because hosted Exchange refuses
|
|
886
|
-
// to answer autodiscovery anonymously; it only ever reaches the autodiscovery host
|
|
887
|
-
// named by the address domain's own DNS, and only after that host has asked for it
|
|
888
|
-
serverSettings = await autodetectImapSettings(request.payload.email, request.app.gt, {
|
|
889
|
-
user: request.payload.email,
|
|
890
|
-
pass: request.payload.password
|
|
891
|
-
});
|
|
892
|
-
} catch (err) {
|
|
893
|
-
request.logger.debug({ msg: 'Failed to resolve email server settings', email: request.payload.email, err });
|
|
894
|
-
}
|
|
889
|
+
const serverSettings = await discoverServerSettings(request, data);
|
|
895
890
|
|
|
896
891
|
let values = Object.assign(
|
|
897
892
|
{
|
|
@@ -920,6 +915,11 @@ function registerPostHostedImap(server) {
|
|
|
920
915
|
setCachedAppPasswordHint(request.payload.email.split('@').pop().trim().toLowerCase(), serverSettings.appPassword);
|
|
921
916
|
}
|
|
922
917
|
|
|
918
|
+
const signIn = await renderProviderSignIn(request, h, serverSettings, values, data.n);
|
|
919
|
+
if (signIn.response) {
|
|
920
|
+
return signIn.response;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
923
|
// Nothing is left for the user to fill in: the settings page would auto-verify what is
|
|
924
924
|
// already there and wait for a click. hasCompleteServerSettings() (above, beside
|
|
925
925
|
// connectionFields) is what both that auto-verify and the skip below agree on.
|
|
@@ -952,7 +952,8 @@ function registerPostHostedImap(server) {
|
|
|
952
952
|
// page says why rather than looking like a form that forgot its defaults
|
|
953
953
|
autodetectFailed: !serverSettings,
|
|
954
954
|
autodetectDomain: request.payload.email.split('@').pop(),
|
|
955
|
-
autoTest: settingsComplete
|
|
955
|
+
autoTest: settingsComplete,
|
|
956
|
+
signInNotice: await microsoftSignInNotice(values, signIn.apps)
|
|
956
957
|
},
|
|
957
958
|
{
|
|
958
959
|
layout: 'public'
|
|
@@ -980,7 +981,7 @@ function registerPostHostedImap(server) {
|
|
|
980
981
|
});
|
|
981
982
|
}
|
|
982
983
|
|
|
983
|
-
await request.flash({ type: 'danger', message: request.app.gt.gettext("Couldn't set up account. Try again.") });
|
|
984
|
+
await request.flash({ type: 'danger', message: request.app.gt.gettext("Couldn't set up your account. Try again.") });
|
|
984
985
|
request.logger.debug({ msg: 'Failed to process account', err });
|
|
985
986
|
|
|
986
987
|
// Repopulate the form (crucially the signed data/sig blob) from what was submitted;
|
|
@@ -1133,7 +1134,8 @@ function registerPostHostedImapSettings(server) {
|
|
|
1133
1134
|
checkFailed: request.query.checkFailed,
|
|
1134
1135
|
// The check just failed, so do not repeat it on load: the page opens on the fields
|
|
1135
1136
|
// to correct rather than on a spinner about to give the same answer.
|
|
1136
|
-
autoTest: false
|
|
1137
|
+
autoTest: false,
|
|
1138
|
+
signInNotice: await microsoftSignInNotice(values)
|
|
1137
1139
|
},
|
|
1138
1140
|
{
|
|
1139
1141
|
layout: 'public'
|
|
@@ -1258,7 +1260,7 @@ function registerPostHostedImapServer(server, args) {
|
|
|
1258
1260
|
});
|
|
1259
1261
|
}
|
|
1260
1262
|
|
|
1261
|
-
await request.flash({ type: 'danger', message: request.app.gt.gettext("Couldn't set up account. Try again.") });
|
|
1263
|
+
await request.flash({ type: 'danger', message: request.app.gt.gettext("Couldn't set up your account. Try again.") });
|
|
1262
1264
|
request.logger.debug({ msg: 'Failed to process account', err });
|
|
1263
1265
|
|
|
1264
1266
|
// Rebuild the re-render values from the SAME schema that just validated the submission
|
|
@@ -1277,7 +1279,8 @@ function registerPostHostedImapServer(server, args) {
|
|
|
1277
1279
|
{
|
|
1278
1280
|
pageTitleFull: request.app.gt.gettext('Email Account Setup'),
|
|
1279
1281
|
errors,
|
|
1280
|
-
values
|
|
1282
|
+
values,
|
|
1283
|
+
signInNotice: await microsoftSignInNotice(values)
|
|
1281
1284
|
},
|
|
1282
1285
|
{
|
|
1283
1286
|
layout: 'public'
|
|
@@ -65,7 +65,7 @@ async function completeAccountSetup(request, { accountObject, accountData, nonce
|
|
|
65
65
|
// A Redis failure is not a consumed nonce. Report it as a retryable server error
|
|
66
66
|
// instead of misdiagnosing a valid setup URL as invalid or expired.
|
|
67
67
|
request.logger.error({ msg: 'Failed to claim nonce for an account form request', err });
|
|
68
|
-
throw Boom.boomify(new Error(gt.gettext('
|
|
68
|
+
throw Boom.boomify(new Error(gt.gettext('A temporary error occurred. Try again.')), { statusCode: 500 });
|
|
69
69
|
}
|
|
70
70
|
if (!claimed) {
|
|
71
71
|
// SET NX returned null: the nonce key already exists, so this URL was already used.
|