emailengine-app 2.77.0 → 2.79.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/test.yml +80 -0
- package/.ncurc.js +23 -13
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +60 -0
- package/bin/emailengine.js +1 -1
- package/config/e2e.toml +2 -1
- package/config/test.toml +2 -1
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +1 -1
- package/lib/account/expected-identity.js +88 -0
- package/lib/account.js +145 -61
- package/lib/api-reference/format.js +105 -4
- package/lib/api-reference/index.js +24 -7
- package/lib/api-reference/model.js +148 -21
- package/lib/api-reference/schema-tree.js +282 -28
- package/lib/api-routes/account-routes.js +99 -36
- package/lib/api-routes/behavior-notes.js +3 -0
- package/lib/api-routes/blocklist-routes.js +21 -47
- package/lib/api-routes/chat-routes.js +10 -12
- package/lib/api-routes/delivery-test-routes.js +6 -26
- package/lib/api-routes/export-routes.js +2 -0
- package/lib/api-routes/gateway-routes.js +52 -11
- package/lib/api-routes/license-routes.js +2 -0
- package/lib/api-routes/mailbox-routes.js +29 -26
- package/lib/api-routes/message-routes.js +27 -21
- package/lib/api-routes/oauth2-app-routes.js +11 -29
- package/lib/api-routes/operation-impact.js +80 -0
- package/lib/api-routes/outbox-routes.js +15 -5
- package/lib/api-routes/permission-map.js +397 -0
- package/lib/api-routes/route-helpers.js +223 -9
- package/lib/api-routes/route-metadata.js +28 -0
- package/lib/api-routes/settings-routes.js +30 -25
- package/lib/api-routes/stats-routes.js +2 -2
- package/lib/api-routes/submit-routes.js +53 -31
- package/lib/api-routes/template-routes.js +3 -0
- package/lib/api-routes/token-routes.js +319 -33
- package/lib/api-routes/webhook-route-routes.js +14 -4
- package/lib/append-list.js +3 -14
- package/lib/arf-detect.js +23 -1
- package/lib/auth-token.js +80 -8
- package/lib/autodetect-imap-settings.js +40 -16
- package/lib/base32.js +30 -0
- package/lib/bounce-detect.js +182 -62
- package/lib/consts.js +10 -0
- package/lib/db.js +20 -2
- package/lib/delivery-error.js +30 -1
- package/lib/egress-filter.js +89 -8
- package/lib/email-client/base-client.js +35 -113
- package/lib/email-client/gmail-client.js +22 -13
- package/lib/email-client/imap/listing-diff.js +3 -3
- package/lib/email-client/imap/mailbox.js +28 -93
- package/lib/email-client/imap/subconnection.js +10 -7
- package/lib/email-client/imap/sync-operations.js +46 -46
- package/lib/email-client/imap-client.js +39 -28
- package/lib/email-client/message-builder.js +15 -15
- package/lib/email-client/notification-handler.js +1 -1
- package/lib/email-client/outlook/graph-api.js +10 -4
- package/lib/email-client/outlook-client.js +54 -55
- package/lib/email-client/smtp-pool-manager.js +1 -1
- package/lib/enum-descriptions.js +92 -2
- package/lib/export.js +2 -2
- package/lib/field-usage.js +133 -0
- package/lib/gateway.js +2 -2
- package/lib/get-raw-email.js +1 -1
- package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +3 -3
- package/lib/imapproxy/imap-core/lib/commands/id.js +2 -13
- package/lib/imapproxy/imap-core/lib/commands/starttls.js +1 -1
- package/lib/imapproxy/imap-core/lib/imap-command.js +21 -5
- package/lib/imapproxy/imap-core/lib/imap-connection.js +17 -7
- package/lib/imapproxy/imap-core/lib/imap-server.js +2 -2
- package/lib/imapproxy/imap-server.js +40 -10
- package/lib/license-beacon.js +5 -10
- package/lib/lists.js +49 -1
- package/lib/llm-pre-process.js +6 -6
- package/lib/logger.js +5 -1
- package/lib/metrics-collector.js +2 -2
- package/lib/msgpack.js +62 -0
- package/lib/oauth/decode-jwt-payload.js +39 -0
- package/lib/oauth/gmail.js +9 -12
- package/lib/oauth/mail-ru.js +5 -7
- package/lib/oauth/outlook-identity.js +61 -0
- package/lib/oauth/outlook.js +9 -9
- package/lib/oauth/pubsub/google.js +25 -10
- package/lib/oauth/retry-setup.js +38 -0
- package/lib/oauth/scope-checker.js +1 -1
- package/lib/oauth2-apps.js +224 -295
- package/lib/openapi/build-document.js +15 -7
- package/lib/openapi/joi-schema.js +20 -0
- package/lib/outbox.js +145 -14
- package/lib/pre-process.js +9 -9
- package/lib/queue-stats.js +49 -0
- package/lib/read-env-value.js +37 -0
- package/lib/reconnection-manager.js +2 -2
- package/lib/rewrite-text-nodes.js +4 -3
- package/lib/routes-ui.js +4 -0
- package/lib/schemas.js +223 -155
- package/lib/settings.js +84 -5
- package/lib/sub-script.js +2 -1
- package/lib/swagger-options.js +2 -1
- package/lib/templates.js +5 -5
- package/lib/threads.js +2 -2
- package/lib/token-audit-log.js +208 -0
- package/lib/token-permission-view.js +219 -0
- package/lib/token-permissions.js +172 -0
- package/lib/tokens.js +100 -16
- package/lib/tools.js +259 -85
- package/lib/totp.js +67 -0
- package/lib/ui-routes/account-routes.js +122 -26
- package/lib/ui-routes/admin-config-routes.js +20 -17
- package/lib/ui-routes/admin-entities-routes.js +66 -22
- package/lib/ui-routes/auth-routes.js +36 -48
- package/lib/ui-routes/export-routes.js +10 -4
- package/lib/ui-routes/oauth-config-routes.js +5 -5
- package/lib/ui-routes/reference-routes.js +11 -8
- package/lib/ui-routes/route-helpers.js +79 -2
- package/lib/ui-routes/settings-page.js +1 -1
- package/lib/ui-routes/smtp-test-routes.js +1 -1
- package/lib/ui-routes/suppression-list-routes.js +294 -0
- package/lib/ui-routes/unsubscribe-routes.js +19 -29
- package/lib/utils/is-email.js +34 -0
- package/lib/utils/network.js +2 -2
- package/lib/utils/to-camel-case.js +17 -0
- package/lib/web-safe-html.js +1 -1
- package/lib/webhook-egress.js +37 -0
- package/lib/webhook-routing.js +80 -0
- package/lib/webhooks.js +21 -15
- package/package.json +26 -27
- package/sbom.json +1 -0
- package/server.js +81 -42
- package/static/css/flyonui.css +1 -1
- package/static/css/public.css +3 -0
- package/static/css/src/app.tailwind.css +159 -9
- package/static/js/app.js +69 -0
- package/static/js/reference.js +741 -10
- package/static/js/ui.js +43 -0
- package/static/licenses.html +698 -1590
- package/translations/README.md +64 -0
- package/translations/de.mo +0 -0
- package/translations/de.po +164 -120
- package/translations/en.po +200 -161
- package/translations/et.mo +0 -0
- package/translations/et.po +163 -120
- package/translations/fr.mo +0 -0
- package/translations/fr.po +163 -120
- package/translations/ja.mo +0 -0
- package/translations/ja.po +163 -120
- package/translations/messages.pot +94 -64
- package/translations/nl.mo +0 -0
- package/translations/nl.po +164 -120
- package/translations/pl.mo +0 -0
- package/translations/pl.po +163 -120
- package/views/account-identity-error.hbs +34 -0
- package/views/accounts/account.hbs +69 -7
- package/views/accounts/browse.hbs +18 -35
- package/views/accounts/edit.hbs +1 -0
- package/views/accounts/register/imap.hbs +12 -2
- package/views/config/logging.hbs +6 -0
- package/views/config/oauth/app.hbs +0 -2
- package/views/config/security.hbs +13 -0
- package/views/layout/app.hbs +29 -5
- package/views/oauth-scope-error.hbs +1 -1
- package/views/partials/oauth_form.hbs +0 -15
- package/views/partials/reference/disclosure.hbs +8 -2
- package/views/partials/reference/nav.hbs +36 -9
- package/views/partials/reference/operation.hbs +48 -14
- package/views/partials/reference/params.hbs +17 -1
- package/views/partials/reference/schema-node.hbs +112 -54
- package/views/partials/reference/schema-tools.hbs +25 -0
- package/views/partials/reference/token-alert.hbs +35 -10
- package/views/partials/reference/try-it.hbs +84 -11
- package/views/partials/side_menu.hbs +1 -0
- package/views/partials/ui/checkbox.hbs +2 -2
- package/views/partials/ui/tabs.hbs +7 -1
- package/views/reference/index.hbs +1 -1
- package/views/reference/token.hbs +4 -0
- package/views/suppression-lists/index.hbs +85 -0
- package/views/suppression-lists/list.hbs +87 -0
- package/views/templates/index.hbs +8 -2
- package/views/tokens/index.hbs +31 -4
- package/views/tokens/new.hbs +324 -2
- package/workers/api.js +299 -140
- package/workers/documents.js +46 -26
- package/workers/export.js +20 -8
- package/workers/imap-proxy.js +2 -2
- package/workers/imap.js +13 -7
- package/workers/smtp.js +13 -7
- package/workers/submit.js +41 -31
- package/workers/webhooks.js +60 -37
- package/lib/feature-flags.js +0 -48
|
@@ -7,14 +7,16 @@ const settings = require('../settings');
|
|
|
7
7
|
const tokens = require('../tokens');
|
|
8
8
|
const { redis } = require('../db');
|
|
9
9
|
const getSecret = require('../get-secret');
|
|
10
|
-
const { failAction, verifyAccountInfo } = require('../tools');
|
|
11
|
-
const { templateSchemas, accountIdSchema } = require('../schemas');
|
|
10
|
+
const { failAction, verifyAccountInfo, formatPartialSecretKey } = require('../tools');
|
|
11
|
+
const { templateSchemas, accountIdSchema, tokenPermissionsSchema } = require('../schemas');
|
|
12
|
+
const tokenPermissionView = require('../token-permission-view');
|
|
12
13
|
const { Account } = require('../account');
|
|
13
14
|
const { Gateway } = require('../gateway');
|
|
14
15
|
const { templates } = require('../templates');
|
|
15
16
|
const { webhooks } = require('../webhooks');
|
|
16
17
|
const consts = require('../consts');
|
|
17
18
|
const wellKnownServices = require('nodemailer/lib/well-known/services.json');
|
|
19
|
+
const { authAwareLevel } = require('./route-helpers');
|
|
18
20
|
const exampleWebhookPayloads = require('../payload-examples-webhooks.json');
|
|
19
21
|
|
|
20
22
|
const { DEFAULT_PAGE_SIZE } = consts;
|
|
@@ -301,7 +303,7 @@ return payload;`)
|
|
|
301
303
|
return h.redirect(`/admin/webhooks/webhook/${createRequest.id}`);
|
|
302
304
|
} catch (err) {
|
|
303
305
|
await request.flash({ type: 'danger', message: `Couldn't create webhook. Try again.` });
|
|
304
|
-
request.logger.error({ msg: 'Failed to create webhook
|
|
306
|
+
request.logger.error({ msg: 'Failed to create webhook route', err });
|
|
305
307
|
|
|
306
308
|
return h.view(
|
|
307
309
|
'webhooks/new',
|
|
@@ -340,7 +342,7 @@ return payload;`)
|
|
|
340
342
|
}
|
|
341
343
|
|
|
342
344
|
await request.flash({ type: 'danger', message: `Couldn't create webhook. Try again.` });
|
|
343
|
-
request.logger.
|
|
345
|
+
request.logger.debug({ msg: 'Failed to create webhook route', err });
|
|
344
346
|
|
|
345
347
|
return h
|
|
346
348
|
.view(
|
|
@@ -613,7 +615,7 @@ return payload;`)
|
|
|
613
615
|
return h.redirect(`/admin/webhooks/webhook/${request.payload.webhook}`);
|
|
614
616
|
} catch (err) {
|
|
615
617
|
await request.flash({ type: 'danger', message: `Couldn't save webhook. Try again.` });
|
|
616
|
-
request.logger.error({ msg: 'Failed to update
|
|
618
|
+
request.logger.error({ msg: 'Failed to update webhook route', err });
|
|
617
619
|
|
|
618
620
|
let webhook = await webhooks.get(request.payload.webhook);
|
|
619
621
|
if (!webhook) {
|
|
@@ -661,7 +663,7 @@ return payload;`)
|
|
|
661
663
|
}
|
|
662
664
|
|
|
663
665
|
await request.flash({ type: 'danger', message: `Couldn't save webhook. Try again.` });
|
|
664
|
-
request.logger.
|
|
666
|
+
request.logger.debug({ msg: 'Failed to update webhook route', err });
|
|
665
667
|
|
|
666
668
|
let webhook = await webhooks.get(request.payload.webhook);
|
|
667
669
|
if (!webhook) {
|
|
@@ -757,7 +759,7 @@ return payload;`)
|
|
|
757
759
|
return h.redirect(accountWebhooksLink.pathname + accountWebhooksLink.search);
|
|
758
760
|
} catch (err) {
|
|
759
761
|
await request.flash({ type: 'danger', message: `Couldn't delete webhook. Try again.` });
|
|
760
|
-
request.logger.error({ msg: 'Failed to delete
|
|
762
|
+
request.logger.error({ msg: 'Failed to delete webhook route', err, webhook: request.payload.webhook, remoteAddress: request.app.ip });
|
|
761
763
|
return h.redirect(`/admin/webhooks/webhook/${request.payload.webhook}`);
|
|
762
764
|
}
|
|
763
765
|
},
|
|
@@ -771,7 +773,7 @@ return payload;`)
|
|
|
771
773
|
|
|
772
774
|
async failAction(request, h, err) {
|
|
773
775
|
await request.flash({ type: 'danger', message: `Couldn't delete webhook. Try again.` });
|
|
774
|
-
request.logger.
|
|
776
|
+
request.logger.debug({ msg: 'Failed to delete webhook route', err });
|
|
775
777
|
|
|
776
778
|
return h.redirect('/admin/webhooks').takeover();
|
|
777
779
|
},
|
|
@@ -1123,7 +1125,7 @@ return payload;`)
|
|
|
1123
1125
|
}
|
|
1124
1126
|
|
|
1125
1127
|
await request.flash({ type: 'danger', message: `Couldn't save template. Try again.` });
|
|
1126
|
-
request.logger.
|
|
1128
|
+
request.logger.debug({ msg: 'Failed to update template', err });
|
|
1127
1129
|
|
|
1128
1130
|
let template = await templates.get(request.payload.template);
|
|
1129
1131
|
if (!template) {
|
|
@@ -1342,7 +1344,7 @@ return payload;`)
|
|
|
1342
1344
|
}
|
|
1343
1345
|
|
|
1344
1346
|
await request.flash({ type: 'danger', message: `Couldn't create template. Try again.` });
|
|
1345
|
-
request.logger.
|
|
1347
|
+
request.logger.debug({ msg: 'Failed to create template', err });
|
|
1346
1348
|
|
|
1347
1349
|
let account;
|
|
1348
1350
|
if (request.payload.account) {
|
|
@@ -1430,8 +1432,8 @@ return payload;`)
|
|
|
1430
1432
|
},
|
|
1431
1433
|
|
|
1432
1434
|
async failAction(request, h, err) {
|
|
1433
|
-
await request.flash({ type: 'danger', message: `Couldn't delete
|
|
1434
|
-
request.logger.error({ msg: 'Failed to delete the
|
|
1435
|
+
await request.flash({ type: 'danger', message: `Couldn't delete template. Try again.` });
|
|
1436
|
+
request.logger.error({ msg: 'Failed to delete the template', err });
|
|
1435
1437
|
|
|
1436
1438
|
return h.redirect('/admin/templates').takeover();
|
|
1437
1439
|
},
|
|
@@ -1453,7 +1455,12 @@ return payload;`)
|
|
|
1453
1455
|
path: '/admin/templates/test',
|
|
1454
1456
|
async handler(request) {
|
|
1455
1457
|
try {
|
|
1456
|
-
request.logger.
|
|
1458
|
+
request.logger.debug({
|
|
1459
|
+
msg: 'Trying to send test message',
|
|
1460
|
+
template: request.payload.template,
|
|
1461
|
+
account: request.payload.account,
|
|
1462
|
+
to: request.payload.to
|
|
1463
|
+
});
|
|
1457
1464
|
|
|
1458
1465
|
let template = await templates.get(request.payload.template);
|
|
1459
1466
|
if (!template) {
|
|
@@ -1502,7 +1509,7 @@ return payload;`)
|
|
|
1502
1509
|
};
|
|
1503
1510
|
}
|
|
1504
1511
|
} catch (err) {
|
|
1505
|
-
request.logger.error({ msg: 'Failed
|
|
1512
|
+
request.logger.error({ msg: 'Failed to send test message', err });
|
|
1506
1513
|
return {
|
|
1507
1514
|
success: false,
|
|
1508
1515
|
error: err.message
|
|
@@ -1824,7 +1831,7 @@ return payload;`)
|
|
|
1824
1831
|
}
|
|
1825
1832
|
|
|
1826
1833
|
await request.flash({ type: 'danger', message: `Couldn't add gateway. Try again.` });
|
|
1827
|
-
request.logger.
|
|
1834
|
+
request.logger.debug({ msg: 'Failed to add new gateway', err });
|
|
1828
1835
|
|
|
1829
1836
|
return h
|
|
1830
1837
|
.view(
|
|
@@ -1946,7 +1953,7 @@ return payload;`)
|
|
|
1946
1953
|
}
|
|
1947
1954
|
|
|
1948
1955
|
await request.flash({ type: 'danger', message: `Couldn't save gateway. Try again.` });
|
|
1949
|
-
request.logger.
|
|
1956
|
+
request.logger.debug({ msg: 'Failed to update gateway', err });
|
|
1950
1957
|
|
|
1951
1958
|
let gatewayObject = new Gateway({ gateway: request.payload.gateway, redis, secret: await getSecret() });
|
|
1952
1959
|
let gatewayData = await gatewayObject.loadGatewayData();
|
|
@@ -2076,7 +2083,7 @@ return payload;`)
|
|
|
2076
2083
|
|
|
2077
2084
|
return verifyResult.smtp;
|
|
2078
2085
|
} catch (err) {
|
|
2079
|
-
request.logger.error({ msg: 'Failed
|
|
2086
|
+
request.logger.error({ msg: 'Failed to verify gateway SMTP settings', host, port, user, pass: !!pass, err });
|
|
2080
2087
|
return {
|
|
2081
2088
|
success: false,
|
|
2082
2089
|
error: err.message
|
|
@@ -2133,7 +2140,7 @@ return payload;`)
|
|
|
2133
2140
|
return h.redirect('/admin/gateways');
|
|
2134
2141
|
} catch (err) {
|
|
2135
2142
|
await request.flash({ type: 'danger', message: `Couldn't delete gateway. Try again.` });
|
|
2136
|
-
request.logger.error({ msg: 'Failed to delete the gateway', err, gateway: request.
|
|
2143
|
+
request.logger.error({ msg: 'Failed to delete the gateway', err, gateway: request.params.gateway, remoteAddress: request.app.ip });
|
|
2137
2144
|
return h.redirect(`/admin/gateways/${request.params.gateway}`);
|
|
2138
2145
|
}
|
|
2139
2146
|
},
|
|
@@ -2147,7 +2154,7 @@ return payload;`)
|
|
|
2147
2154
|
|
|
2148
2155
|
async failAction(request, h, err) {
|
|
2149
2156
|
await request.flash({ type: 'danger', message: `Couldn't delete gateway. Try again.` });
|
|
2150
|
-
request.logger.
|
|
2157
|
+
request.logger.debug({ msg: 'Failed to delete the gateway', err });
|
|
2151
2158
|
|
|
2152
2159
|
return h.redirect('/admin/gateways').takeover();
|
|
2153
2160
|
},
|
|
@@ -2187,6 +2194,9 @@ return payload;`)
|
|
|
2187
2194
|
first: !i
|
|
2188
2195
|
}))
|
|
2189
2196
|
: false;
|
|
2197
|
+
// A narrowed token looks identical to a full one in a list that only shows scopes,
|
|
2198
|
+
// which is the opposite of what the narrowing is for
|
|
2199
|
+
entry.permissionSummary = tokenPermissionView.summarize(entry.permissions);
|
|
2190
2200
|
});
|
|
2191
2201
|
|
|
2192
2202
|
let nextPage = false;
|
|
@@ -2237,6 +2247,8 @@ return payload;`)
|
|
|
2237
2247
|
searchTarget: '/admin/tokens',
|
|
2238
2248
|
searchPlaceholder: 'Search for access tokens…',
|
|
2239
2249
|
query: request.query.query,
|
|
2250
|
+
// The create button leads to a form that cannot submit without an admin session
|
|
2251
|
+
canProvision: request.auth.isAuthenticated,
|
|
2240
2252
|
searchHidden: request.query.account ? [{ name: 'account', value: request.query.account }] : null,
|
|
2241
2253
|
total: data.total,
|
|
2242
2254
|
|
|
@@ -2295,6 +2307,8 @@ return payload;`)
|
|
|
2295
2307
|
accountTokensLink.searchParams.append('account', request.query.account);
|
|
2296
2308
|
}
|
|
2297
2309
|
|
|
2310
|
+
const permissionModel = tokenPermissionView.formModel();
|
|
2311
|
+
|
|
2298
2312
|
return h.view(
|
|
2299
2313
|
'tokens/new',
|
|
2300
2314
|
{
|
|
@@ -2305,6 +2319,15 @@ return payload;`)
|
|
|
2305
2319
|
allAccounts: !request.query.account,
|
|
2306
2320
|
account: request.query.account
|
|
2307
2321
|
},
|
|
2322
|
+
// Same expression the POST gate uses, so the form and the thing it submits to
|
|
2323
|
+
// cannot disagree. A token is never invalidated once minted, so one handed to a
|
|
2324
|
+
// caller that reached this page without authenticating would keep working - which
|
|
2325
|
+
// is why the mint is refused rather than merely discouraged. Rendering the form
|
|
2326
|
+
// anyway meant filling it in and losing the work to a 403.
|
|
2327
|
+
canProvision: request.auth.isAuthenticated,
|
|
2328
|
+
...permissionModel,
|
|
2329
|
+
// Handed to the page as data rather than restated in its script
|
|
2330
|
+
permissionSurfacesJson: JSON.stringify(permissionModel.permissionSurfaces),
|
|
2308
2331
|
account: accountData,
|
|
2309
2332
|
accountTokensLink: accountTokensLink.pathname + accountTokensLink.search
|
|
2310
2333
|
},
|
|
@@ -2359,6 +2382,12 @@ return payload;`)
|
|
|
2359
2382
|
scopes: request.payload.scopes
|
|
2360
2383
|
};
|
|
2361
2384
|
|
|
2385
|
+
if (request.payload.permissions) {
|
|
2386
|
+
// An axis that lists nothing is refused by tokenPermissionsSchema, so both mint
|
|
2387
|
+
// paths give the same answer rather than this one carrying its own copy of the rule
|
|
2388
|
+
data.permissions = request.payload.permissions;
|
|
2389
|
+
}
|
|
2390
|
+
|
|
2362
2391
|
if (request.payload.account) {
|
|
2363
2392
|
let accountObject = new Account({ redis, account: request.payload.account });
|
|
2364
2393
|
await accountObject.loadAccountData();
|
|
@@ -2372,7 +2401,12 @@ return payload;`)
|
|
|
2372
2401
|
token
|
|
2373
2402
|
};
|
|
2374
2403
|
} catch (err) {
|
|
2375
|
-
request.logger
|
|
2404
|
+
request.logger[authAwareLevel(err)]({
|
|
2405
|
+
msg: 'Failed to generate token',
|
|
2406
|
+
err,
|
|
2407
|
+
remoteAddress: request.app.ip,
|
|
2408
|
+
description: request.payload.description
|
|
2409
|
+
});
|
|
2376
2410
|
if (Boom.isBoom(err)) {
|
|
2377
2411
|
return Object.assign({ success: false }, err.output.payload);
|
|
2378
2412
|
}
|
|
@@ -2395,6 +2429,9 @@ return payload;`)
|
|
|
2395
2429
|
.items(Joi.string().valid('*', 'api', 'metrics', 'smtp', 'imap-proxy'))
|
|
2396
2430
|
.required()
|
|
2397
2431
|
.label('Scopes'),
|
|
2432
|
+
// Null when the restriction is off, which is what "not narrowed" means on the
|
|
2433
|
+
// record - distinct from an empty object, which tokenPermissionsSchema refuses
|
|
2434
|
+
permissions: tokenPermissionsSchema.default(null),
|
|
2398
2435
|
account: accountIdSchema.default(null)
|
|
2399
2436
|
})
|
|
2400
2437
|
}
|
|
@@ -2414,7 +2451,14 @@ return payload;`)
|
|
|
2414
2451
|
return h.redirect('/admin/tokens');
|
|
2415
2452
|
} catch (err) {
|
|
2416
2453
|
await request.flash({ type: 'danger', message: `Couldn't delete token. Try again.` });
|
|
2417
|
-
|
|
2454
|
+
// Only log a partial value: the payload is usually a token id, but it can also be a
|
|
2455
|
+
// raw access token, which must never land in the log whole
|
|
2456
|
+
request.logger.error({
|
|
2457
|
+
msg: 'Failed to delete access token',
|
|
2458
|
+
err,
|
|
2459
|
+
token: request.payload.token ? formatPartialSecretKey(request.payload.token) : null,
|
|
2460
|
+
remoteAddress: request.app.ip
|
|
2461
|
+
});
|
|
2418
2462
|
return h.redirect('/admin/tokens');
|
|
2419
2463
|
}
|
|
2420
2464
|
},
|
|
@@ -2428,7 +2472,7 @@ return payload;`)
|
|
|
2428
2472
|
|
|
2429
2473
|
async failAction(request, h, err) {
|
|
2430
2474
|
await request.flash({ type: 'danger', message: `Couldn't delete token. Try again.` });
|
|
2431
|
-
request.logger.
|
|
2475
|
+
request.logger.debug({ msg: 'Failed to delete access token', err });
|
|
2432
2476
|
|
|
2433
2477
|
return h.redirect('/admin/tokens').takeover();
|
|
2434
2478
|
},
|
|
@@ -12,8 +12,7 @@ const Joi = require('joi');
|
|
|
12
12
|
const crypto = require('crypto');
|
|
13
13
|
const pbkdf2 = require('@phc/pbkdf2');
|
|
14
14
|
const QRCode = require('qrcode');
|
|
15
|
-
const
|
|
16
|
-
const base32 = require('base32.js');
|
|
15
|
+
const { generateTotpSeed, verifyTotp, generateTotpUrl } = require('../totp');
|
|
17
16
|
const {
|
|
18
17
|
generateRegistrationOptions,
|
|
19
18
|
verifyRegistrationResponse,
|
|
@@ -122,7 +121,7 @@ function init(args) {
|
|
|
122
121
|
},
|
|
123
122
|
|
|
124
123
|
async failAction(request, h, err) {
|
|
125
|
-
request.logger.
|
|
124
|
+
request.logger.debug({ msg: 'Failed to validate login arguments', err });
|
|
126
125
|
return h.redirect('/admin/login').takeover();
|
|
127
126
|
},
|
|
128
127
|
|
|
@@ -182,7 +181,7 @@ function init(args) {
|
|
|
182
181
|
try {
|
|
183
182
|
let ipRateLimit = await h.checkRateLimit(`login:ip:${request.app.ip}`, 1, 30, 60);
|
|
184
183
|
if (!ipRateLimit.success) {
|
|
185
|
-
request.logger.
|
|
184
|
+
request.logger.warn({ msg: 'Rate limited', ipRateLimit, remoteAddress: request.app.ip });
|
|
186
185
|
let err = new Error('Rate limited, please wait and try again');
|
|
187
186
|
err.responseText = err.message;
|
|
188
187
|
throw err;
|
|
@@ -190,7 +189,7 @@ function init(args) {
|
|
|
190
189
|
|
|
191
190
|
let rateLimit = await h.checkRateLimit(`login:${request.payload.username}`, 1, 10, 60);
|
|
192
191
|
if (!rateLimit.success) {
|
|
193
|
-
request.logger.
|
|
192
|
+
request.logger.warn({ msg: 'Rate limited', rateLimit, remoteAddress: request.app.ip });
|
|
194
193
|
let err = new Error('Rate limited, please wait and try again');
|
|
195
194
|
err.responseText = err.message;
|
|
196
195
|
throw err;
|
|
@@ -200,20 +199,23 @@ function init(args) {
|
|
|
200
199
|
let totpEnabled = (await settings.get('totpEnabled')) || false;
|
|
201
200
|
|
|
202
201
|
if (authData && authData.user && authData.user !== request.payload.username) {
|
|
203
|
-
request.logger.
|
|
202
|
+
request.logger.warn({ msg: 'Invalid username', username: request.payload.username, method: 'password', remoteAddress: request.app.ip });
|
|
204
203
|
let err = new Error('Failed to authenticate');
|
|
205
204
|
err.details = { password: err.message };
|
|
206
205
|
throw err;
|
|
207
206
|
}
|
|
208
207
|
|
|
209
208
|
if (authData && authData.password) {
|
|
209
|
+
let valid;
|
|
210
210
|
try {
|
|
211
|
-
|
|
212
|
-
if (!valid) {
|
|
213
|
-
throw new Error('Invalid password');
|
|
214
|
-
}
|
|
211
|
+
valid = await pbkdf2.verify(authData.password, request.payload.password);
|
|
215
212
|
} catch (E) {
|
|
213
|
+
// verify() only throws on a malformed stored hash, not on a wrong password
|
|
216
214
|
request.logger.error({ msg: 'Failed to verify password hash', err: E });
|
|
215
|
+
valid = false;
|
|
216
|
+
}
|
|
217
|
+
if (!valid) {
|
|
218
|
+
request.logger.warn({ msg: 'Invalid password', user: request.payload.username, method: 'password', remoteAddress: request.app.ip });
|
|
217
219
|
let err = new Error('Failed to authenticate');
|
|
218
220
|
err.details = { password: err.message };
|
|
219
221
|
throw err;
|
|
@@ -252,7 +254,7 @@ function init(args) {
|
|
|
252
254
|
}
|
|
253
255
|
} catch (err) {
|
|
254
256
|
await request.flash({ type: 'danger', message: err.responseText || `Could not sign in. Check your password and try again.` });
|
|
255
|
-
request.logger.
|
|
257
|
+
request.logger.warn({ msg: 'Failed to authenticate', err, user: request.payload.username, method: 'password', remoteAddress: request.app.ip });
|
|
256
258
|
|
|
257
259
|
let errors = err.details;
|
|
258
260
|
|
|
@@ -295,7 +297,7 @@ function init(args) {
|
|
|
295
297
|
}
|
|
296
298
|
|
|
297
299
|
await request.flash({ type: 'danger', message: `Could not sign in. Check your password and try again.` });
|
|
298
|
-
request.logger.
|
|
300
|
+
request.logger.debug({ msg: 'Failed to authenticate', err, method: 'password', remoteAddress: request.app.ip });
|
|
299
301
|
|
|
300
302
|
return h
|
|
301
303
|
.view(
|
|
@@ -376,7 +378,7 @@ function init(args) {
|
|
|
376
378
|
},
|
|
377
379
|
|
|
378
380
|
async failAction(request, h, err) {
|
|
379
|
-
request.logger.
|
|
381
|
+
request.logger.debug({ msg: 'Failed to validate login arguments', err });
|
|
380
382
|
return h.redirect('/admin/login').takeover();
|
|
381
383
|
},
|
|
382
384
|
|
|
@@ -411,7 +413,7 @@ function init(args) {
|
|
|
411
413
|
// attempt limiter
|
|
412
414
|
let rateLimit = await h.checkRateLimit(`totp:attempt:${request.auth.credentials.user}`, 1, 10, 60);
|
|
413
415
|
if (!rateLimit.success) {
|
|
414
|
-
request.logger.
|
|
416
|
+
request.logger.warn({ msg: 'Rate limited', rateLimit });
|
|
415
417
|
let err = new Error('Rate limited, please wait and try again');
|
|
416
418
|
err.responseText = err.message;
|
|
417
419
|
throw err;
|
|
@@ -424,12 +426,7 @@ function init(args) {
|
|
|
424
426
|
return h.redirect(`/admin/login`);
|
|
425
427
|
}
|
|
426
428
|
|
|
427
|
-
let verified =
|
|
428
|
-
secret: base32.encode(Buffer.from(totpSeed)),
|
|
429
|
-
encoding: 'base32',
|
|
430
|
-
token: request.payload.code,
|
|
431
|
-
window: TOTP_WINDOW_SIZE
|
|
432
|
-
});
|
|
429
|
+
let verified = verifyTotp(totpSeed, request.payload.code, { window: TOTP_WINDOW_SIZE });
|
|
433
430
|
|
|
434
431
|
if (!verified) {
|
|
435
432
|
let err = new Error('Failed to verify login');
|
|
@@ -440,7 +437,7 @@ function init(args) {
|
|
|
440
437
|
// code re-use limiter
|
|
441
438
|
let reUseLimit = await h.checkRateLimit(`totp:code:${request.payload.code}`, 1, 1, 12 * 60);
|
|
442
439
|
if (!reUseLimit.success) {
|
|
443
|
-
request.logger.
|
|
440
|
+
request.logger.warn({ msg: 'TOTP code recently used', reUseLimit });
|
|
444
441
|
let err = new Error('This code has been already used, please wait and try another code');
|
|
445
442
|
err.responseText = err.message;
|
|
446
443
|
throw err;
|
|
@@ -470,7 +467,7 @@ function init(args) {
|
|
|
470
467
|
await request.flash({ type: 'danger', message: err.responseText || `Could not verify. Check your code and try again.` });
|
|
471
468
|
}
|
|
472
469
|
|
|
473
|
-
request.logger.
|
|
470
|
+
request.logger.warn({
|
|
474
471
|
msg: 'Failed to verify TOTP',
|
|
475
472
|
err,
|
|
476
473
|
user: request.auth && request.auth.credentials && request.auth.credentials.user,
|
|
@@ -513,7 +510,7 @@ function init(args) {
|
|
|
513
510
|
}
|
|
514
511
|
|
|
515
512
|
await request.flash({ type: 'danger', message: `Could not verify. Check your code and try again.` });
|
|
516
|
-
request.logger.
|
|
513
|
+
request.logger.debug({ msg: 'Failed to verify login', err });
|
|
517
514
|
|
|
518
515
|
return h
|
|
519
516
|
.view(
|
|
@@ -569,12 +566,7 @@ function init(args) {
|
|
|
569
566
|
|
|
570
567
|
let totpSeed = await settings.get('totpSeed');
|
|
571
568
|
if (!totpSeed) {
|
|
572
|
-
|
|
573
|
-
length: 20,
|
|
574
|
-
name: username
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
totpSeed = secret.ascii;
|
|
569
|
+
totpSeed = generateTotpSeed();
|
|
578
570
|
await settings.set('totpSeed', totpSeed);
|
|
579
571
|
}
|
|
580
572
|
|
|
@@ -582,17 +574,15 @@ function init(args) {
|
|
|
582
574
|
// create QR code
|
|
583
575
|
const serviceUrl = (await settings.get('serviceUrl')) || '';
|
|
584
576
|
|
|
585
|
-
let otpauth_url =
|
|
586
|
-
|
|
587
|
-
// label is part of URL and speakeasy as of v2.0.0 does not encode special characters
|
|
588
|
-
label: encodeURIComponent(serviceUrl.replace(/^https?:\/\/|\/$/g, '')),
|
|
577
|
+
let otpauth_url = generateTotpUrl(totpSeed, {
|
|
578
|
+
label: serviceUrl.replace(/^https?:\/\/|\/$/g, ''),
|
|
589
579
|
issuer: 'EmailEngine'
|
|
590
580
|
});
|
|
591
581
|
|
|
592
582
|
try {
|
|
593
583
|
totp.dataUrl = await QRCode.toDataURL(otpauth_url);
|
|
594
584
|
} catch (err) {
|
|
595
|
-
request.logger.error({ msg: 'QR code
|
|
585
|
+
request.logger.error({ msg: 'Failed to generate QR code', err });
|
|
596
586
|
}
|
|
597
587
|
}
|
|
598
588
|
|
|
@@ -665,12 +655,7 @@ function init(args) {
|
|
|
665
655
|
return h.redirect(`/admin/account/security`);
|
|
666
656
|
}
|
|
667
657
|
|
|
668
|
-
let verified =
|
|
669
|
-
secret: base32.encode(Buffer.from(totpSeed)),
|
|
670
|
-
encoding: 'base32',
|
|
671
|
-
token: request.payload.code,
|
|
672
|
-
window: TOTP_WINDOW_SIZE
|
|
673
|
-
});
|
|
658
|
+
let verified = verifyTotp(totpSeed, request.payload.code, { window: TOTP_WINDOW_SIZE });
|
|
674
659
|
|
|
675
660
|
if (!verified) {
|
|
676
661
|
await request.flash({ type: 'danger', message: `Invalid verification code` });
|
|
@@ -707,7 +692,7 @@ function init(args) {
|
|
|
707
692
|
|
|
708
693
|
async failAction(request, h, err) {
|
|
709
694
|
await request.flash({ type: 'danger', message: `Couldn't enable two-factor auth. Try again.` });
|
|
710
|
-
request.logger.
|
|
695
|
+
request.logger.debug({ msg: 'Failed to enable 2FA', err });
|
|
711
696
|
|
|
712
697
|
return h.redirect('/admin').takeover();
|
|
713
698
|
},
|
|
@@ -736,7 +721,7 @@ function init(args) {
|
|
|
736
721
|
return h.redirect(`/admin/account/security`);
|
|
737
722
|
} catch (err) {
|
|
738
723
|
await request.flash({ type: 'danger', message: `Couldn't disable two-factor auth. Try again.` });
|
|
739
|
-
request.logger.error({ msg: 'Failed to
|
|
724
|
+
request.logger.error({ msg: 'Failed to disable 2FA', err, remoteAddress: request.app.ip });
|
|
740
725
|
return h.redirect(`/admin/account/security`);
|
|
741
726
|
}
|
|
742
727
|
},
|
|
@@ -1036,7 +1021,7 @@ function init(args) {
|
|
|
1036
1021
|
|
|
1037
1022
|
async failAction(request, h, err) {
|
|
1038
1023
|
await request.flash({ type: 'danger', message: 'Failed to remove passkey' });
|
|
1039
|
-
request.logger.
|
|
1024
|
+
request.logger.debug({ msg: 'Failed to delete passkey', err });
|
|
1040
1025
|
return h.redirect('/admin/account/security').takeover();
|
|
1041
1026
|
},
|
|
1042
1027
|
|
|
@@ -1266,13 +1251,16 @@ function init(args) {
|
|
|
1266
1251
|
let authData = await settings.get('authData');
|
|
1267
1252
|
let hasExistingPassword = !!(authData && authData.password);
|
|
1268
1253
|
if (hasExistingPassword) {
|
|
1254
|
+
let valid;
|
|
1269
1255
|
try {
|
|
1270
|
-
|
|
1271
|
-
if (!valid) {
|
|
1272
|
-
throw new Error('Invalid current password');
|
|
1273
|
-
}
|
|
1256
|
+
valid = await pbkdf2.verify(authData.password, request.payload.password0);
|
|
1274
1257
|
} catch (E) {
|
|
1258
|
+
// verify() only throws on a malformed stored hash, not on a wrong password
|
|
1275
1259
|
request.logger.error({ msg: 'Failed to verify password hash', err: E });
|
|
1260
|
+
valid = false;
|
|
1261
|
+
}
|
|
1262
|
+
if (!valid) {
|
|
1263
|
+
request.logger.warn({ msg: 'Invalid current password', remoteAddress: request.app.ip });
|
|
1276
1264
|
let err = new Error('Failed to verify current password');
|
|
1277
1265
|
err.details = { password0: err.message };
|
|
1278
1266
|
throw err;
|
|
@@ -1365,7 +1353,7 @@ function init(args) {
|
|
|
1365
1353
|
}
|
|
1366
1354
|
|
|
1367
1355
|
await request.flash({ type: 'danger', message: `Couldn't update password. Try again.` });
|
|
1368
|
-
request.logger.
|
|
1356
|
+
request.logger.debug({ msg: 'Failed to update account password', err });
|
|
1369
1357
|
|
|
1370
1358
|
let username = (request.auth && request.auth.credentials && request.auth.credentials.user) || 'admin';
|
|
1371
1359
|
|
|
@@ -12,7 +12,7 @@ const { Export } = require('../export');
|
|
|
12
12
|
const getSecret = require('../get-secret');
|
|
13
13
|
const { failAction } = require('../tools');
|
|
14
14
|
const { exportIdSchema } = require('../schemas');
|
|
15
|
-
const { throwAsBoom } = require('./route-helpers');
|
|
15
|
+
const { throwAsBoom, isClientError } = require('./route-helpers');
|
|
16
16
|
|
|
17
17
|
function init(args) {
|
|
18
18
|
const { server } = args;
|
|
@@ -63,7 +63,9 @@ function init(args) {
|
|
|
63
63
|
}
|
|
64
64
|
return result;
|
|
65
65
|
} catch (err) {
|
|
66
|
-
|
|
66
|
+
if (!isClientError(err)) {
|
|
67
|
+
request.logger.error({ msg: 'Failed to get export', err, account: request.params.account, exportId: request.params.exportId });
|
|
68
|
+
}
|
|
67
69
|
throwAsBoom(err);
|
|
68
70
|
}
|
|
69
71
|
},
|
|
@@ -132,7 +134,9 @@ function init(args) {
|
|
|
132
134
|
}
|
|
133
135
|
return { deleted: true };
|
|
134
136
|
} catch (err) {
|
|
135
|
-
|
|
137
|
+
if (!isClientError(err)) {
|
|
138
|
+
request.logger.error({ msg: 'Failed to delete export', err, account: request.params.account, exportId: request.params.exportId });
|
|
139
|
+
}
|
|
136
140
|
throwAsBoom(err);
|
|
137
141
|
}
|
|
138
142
|
},
|
|
@@ -193,7 +197,9 @@ function init(args) {
|
|
|
193
197
|
.header('Content-Disposition', `attachment; filename="${fileInfo.filename}"`)
|
|
194
198
|
.header('Content-Encoding', 'identity');
|
|
195
199
|
} catch (err) {
|
|
196
|
-
|
|
200
|
+
if (!isClientError(err)) {
|
|
201
|
+
request.logger.error({ msg: 'Failed to download export', err, account: request.params.account, exportId: request.params.exportId });
|
|
202
|
+
}
|
|
197
203
|
throwAsBoom(err);
|
|
198
204
|
}
|
|
199
205
|
},
|
|
@@ -549,7 +549,7 @@ function init(args) {
|
|
|
549
549
|
},
|
|
550
550
|
|
|
551
551
|
async failAction(request, h, err) {
|
|
552
|
-
request.logger.
|
|
552
|
+
request.logger.debug({ msg: 'Failed to register service account', err, app: request.params.app });
|
|
553
553
|
await request.flash({ type: 'danger', message: `Failed to add account. Provide a valid email address.` });
|
|
554
554
|
return h.redirect(`/admin/config/oauth/app/${request.params.app}`).takeover();
|
|
555
555
|
},
|
|
@@ -590,7 +590,7 @@ function init(args) {
|
|
|
590
590
|
},
|
|
591
591
|
|
|
592
592
|
async failAction(request, h, err) {
|
|
593
|
-
request.logger.
|
|
593
|
+
request.logger.debug({ msg: 'Invalid verify request', err, app: request.params.app });
|
|
594
594
|
return h.response({ error: 'Invalid request' }).code(400).takeover();
|
|
595
595
|
},
|
|
596
596
|
|
|
@@ -789,7 +789,7 @@ function init(args) {
|
|
|
789
789
|
}
|
|
790
790
|
|
|
791
791
|
await request.flash({ type: 'danger', message: `Couldn't register OAuth2 app. Try again.` });
|
|
792
|
-
request.logger.
|
|
792
|
+
request.logger.debug({ msg: 'Failed to register OAuth2 app', err });
|
|
793
793
|
|
|
794
794
|
let { provider, baseScopes } = request.payload;
|
|
795
795
|
if (!provider || !OAUTH_PROVIDERS.hasOwnProperty(provider)) {
|
|
@@ -1048,12 +1048,12 @@ function init(args) {
|
|
|
1048
1048
|
let appData = await oauth2Apps.get(request.payload.app);
|
|
1049
1049
|
if (!appData) {
|
|
1050
1050
|
await request.flash({ type: 'danger', message: `Application not found` });
|
|
1051
|
-
request.logger.
|
|
1051
|
+
request.logger.warn({ msg: 'OAuth2 application not found', app: request.payload.app });
|
|
1052
1052
|
return h.redirect('/admin').takeover();
|
|
1053
1053
|
}
|
|
1054
1054
|
|
|
1055
1055
|
await request.flash({ type: 'danger', message: `Couldn't save OAuth2 app. Try again.` });
|
|
1056
|
-
request.logger.
|
|
1056
|
+
request.logger.debug({ msg: 'Failed to update OAuth2 app', err });
|
|
1057
1057
|
|
|
1058
1058
|
let { provider } = request.payload;
|
|
1059
1059
|
if (!provider || !OAUTH_PROVIDERS.hasOwnProperty(provider)) {
|