emailengine-app 2.78.0 → 2.79.1
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 +23 -13
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +68 -0
- package/config/e2e.toml +2 -1
- package/config/test.toml +2 -1
- package/data/google-crawlers.json +1 -1
- package/lib/account.js +112 -36
- package/lib/api-reference/format.js +91 -4
- package/lib/api-reference/model.js +144 -19
- package/lib/api-reference/schema-tree.js +282 -28
- package/lib/api-routes/account-routes.js +80 -34
- 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 +401 -0
- package/lib/api-routes/route-helpers.js +294 -9
- package/lib/api-routes/route-metadata.js +28 -0
- package/lib/api-routes/settings-routes.js +66 -38
- 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 +526 -72
- package/lib/api-routes/webhook-route-routes.js +14 -4
- package/lib/arf-detect.js +17 -4
- package/lib/auth-token.js +80 -8
- package/lib/bounce-detect.js +28 -17
- package/lib/consts.js +16 -0
- package/lib/db.js +26 -2
- package/lib/delivery-error.js +30 -1
- package/lib/email-client/base-client.js +27 -41
- package/lib/email-client/gmail-client.js +23 -17
- package/lib/email-client/imap/mailbox.js +58 -59
- 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 +85 -28
- package/lib/email-client/message-builder.js +3 -3
- 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 +56 -64
- package/lib/email-client/smtp-pool-manager.js +1 -1
- package/lib/enum-descriptions.js +92 -2
- package/lib/export.js +1 -1
- package/lib/field-usage.js +133 -0
- package/lib/gateway.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 +15 -5
- package/lib/imapproxy/imap-server.js +27 -7
- package/lib/license-beacon.js +4 -9
- package/lib/lists.js +49 -1
- package/lib/llm-pre-process.js +5 -5
- package/lib/logger.js +5 -1
- package/lib/lua/h-set-new-mark.lua +36 -0
- package/lib/message-port-stream.js +84 -1
- package/lib/metrics-collector.js +2 -2
- package/lib/oauth/gmail.js +9 -12
- package/lib/oauth/mail-ru.js +5 -7
- package/lib/oauth/outlook.js +9 -9
- package/lib/oauth/pubsub/google.js +25 -10
- package/lib/oauth/scope-checker.js +1 -1
- package/lib/oauth2-apps.js +290 -292
- package/lib/openapi/build-document.js +20 -8
- package/lib/openapi/joi-schema.js +20 -0
- package/lib/outbox.js +85 -17
- package/lib/pre-process.js +8 -8
- package/lib/queue-stats.js +49 -0
- package/lib/read-env-value.js +1 -1
- 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 +218 -162
- package/lib/settings.js +98 -5
- package/lib/sub-script.js +2 -1
- package/lib/swagger-options.js +2 -1
- package/lib/templates.js +4 -4
- package/lib/threads.js +2 -2
- package/lib/token-audit-log.js +231 -0
- package/lib/token-permission-view.js +219 -0
- package/lib/token-permissions.js +172 -0
- package/lib/tokens.js +247 -66
- package/lib/tools.js +142 -37
- package/lib/ui-routes/account-routes.js +42 -15
- package/lib/ui-routes/admin-config-routes.js +18 -10
- package/lib/ui-routes/admin-entities-routes.js +117 -38
- package/lib/ui-routes/auth-routes.js +30 -24
- package/lib/ui-routes/export-routes.js +10 -4
- package/lib/ui-routes/oauth-config-routes.js +12 -12
- package/lib/ui-routes/reference-routes.js +3 -3
- package/lib/ui-routes/route-helpers.js +78 -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 +299 -0
- package/lib/ui-routes/unsubscribe-routes.js +19 -29
- package/lib/utils/decode-headers.js +42 -0
- package/lib/utils/header-map.js +48 -0
- package/lib/utils/network.js +2 -2
- package/lib/utils/unsafe-key.js +59 -0
- package/lib/web-safe-html.js +1 -1
- package/lib/webhook-routing.js +84 -0
- package/lib/webhooks.js +48 -14
- package/package.json +11 -10
- package/sbom.json +1 -1
- package/server.js +116 -55
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +136 -9
- package/static/js/reference.js +456 -10
- package/static/js/ui.js +43 -0
- package/static/licenses.html +51 -41
- package/translations/messages.pot +59 -59
- package/views/accounts/account.hbs +75 -13
- package/views/accounts/browse.hbs +19 -36
- package/views/accounts/edit.hbs +2 -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/gateways/edit.hbs +1 -1
- package/views/gateways/gateway.hbs +2 -2
- package/views/gateways/index.hbs +7 -7
- package/views/partials/accounts_table.hbs +7 -7
- package/views/partials/oauth_form.hbs +0 -15
- package/views/partials/reference/disclosure.hbs +8 -2
- package/views/partials/reference/operation.hbs +47 -13
- package/views/partials/reference/params.hbs +17 -1
- package/views/partials/reference/schema-node.hbs +110 -52
- package/views/partials/reference/schema-tools.hbs +25 -0
- 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/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 +10 -4
- package/views/templates/template.hbs +1 -1
- package/views/tokens/index.hbs +53 -6
- package/views/tokens/new.hbs +334 -5
- package/workers/api.js +185 -102
- package/workers/documents.js +46 -26
- package/workers/export.js +20 -8
- package/workers/imap-proxy.js +2 -2
- package/workers/imap.js +77 -78
- package/workers/smtp.js +13 -7
- package/workers/submit.js +40 -30
- package/workers/webhooks.js +80 -26
- 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');
|
|
12
|
-
const
|
|
10
|
+
const { failAction, verifyAccountInfo, formatPartialSecretKey } = require('../tools');
|
|
11
|
+
const { templateSchemas, accountIdSchema, tokenPermissionsSchema } = require('../schemas');
|
|
12
|
+
const tokenPermissionView = require('../token-permission-view');
|
|
13
|
+
const { Account, accountExists } = 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, resolveKnownAccounts, adminUrl } = require('./route-helpers');
|
|
18
20
|
const exampleWebhookPayloads = require('../payload-examples-webhooks.json');
|
|
19
21
|
|
|
20
22
|
const { DEFAULT_PAGE_SIZE } = consts;
|
|
@@ -298,10 +300,10 @@ return payload;`)
|
|
|
298
300
|
);
|
|
299
301
|
|
|
300
302
|
await request.flash({ type: 'info', message: `Webhook created` });
|
|
301
|
-
return h.redirect(`/admin/webhooks/webhook/${createRequest.id}`);
|
|
303
|
+
return h.redirect(adminUrl`/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(
|
|
@@ -610,10 +612,10 @@ return payload;`)
|
|
|
610
612
|
);
|
|
611
613
|
|
|
612
614
|
await request.flash({ type: 'info', message: `Webhook saved` });
|
|
613
|
-
return h.redirect(`/admin/webhooks/webhook/${request.payload.webhook}`);
|
|
615
|
+
return h.redirect(adminUrl`/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,8 +759,8 @@ 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
|
|
761
|
-
return h.redirect(`/admin/webhooks/webhook/${request.payload.webhook}`);
|
|
762
|
+
request.logger.error({ msg: 'Failed to delete webhook route', err, webhook: request.payload.webhook, remoteAddress: request.app.ip });
|
|
763
|
+
return h.redirect(adminUrl`/admin/webhooks/webhook/${request.payload.webhook}`);
|
|
762
764
|
}
|
|
763
765
|
},
|
|
764
766
|
options: {
|
|
@@ -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
|
},
|
|
@@ -1056,7 +1058,7 @@ return payload;`)
|
|
|
1056
1058
|
);
|
|
1057
1059
|
|
|
1058
1060
|
await request.flash({ type: 'info', message: `Template saved` });
|
|
1059
|
-
return h.redirect(`/admin/templates/template/${request.payload.template}`);
|
|
1061
|
+
return h.redirect(adminUrl`/admin/templates/template/${request.payload.template}`);
|
|
1060
1062
|
} catch (err) {
|
|
1061
1063
|
await request.flash({ type: 'danger', message: `Couldn't save template. Try again.` });
|
|
1062
1064
|
request.logger.error({ msg: 'Failed to update template', err });
|
|
@@ -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) {
|
|
@@ -1283,7 +1285,7 @@ return payload;`)
|
|
|
1283
1285
|
);
|
|
1284
1286
|
|
|
1285
1287
|
await request.flash({ type: 'info', message: `Template created` });
|
|
1286
|
-
return h.redirect(`/admin/templates/template/${createRequest.id}`);
|
|
1288
|
+
return h.redirect(adminUrl`/admin/templates/template/${createRequest.id}`);
|
|
1287
1289
|
} catch (err) {
|
|
1288
1290
|
await request.flash({ type: 'danger', message: `Couldn't create template. Try again.` });
|
|
1289
1291
|
request.logger.error({ msg: 'Failed to create template', err });
|
|
@@ -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) {
|
|
@@ -1418,7 +1420,7 @@ return payload;`)
|
|
|
1418
1420
|
} catch (err) {
|
|
1419
1421
|
await request.flash({ type: 'danger', message: `Couldn't delete template. Try again.` });
|
|
1420
1422
|
request.logger.error({ msg: 'Failed to delete the template', err, template: request.payload.template, remoteAddress: request.app.ip });
|
|
1421
|
-
return h.redirect(`/admin/templates/template/${request.payload.template}`);
|
|
1423
|
+
return h.redirect(adminUrl`/admin/templates/template/${request.payload.template}`);
|
|
1422
1424
|
}
|
|
1423
1425
|
},
|
|
1424
1426
|
options: {
|
|
@@ -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
|
|
@@ -1785,7 +1792,7 @@ return payload;`)
|
|
|
1785
1792
|
await request.flash({ type: 'success', message: `Updated SMTP gateway`, result });
|
|
1786
1793
|
}
|
|
1787
1794
|
|
|
1788
|
-
return h.redirect(`/admin/gateways/gateway/${
|
|
1795
|
+
return h.redirect(adminUrl`/admin/gateways/gateway/${result.gateway}?state=${result.state}`);
|
|
1789
1796
|
} catch (err) {
|
|
1790
1797
|
await request.flash({ type: 'danger', message: `Couldn't add gateway. Try again.` });
|
|
1791
1798
|
request.logger.error({ msg: 'Failed to add new gateway', err });
|
|
@@ -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(
|
|
@@ -1900,7 +1907,7 @@ return payload;`)
|
|
|
1900
1907
|
|
|
1901
1908
|
await request.flash({ type: 'success', message: `Updated SMTP gateway`, result });
|
|
1902
1909
|
|
|
1903
|
-
return h.redirect(`/admin/gateways/gateway/${
|
|
1910
|
+
return h.redirect(adminUrl`/admin/gateways/gateway/${result.gateway}`);
|
|
1904
1911
|
} catch (err) {
|
|
1905
1912
|
await request.flash({ type: 'danger', message: `Couldn't save gateway. Try again.` });
|
|
1906
1913
|
request.logger.error({ msg: 'Failed to update gateway', err });
|
|
@@ -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,8 +2140,8 @@ 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.
|
|
2137
|
-
return h.redirect(`/admin/gateways/${request.params.gateway}`);
|
|
2143
|
+
request.logger.error({ msg: 'Failed to delete the gateway', err, gateway: request.params.gateway, remoteAddress: request.app.ip });
|
|
2144
|
+
return h.redirect(adminUrl`/admin/gateways/gateway/${request.params.gateway}`);
|
|
2138
2145
|
}
|
|
2139
2146
|
},
|
|
2140
2147
|
options: {
|
|
@@ -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
|
},
|
|
@@ -2171,9 +2178,26 @@ return payload;`)
|
|
|
2171
2178
|
accountData = await accountObject.loadAccountData();
|
|
2172
2179
|
}
|
|
2173
2180
|
|
|
2174
|
-
const data = await tokens.list(request.query.account, request.query.page - 1, request.query.pageSize, request.query.query
|
|
2181
|
+
const data = await tokens.list(request.query.account, request.query.page - 1, request.query.pageSize, request.query.query, {
|
|
2182
|
+
// Every token on the instance, not just the unbound ones. A bound token lives in its
|
|
2183
|
+
// account's index, so without this the page that manages access tokens was the one
|
|
2184
|
+
// place a bound token could not be seen - and the form can now issue one directly.
|
|
2185
|
+
all: !request.query.account
|
|
2186
|
+
});
|
|
2187
|
+
|
|
2188
|
+
// A token outlives the account it was bound to: deleting an account drops that account's
|
|
2189
|
+
// token index but not the token records, and such a token still authenticates. So the
|
|
2190
|
+
// binding column has to tell a live account from a gone one rather than link every row
|
|
2191
|
+
// and let some of them lead to a 404.
|
|
2192
|
+
//
|
|
2193
|
+
// That column is the only reader of accountKnown, so the probe follows the same flag the
|
|
2194
|
+
// view renders on: an account-filtered page names one account, already loaded above, and
|
|
2195
|
+
// shows no column to put the answer in.
|
|
2196
|
+
const showAccountColumn = !accountData;
|
|
2197
|
+
const knownAccounts = showAccountColumn ? await resolveKnownAccounts(data.tokens) : new Map();
|
|
2175
2198
|
|
|
2176
2199
|
data.tokens.forEach(entry => {
|
|
2200
|
+
entry.accountKnown = knownAccounts.get(entry.account);
|
|
2177
2201
|
entry.access = entry.access || {};
|
|
2178
2202
|
entry.access.timeStr =
|
|
2179
2203
|
entry.access && entry.access.time && typeof entry.access.time.toISOString === 'function' ? entry.access.time.toISOString() : null;
|
|
@@ -2187,6 +2211,9 @@ return payload;`)
|
|
|
2187
2211
|
first: !i
|
|
2188
2212
|
}))
|
|
2189
2213
|
: false;
|
|
2214
|
+
// A narrowed token looks identical to a full one in a list that only shows scopes,
|
|
2215
|
+
// which is the opposite of what the narrowing is for
|
|
2216
|
+
entry.permissionSummary = tokenPermissionView.summarize(entry.permissions);
|
|
2190
2217
|
});
|
|
2191
2218
|
|
|
2192
2219
|
let nextPage = false;
|
|
@@ -2234,9 +2261,15 @@ return payload;`)
|
|
|
2234
2261
|
menuTokens: true,
|
|
2235
2262
|
data,
|
|
2236
2263
|
|
|
2264
|
+
// Redundant in the account-filtered listing, where the card header above the
|
|
2265
|
+
// table already names the one account every row belongs to
|
|
2266
|
+
showAccountColumn,
|
|
2267
|
+
|
|
2237
2268
|
searchTarget: '/admin/tokens',
|
|
2238
2269
|
searchPlaceholder: 'Search for access tokens…',
|
|
2239
2270
|
query: request.query.query,
|
|
2271
|
+
// The create button leads to a form that cannot submit without an admin session
|
|
2272
|
+
canProvision: request.auth.isAuthenticated,
|
|
2240
2273
|
searchHidden: request.query.account ? [{ name: 'account', value: request.query.account }] : null,
|
|
2241
2274
|
total: data.total,
|
|
2242
2275
|
|
|
@@ -2276,7 +2309,10 @@ return payload;`)
|
|
|
2276
2309
|
account: accountIdSchema.default(null),
|
|
2277
2310
|
page: Joi.number().integer().min(1).max(1000000).default(1),
|
|
2278
2311
|
pageSize: Joi.number().integer().min(1).max(250).default(DEFAULT_PAGE_SIZE),
|
|
2279
|
-
|
|
2312
|
+
// Trimmed like the /v1/tokens listing: an untrimmed whitespace-only value is a
|
|
2313
|
+
// query to the route and no query at all to the filter, so the listing would
|
|
2314
|
+
// read every record on the instance and then match all of them
|
|
2315
|
+
query: Joi.string().empty('').trim().example('prometheus').description('Filter by search term')
|
|
2280
2316
|
})
|
|
2281
2317
|
}
|
|
2282
2318
|
}
|
|
@@ -2295,6 +2331,8 @@ return payload;`)
|
|
|
2295
2331
|
accountTokensLink.searchParams.append('account', request.query.account);
|
|
2296
2332
|
}
|
|
2297
2333
|
|
|
2334
|
+
const permissionModel = tokenPermissionView.formModel();
|
|
2335
|
+
|
|
2298
2336
|
return h.view(
|
|
2299
2337
|
'tokens/new',
|
|
2300
2338
|
{
|
|
@@ -2302,9 +2340,17 @@ return payload;`)
|
|
|
2302
2340
|
menuTokens: true,
|
|
2303
2341
|
values: {
|
|
2304
2342
|
scopesAll: true,
|
|
2305
|
-
allAccounts: !request.query.account,
|
|
2306
2343
|
account: request.query.account
|
|
2307
2344
|
},
|
|
2345
|
+
// Same expression the POST gate uses, so the form and the thing it submits to
|
|
2346
|
+
// cannot disagree. A token is never invalidated once minted, so one handed to a
|
|
2347
|
+
// caller that reached this page without authenticating would keep working - which
|
|
2348
|
+
// is why the mint is refused rather than merely discouraged. Rendering the form
|
|
2349
|
+
// anyway meant filling it in and losing the work to a 403.
|
|
2350
|
+
canProvision: request.auth.isAuthenticated,
|
|
2351
|
+
...permissionModel,
|
|
2352
|
+
// Handed to the page as data rather than restated in its script
|
|
2353
|
+
permissionSurfacesJson: JSON.stringify(permissionModel.permissionSurfaces),
|
|
2308
2354
|
account: accountData,
|
|
2309
2355
|
accountTokensLink: accountTokensLink.pathname + accountTokensLink.search
|
|
2310
2356
|
},
|
|
@@ -2359,9 +2405,20 @@ return payload;`)
|
|
|
2359
2405
|
scopes: request.payload.scopes
|
|
2360
2406
|
};
|
|
2361
2407
|
|
|
2408
|
+
if (request.payload.permissions) {
|
|
2409
|
+
// An axis that lists nothing is refused by tokenPermissionsSchema, so both mint
|
|
2410
|
+
// paths give the same answer rather than this one carrying its own copy of the rule
|
|
2411
|
+
data.permissions = request.payload.permissions;
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2362
2414
|
if (request.payload.account) {
|
|
2363
|
-
|
|
2364
|
-
|
|
2415
|
+
// Existence probe rather than a full account load: nothing here reads the record,
|
|
2416
|
+
// only whether the ID names one. The ID is typed into the form now rather than
|
|
2417
|
+
// carried over from an account page, so a typo is the likely cause and the answer
|
|
2418
|
+
// has to name the value that was not found.
|
|
2419
|
+
if (!(await accountExists(redis, request.payload.account))) {
|
|
2420
|
+
throw Boom.badRequest(`No account found with ID "${request.payload.account}"`);
|
|
2421
|
+
}
|
|
2365
2422
|
data.account = request.payload.account;
|
|
2366
2423
|
}
|
|
2367
2424
|
|
|
@@ -2372,7 +2429,12 @@ return payload;`)
|
|
|
2372
2429
|
token
|
|
2373
2430
|
};
|
|
2374
2431
|
} catch (err) {
|
|
2375
|
-
request.logger
|
|
2432
|
+
request.logger[authAwareLevel(err)]({
|
|
2433
|
+
msg: 'Failed to generate token',
|
|
2434
|
+
err,
|
|
2435
|
+
remoteAddress: request.app.ip,
|
|
2436
|
+
description: request.payload.description
|
|
2437
|
+
});
|
|
2376
2438
|
if (Boom.isBoom(err)) {
|
|
2377
2439
|
return Object.assign({ success: false }, err.output.payload);
|
|
2378
2440
|
}
|
|
@@ -2395,6 +2457,9 @@ return payload;`)
|
|
|
2395
2457
|
.items(Joi.string().valid('*', 'api', 'metrics', 'smtp', 'imap-proxy'))
|
|
2396
2458
|
.required()
|
|
2397
2459
|
.label('Scopes'),
|
|
2460
|
+
// Null when the restriction is off, which is what "not narrowed" means on the
|
|
2461
|
+
// record - distinct from an empty object, which tokenPermissionsSchema refuses
|
|
2462
|
+
permissions: tokenPermissionsSchema.default(null),
|
|
2398
2463
|
account: accountIdSchema.default(null)
|
|
2399
2464
|
})
|
|
2400
2465
|
}
|
|
@@ -2414,7 +2479,14 @@ return payload;`)
|
|
|
2414
2479
|
return h.redirect('/admin/tokens');
|
|
2415
2480
|
} catch (err) {
|
|
2416
2481
|
await request.flash({ type: 'danger', message: `Couldn't delete token. Try again.` });
|
|
2417
|
-
|
|
2482
|
+
// Only log a partial value: the payload is usually a token id, but it can also be a
|
|
2483
|
+
// raw access token, which must never land in the log whole
|
|
2484
|
+
request.logger.error({
|
|
2485
|
+
msg: 'Failed to delete access token',
|
|
2486
|
+
err,
|
|
2487
|
+
token: request.payload.token ? formatPartialSecretKey(request.payload.token) : null,
|
|
2488
|
+
remoteAddress: request.app.ip
|
|
2489
|
+
});
|
|
2418
2490
|
return h.redirect('/admin/tokens');
|
|
2419
2491
|
}
|
|
2420
2492
|
},
|
|
@@ -2428,12 +2500,19 @@ return payload;`)
|
|
|
2428
2500
|
|
|
2429
2501
|
async failAction(request, h, err) {
|
|
2430
2502
|
await request.flash({ type: 'danger', message: `Couldn't delete token. Try again.` });
|
|
2431
|
-
request.logger.
|
|
2503
|
+
request.logger.debug({ msg: 'Failed to delete access token', err });
|
|
2432
2504
|
|
|
2433
2505
|
return h.redirect('/admin/tokens').takeover();
|
|
2434
2506
|
},
|
|
2435
2507
|
|
|
2436
|
-
payload: Joi.object({
|
|
2508
|
+
payload: Joi.object({
|
|
2509
|
+
token: Joi.string()
|
|
2510
|
+
.length(64)
|
|
2511
|
+
.hex()
|
|
2512
|
+
.required()
|
|
2513
|
+
.example('1bc12baf7f0d5e51fe0a4e0eda06e1be5b8d6cc2c66b95dc0fbe4d2e9f5d5e1a')
|
|
2514
|
+
.description('Access token')
|
|
2515
|
+
})
|
|
2437
2516
|
}
|
|
2438
2517
|
}
|
|
2439
2518
|
});
|
|
@@ -121,7 +121,7 @@ function init(args) {
|
|
|
121
121
|
},
|
|
122
122
|
|
|
123
123
|
async failAction(request, h, err) {
|
|
124
|
-
request.logger.
|
|
124
|
+
request.logger.debug({ msg: 'Failed to validate login arguments', err });
|
|
125
125
|
return h.redirect('/admin/login').takeover();
|
|
126
126
|
},
|
|
127
127
|
|
|
@@ -181,7 +181,7 @@ function init(args) {
|
|
|
181
181
|
try {
|
|
182
182
|
let ipRateLimit = await h.checkRateLimit(`login:ip:${request.app.ip}`, 1, 30, 60);
|
|
183
183
|
if (!ipRateLimit.success) {
|
|
184
|
-
request.logger.
|
|
184
|
+
request.logger.warn({ msg: 'Rate limited', ipRateLimit, remoteAddress: request.app.ip });
|
|
185
185
|
let err = new Error('Rate limited, please wait and try again');
|
|
186
186
|
err.responseText = err.message;
|
|
187
187
|
throw err;
|
|
@@ -189,7 +189,7 @@ function init(args) {
|
|
|
189
189
|
|
|
190
190
|
let rateLimit = await h.checkRateLimit(`login:${request.payload.username}`, 1, 10, 60);
|
|
191
191
|
if (!rateLimit.success) {
|
|
192
|
-
request.logger.
|
|
192
|
+
request.logger.warn({ msg: 'Rate limited', rateLimit, remoteAddress: request.app.ip });
|
|
193
193
|
let err = new Error('Rate limited, please wait and try again');
|
|
194
194
|
err.responseText = err.message;
|
|
195
195
|
throw err;
|
|
@@ -199,20 +199,23 @@ function init(args) {
|
|
|
199
199
|
let totpEnabled = (await settings.get('totpEnabled')) || false;
|
|
200
200
|
|
|
201
201
|
if (authData && authData.user && authData.user !== request.payload.username) {
|
|
202
|
-
request.logger.
|
|
202
|
+
request.logger.warn({ msg: 'Invalid username', username: request.payload.username, method: 'password', remoteAddress: request.app.ip });
|
|
203
203
|
let err = new Error('Failed to authenticate');
|
|
204
204
|
err.details = { password: err.message };
|
|
205
205
|
throw err;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
if (authData && authData.password) {
|
|
209
|
+
let valid;
|
|
209
210
|
try {
|
|
210
|
-
|
|
211
|
-
if (!valid) {
|
|
212
|
-
throw new Error('Invalid password');
|
|
213
|
-
}
|
|
211
|
+
valid = await pbkdf2.verify(authData.password, request.payload.password);
|
|
214
212
|
} catch (E) {
|
|
213
|
+
// verify() only throws on a malformed stored hash, not on a wrong password
|
|
215
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 });
|
|
216
219
|
let err = new Error('Failed to authenticate');
|
|
217
220
|
err.details = { password: err.message };
|
|
218
221
|
throw err;
|
|
@@ -251,7 +254,7 @@ function init(args) {
|
|
|
251
254
|
}
|
|
252
255
|
} catch (err) {
|
|
253
256
|
await request.flash({ type: 'danger', message: err.responseText || `Could not sign in. Check your password and try again.` });
|
|
254
|
-
request.logger.
|
|
257
|
+
request.logger.warn({ msg: 'Failed to authenticate', err, user: request.payload.username, method: 'password', remoteAddress: request.app.ip });
|
|
255
258
|
|
|
256
259
|
let errors = err.details;
|
|
257
260
|
|
|
@@ -294,7 +297,7 @@ function init(args) {
|
|
|
294
297
|
}
|
|
295
298
|
|
|
296
299
|
await request.flash({ type: 'danger', message: `Could not sign in. Check your password and try again.` });
|
|
297
|
-
request.logger.
|
|
300
|
+
request.logger.debug({ msg: 'Failed to authenticate', err, method: 'password', remoteAddress: request.app.ip });
|
|
298
301
|
|
|
299
302
|
return h
|
|
300
303
|
.view(
|
|
@@ -375,7 +378,7 @@ function init(args) {
|
|
|
375
378
|
},
|
|
376
379
|
|
|
377
380
|
async failAction(request, h, err) {
|
|
378
|
-
request.logger.
|
|
381
|
+
request.logger.debug({ msg: 'Failed to validate login arguments', err });
|
|
379
382
|
return h.redirect('/admin/login').takeover();
|
|
380
383
|
},
|
|
381
384
|
|
|
@@ -410,7 +413,7 @@ function init(args) {
|
|
|
410
413
|
// attempt limiter
|
|
411
414
|
let rateLimit = await h.checkRateLimit(`totp:attempt:${request.auth.credentials.user}`, 1, 10, 60);
|
|
412
415
|
if (!rateLimit.success) {
|
|
413
|
-
request.logger.
|
|
416
|
+
request.logger.warn({ msg: 'Rate limited', rateLimit });
|
|
414
417
|
let err = new Error('Rate limited, please wait and try again');
|
|
415
418
|
err.responseText = err.message;
|
|
416
419
|
throw err;
|
|
@@ -434,7 +437,7 @@ function init(args) {
|
|
|
434
437
|
// code re-use limiter
|
|
435
438
|
let reUseLimit = await h.checkRateLimit(`totp:code:${request.payload.code}`, 1, 1, 12 * 60);
|
|
436
439
|
if (!reUseLimit.success) {
|
|
437
|
-
request.logger.
|
|
440
|
+
request.logger.warn({ msg: 'TOTP code recently used', reUseLimit });
|
|
438
441
|
let err = new Error('This code has been already used, please wait and try another code');
|
|
439
442
|
err.responseText = err.message;
|
|
440
443
|
throw err;
|
|
@@ -464,7 +467,7 @@ function init(args) {
|
|
|
464
467
|
await request.flash({ type: 'danger', message: err.responseText || `Could not verify. Check your code and try again.` });
|
|
465
468
|
}
|
|
466
469
|
|
|
467
|
-
request.logger.
|
|
470
|
+
request.logger.warn({
|
|
468
471
|
msg: 'Failed to verify TOTP',
|
|
469
472
|
err,
|
|
470
473
|
user: request.auth && request.auth.credentials && request.auth.credentials.user,
|
|
@@ -507,7 +510,7 @@ function init(args) {
|
|
|
507
510
|
}
|
|
508
511
|
|
|
509
512
|
await request.flash({ type: 'danger', message: `Could not verify. Check your code and try again.` });
|
|
510
|
-
request.logger.
|
|
513
|
+
request.logger.debug({ msg: 'Failed to verify login', err });
|
|
511
514
|
|
|
512
515
|
return h
|
|
513
516
|
.view(
|
|
@@ -579,7 +582,7 @@ function init(args) {
|
|
|
579
582
|
try {
|
|
580
583
|
totp.dataUrl = await QRCode.toDataURL(otpauth_url);
|
|
581
584
|
} catch (err) {
|
|
582
|
-
request.logger.error({ msg: 'QR code
|
|
585
|
+
request.logger.error({ msg: 'Failed to generate QR code', err });
|
|
583
586
|
}
|
|
584
587
|
}
|
|
585
588
|
|
|
@@ -689,7 +692,7 @@ function init(args) {
|
|
|
689
692
|
|
|
690
693
|
async failAction(request, h, err) {
|
|
691
694
|
await request.flash({ type: 'danger', message: `Couldn't enable two-factor auth. Try again.` });
|
|
692
|
-
request.logger.
|
|
695
|
+
request.logger.debug({ msg: 'Failed to enable 2FA', err });
|
|
693
696
|
|
|
694
697
|
return h.redirect('/admin').takeover();
|
|
695
698
|
},
|
|
@@ -718,7 +721,7 @@ function init(args) {
|
|
|
718
721
|
return h.redirect(`/admin/account/security`);
|
|
719
722
|
} catch (err) {
|
|
720
723
|
await request.flash({ type: 'danger', message: `Couldn't disable two-factor auth. Try again.` });
|
|
721
|
-
request.logger.error({ msg: 'Failed to
|
|
724
|
+
request.logger.error({ msg: 'Failed to disable 2FA', err, remoteAddress: request.app.ip });
|
|
722
725
|
return h.redirect(`/admin/account/security`);
|
|
723
726
|
}
|
|
724
727
|
},
|
|
@@ -1018,7 +1021,7 @@ function init(args) {
|
|
|
1018
1021
|
|
|
1019
1022
|
async failAction(request, h, err) {
|
|
1020
1023
|
await request.flash({ type: 'danger', message: 'Failed to remove passkey' });
|
|
1021
|
-
request.logger.
|
|
1024
|
+
request.logger.debug({ msg: 'Failed to delete passkey', err });
|
|
1022
1025
|
return h.redirect('/admin/account/security').takeover();
|
|
1023
1026
|
},
|
|
1024
1027
|
|
|
@@ -1248,13 +1251,16 @@ function init(args) {
|
|
|
1248
1251
|
let authData = await settings.get('authData');
|
|
1249
1252
|
let hasExistingPassword = !!(authData && authData.password);
|
|
1250
1253
|
if (hasExistingPassword) {
|
|
1254
|
+
let valid;
|
|
1251
1255
|
try {
|
|
1252
|
-
|
|
1253
|
-
if (!valid) {
|
|
1254
|
-
throw new Error('Invalid current password');
|
|
1255
|
-
}
|
|
1256
|
+
valid = await pbkdf2.verify(authData.password, request.payload.password0);
|
|
1256
1257
|
} catch (E) {
|
|
1258
|
+
// verify() only throws on a malformed stored hash, not on a wrong password
|
|
1257
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 });
|
|
1258
1264
|
let err = new Error('Failed to verify current password');
|
|
1259
1265
|
err.details = { password0: err.message };
|
|
1260
1266
|
throw err;
|
|
@@ -1347,7 +1353,7 @@ function init(args) {
|
|
|
1347
1353
|
}
|
|
1348
1354
|
|
|
1349
1355
|
await request.flash({ type: 'danger', message: `Couldn't update password. Try again.` });
|
|
1350
|
-
request.logger.
|
|
1356
|
+
request.logger.debug({ msg: 'Failed to update account password', err });
|
|
1351
1357
|
|
|
1352
1358
|
let username = (request.auth && request.auth.credentials && request.auth.credentials.user) || 'admin';
|
|
1353
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
|
},
|