emailengine-app 2.80.0 → 2.81.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/.dockerignore +44 -0
- package/.github/docker-smoke-test.sh +16 -0
- package/.github/workflows/deploy.yml +4 -0
- package/.github/workflows/release.yaml +4 -0
- package/.github/workflows/test.yml +2 -0
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +56 -0
- package/Dockerfile +17 -9
- package/README.md +6 -0
- package/data/google-crawlers.json +1 -1
- package/docker-compose.yml +7 -1
- package/lib/api-routes/account-routes.js +239 -73
- package/lib/api-routes/blocklist-routes.js +24 -0
- package/lib/api-routes/delivery-test-routes.js +6 -0
- package/lib/api-routes/gateway-routes.js +30 -0
- package/lib/api-routes/license-routes.js +10 -0
- package/lib/api-routes/mcp-oauth-routes.js +3 -3
- package/lib/api-routes/mcp-routes.js +39 -21
- package/lib/api-routes/oauth2-app-routes.js +38 -1
- package/lib/api-routes/outbox-routes.js +6 -0
- package/lib/api-routes/permission-map.js +212 -42
- package/lib/api-routes/pubsub-routes.js +8 -0
- package/lib/api-routes/route-helpers.js +58 -11
- package/lib/api-routes/settings-routes.js +50 -4
- package/lib/api-routes/stats-routes.js +6 -0
- package/lib/api-routes/template-routes.js +21 -0
- package/lib/api-routes/token-routes.js +34 -2
- package/lib/api-routes/webhook-route-routes.js +13 -0
- package/lib/autodetect-imap-settings.js +4 -4
- package/lib/email-client/base-client.js +6 -3
- package/lib/email-client/credential-errors.js +4 -0
- package/lib/email-client/imap/login-failure.js +52 -0
- package/lib/email-client/imap/subconnection.js +2 -1
- package/lib/email-client/imap-client.js +3 -6
- package/lib/enum-descriptions.js +12 -2
- package/lib/imapproxy/imap-server.js +1 -1
- package/lib/mcp/oauth.js +46 -8
- package/lib/mcp/protocol.js +78 -35
- package/lib/mcp/tools.js +53 -17
- package/lib/privileged-settings.js +147 -0
- package/lib/schemas.js +60 -16
- package/lib/sentry.js +13 -2
- package/lib/settings.js +13 -0
- package/lib/tls/catalog.js +428 -0
- package/lib/tls/context.js +87 -161
- package/lib/tls/listeners.js +62 -0
- package/lib/tls/provision.js +1 -1
- package/lib/tls/status.js +128 -79
- package/lib/tls/store.js +3 -2
- package/lib/token-permission-view.js +253 -102
- package/lib/token-permissions.js +176 -26
- package/lib/tokens.js +7 -6
- package/lib/tools.js +5 -3
- package/lib/ui-routes/account-routes.js +195 -61
- package/lib/ui-routes/admin-config-routes.js +41 -21
- package/lib/ui-routes/admin-entities-routes.js +32 -22
- package/lib/ui-routes/mcp-consent-routes.js +72 -31
- package/lib/ui-routes/tls-config-routes.js +121 -74
- package/package.json +16 -16
- package/sbom.json +1 -1
- package/server.js +7 -1
- package/static/css/flyonui.css +1 -1
- package/static/css/public.css +41 -0
- package/static/css/src/app.tailwind.css +135 -4
- package/static/js/public.js +218 -0
- package/static/js/ui.js +89 -36
- package/static/licenses.html +55 -37
- package/translations/README.md +4 -3
- package/translations/de.mo +0 -0
- package/translations/de.po +296 -185
- package/translations/en.po +220 -128
- package/translations/es.mo +0 -0
- package/translations/es.po +558 -0
- package/translations/et.mo +0 -0
- package/translations/et.po +288 -181
- package/translations/fr.mo +0 -0
- package/translations/fr.po +295 -183
- package/translations/it.mo +0 -0
- package/translations/it.po +558 -0
- package/translations/ja.mo +0 -0
- package/translations/ja.po +268 -192
- package/translations/locales.json +24 -0
- package/translations/messages.pot +179 -127
- package/translations/nl.mo +0 -0
- package/translations/nl.po +288 -175
- package/translations/pl.mo +0 -0
- package/translations/pl.po +294 -181
- package/translations/sv.mo +0 -0
- package/translations/sv.po +555 -0
- package/translations/tr.mo +0 -0
- package/translations/tr.po +555 -0
- package/update-info.sh +12 -6
- package/views/account/login-redirect.hbs +6 -5
- package/views/account/passkeys.hbs +8 -8
- package/views/account/security.hbs +2 -2
- package/views/accounts/account.hbs +19 -21
- package/views/accounts/browse.hbs +1 -1
- package/views/accounts/edit.hbs +15 -15
- package/views/accounts/index.hbs +3 -3
- package/views/accounts/register/imap-server.hbs +27 -173
- package/views/accounts/register/validating.hbs +139 -0
- package/views/config/ai.hbs +15 -17
- package/views/config/branding.hbs +7 -7
- package/views/config/document-store/chat.hbs +9 -8
- package/views/config/document-store/index.hbs +14 -15
- package/views/config/document-store/mappings/index.hbs +5 -6
- package/views/config/document-store/mappings/new.hbs +1 -2
- package/views/config/document-store/pre-processing/index.hbs +4 -4
- package/views/config/email-processing.hbs +6 -6
- package/views/config/imap-proxy.hbs +7 -8
- package/views/config/license.hbs +9 -9
- package/views/config/logging.hbs +5 -7
- package/views/config/mcp.hbs +90 -58
- package/views/config/network.hbs +4 -4
- package/views/config/oauth/app.hbs +12 -12
- package/views/config/oauth/index.hbs +6 -6
- package/views/config/oauth/subscriptions.hbs +9 -9
- package/views/config/security.hbs +5 -7
- package/views/config/service.hbs +11 -10
- package/views/config/smtp.hbs +9 -12
- package/views/config/tls-upload.hbs +3 -3
- package/views/config/tls.hbs +281 -182
- package/views/config/webhooks.hbs +12 -15
- package/views/dashboard.hbs +9 -8
- package/views/gateways/edit.hbs +3 -3
- package/views/gateways/gateway.hbs +3 -3
- package/views/gateways/index.hbs +6 -6
- package/views/gateways/new.hbs +3 -3
- package/views/internals/index.hbs +15 -13
- package/views/layout/app.hbs +6 -6
- package/views/layout/login.hbs +32 -19
- package/views/layout/main.hbs +2 -2
- package/views/layout/prompt.hbs +15 -18
- package/views/layout/public.hbs +1 -1
- package/views/mcp/authorize.hbs +47 -45
- package/views/partials/accounts_table.hbs +5 -5
- package/views/partials/ace_assets.hbs +1 -1
- package/views/partials/add_account_modal.hbs +4 -4
- package/views/partials/address_list.hbs +4 -4
- package/views/partials/filter_editor_js.hbs +2 -2
- package/views/partials/gateway_form.hbs +5 -5
- package/views/partials/gateway_js.hbs +1 -1
- package/views/partials/mcp_access_levels.hbs +16 -9
- package/views/partials/mcp_account_limit.hbs +2 -2
- package/views/partials/mcp_tool_count.hbs +15 -14
- package/views/partials/oauth_config_header.hbs +2 -2
- package/views/partials/oauth_form.hbs +37 -42
- package/views/partials/public_alerts.hbs +1 -1
- package/views/partials/public_test_labels.hbs +15 -0
- package/views/partials/public_theme_init.hbs +1 -1
- package/views/partials/security_header.hbs +2 -2
- package/views/partials/template_form.hbs +4 -4
- package/views/partials/theme_init.hbs +1 -1
- package/views/partials/tls_security_card.hbs +4 -1
- package/views/partials/ui/form-field.hbs +6 -1
- package/views/partials/ui/setting-ref.hbs +12 -7
- package/views/partials/ui/stat-card.hbs +4 -1
- package/views/partials/ui/tabs.hbs +3 -7
- package/views/partials/webhook_form.hbs +9 -12
- package/views/partials/webhooks_editor_functions.hbs +1 -1
- package/views/reference/index.hbs +3 -3
- package/views/reference/redirect.hbs +1 -1
- package/views/reference/tag.hbs +1 -1
- package/views/reference/token.hbs +4 -4
- package/views/suppression-lists/index.hbs +8 -6
- package/views/suppression-lists/list.hbs +13 -8
- package/views/templates/edit.hbs +1 -1
- package/views/templates/index.hbs +10 -11
- package/views/templates/template.hbs +5 -5
- package/views/tokens/index.hbs +17 -17
- package/views/tokens/new.hbs +190 -93
- package/views/unsubscribe.hbs +1 -1
- package/views/webhooks/edit.hbs +1 -1
- package/views/webhooks/index.hbs +10 -11
- package/views/webhooks/new.hbs +1 -1
- package/views/webhooks/webhook.hbs +5 -6
- package/workers/api.js +9 -8
- package/workers/smtp.js +1 -1
|
@@ -21,7 +21,7 @@ const Boom = require('@hapi/boom');
|
|
|
21
21
|
const settings = require('../settings');
|
|
22
22
|
const { isMcpEnabled, MCP_DISABLED_MESSAGE } = require('../mcp');
|
|
23
23
|
const { processMcpRequest, isAllowedOrigin, acceptsEventStream, rpcError, ERROR_CODES, serverInstructions } = require('../mcp/protocol');
|
|
24
|
-
const { getToolRegistry, callTool, listToolsFor } = require('../mcp/tools');
|
|
24
|
+
const { getToolRegistry, callTool, listToolsFor, catalogSurfaces } = require('../mcp/tools');
|
|
25
25
|
const { listResources, readResource } = require('../mcp/resources');
|
|
26
26
|
const { acceptFilter, openListenStream, canOpenListenStream, MAX_STREAMS_PER_CREDENTIAL } = require('../mcp/listen');
|
|
27
27
|
|
|
@@ -56,18 +56,31 @@ async function init(args) {
|
|
|
56
56
|
|
|
57
57
|
const boundAccount = request.app.mcpBoundAccount;
|
|
58
58
|
|
|
59
|
+
// A credential sees the surface it can actually use, so the agent does not plan
|
|
60
|
+
// around tools that would only ever answer it with a 403: a bound credential loses
|
|
61
|
+
// the instance-wide listings (list_accounts, get_outbox) and the `account` argument
|
|
62
|
+
// of everything else, a token holding one MCP scope loses the other scope's tools,
|
|
63
|
+
// and a permission-narrowed token loses the tools whose grant its record refuses -
|
|
64
|
+
// the same checks the injected inner request would enforce, asked ahead of time.
|
|
65
|
+
// Advertisement only: tools/call still dispatches whatever is asked, and the inner
|
|
66
|
+
// request stays the enforcement.
|
|
67
|
+
//
|
|
68
|
+
// Computed on first use and at most once per request: only tools/list and the
|
|
69
|
+
// discovery methods read the catalog, and only the latter read the instructions, so
|
|
70
|
+
// a tools/call or a ping pays for neither.
|
|
71
|
+
//
|
|
72
|
+
// Auth mode is required and every strategy success path sets artifacts (the token
|
|
73
|
+
// record, or {} for the preauth caller).
|
|
74
|
+
let catalog = null;
|
|
75
|
+
const listTools = () => {
|
|
76
|
+
if (!catalog) {
|
|
77
|
+
catalog = listToolsFor(server, { tokenData: request.auth.artifacts, boundAccount });
|
|
78
|
+
}
|
|
79
|
+
return catalog;
|
|
80
|
+
};
|
|
81
|
+
|
|
59
82
|
const ctx = {
|
|
60
|
-
|
|
61
|
-
// around tools that would only ever answer it with a 403: a bound credential
|
|
62
|
-
// loses the instance-wide listings (list_accounts, get_outbox) and the `account`
|
|
63
|
-
// argument of everything else, and a permission-narrowed token loses the tools
|
|
64
|
-
// whose grant its record refuses - the same check the injected inner request
|
|
65
|
-
// would enforce, asked ahead of time. Advertisement only: tools/call still
|
|
66
|
-
// dispatches whatever is asked, and the inner request stays the enforcement.
|
|
67
|
-
//
|
|
68
|
-
// Auth mode is required and every strategy success path sets artifacts (the token
|
|
69
|
-
// record, or {} for the preauth caller).
|
|
70
|
-
listTools: () => listToolsFor(server, { tokenData: request.auth.artifacts, boundAccount }),
|
|
83
|
+
listTools,
|
|
71
84
|
|
|
72
85
|
callTool: async (name, toolArgs) => {
|
|
73
86
|
const tool = getToolRegistry(server).byName.get(name);
|
|
@@ -82,10 +95,15 @@ async function init(args) {
|
|
|
82
95
|
listResources: () => listResources({ server, request }),
|
|
83
96
|
readResource: uri => readResource({ server, request, uri }),
|
|
84
97
|
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
|
|
98
|
+
// Written for this credential: which tool sets it holds, read off the catalog it
|
|
99
|
+
// is advertised rather than off its scopes (a narrowed record can empty a scope
|
|
100
|
+
// out, and the instructions should describe the tools the agent will see), and
|
|
101
|
+
// whether it is bound to one account (in which case the generic opening - call
|
|
102
|
+
// list_accounts, then pass the id - describes a workflow it cannot perform)
|
|
103
|
+
get instructions() {
|
|
104
|
+
const advertised = listTools();
|
|
105
|
+
return serverInstructions({ account: boundAccount, surfaces: catalogSurfaces(server, advertised), hasTools: advertised.length > 0 });
|
|
106
|
+
},
|
|
89
107
|
|
|
90
108
|
acceptsEventStream: acceptsEventStream(request.headers.accept)
|
|
91
109
|
};
|
|
@@ -120,11 +138,11 @@ async function init(args) {
|
|
|
120
138
|
description: 'MCP endpoint',
|
|
121
139
|
notes: ['JSON-RPC endpoint implementing the Model Context Protocol Streamable HTTP transport'],
|
|
122
140
|
|
|
123
|
-
// `external`: no CSRF crumb and no OpenAPI operation.
|
|
124
|
-
// do over MCP whatever they can do over REST, and `mcp`
|
|
125
|
-
//
|
|
126
|
-
// workers/api.js).
|
|
127
|
-
tags: ['external', 'scope:api', 'scope:mcp'],
|
|
141
|
+
// `external`: no CSRF crumb and no OpenAPI operation. Three scopes: `api` tokens can
|
|
142
|
+
// do over MCP whatever they can do over REST, and `mcp` (mail) and `mcp-manage`
|
|
143
|
+
// (instance management) tokens are surface-bound credentials this endpoint admits
|
|
144
|
+
// and plain REST refuses (see the scope check in workers/api.js).
|
|
145
|
+
tags: ['external', 'scope:api', 'scope:mcp', 'scope:mcp-manage'],
|
|
128
146
|
|
|
129
147
|
plugins: {
|
|
130
148
|
mcp: { endpoint: true }
|
|
@@ -16,7 +16,7 @@ const {
|
|
|
16
16
|
ENUM_DESCRIPTIONS
|
|
17
17
|
} = require('../schemas');
|
|
18
18
|
const { handleError, throwNotFound, flattenOAuthAppMeta, MASKED } = require('./route-helpers');
|
|
19
|
-
const { ENCRYPTED_APP_KEYS } = require('../consts');
|
|
19
|
+
const { ENCRYPTED_APP_KEYS, MCP_MAX_PAGE_SIZE } = require('../consts');
|
|
20
20
|
const { IMPACT } = require('./operation-impact');
|
|
21
21
|
|
|
22
22
|
// Stored fields that are returned on OAuth2 application objects in addition to the basic fields
|
|
@@ -101,6 +101,13 @@ async function init(args) {
|
|
|
101
101
|
tags: ['api', 'OAuth2 Applications'],
|
|
102
102
|
|
|
103
103
|
plugins: {
|
|
104
|
+
mcp: {
|
|
105
|
+
name: 'list_oauth2_apps',
|
|
106
|
+
title: 'List OAuth2 applications',
|
|
107
|
+
description:
|
|
108
|
+
'List the OAuth2 applications (Gmail, Outlook and other providers) that accounts can sign in through, paged. Client secrets are masked.',
|
|
109
|
+
bounds: { pageSize: MCP_MAX_PAGE_SIZE }
|
|
110
|
+
},
|
|
104
111
|
openapi: {
|
|
105
112
|
responses: apiResponses('Returns a page of OAuth2 applications.', 400, 401, 403, 429, 500)
|
|
106
113
|
}
|
|
@@ -249,6 +256,11 @@ async function init(args) {
|
|
|
249
256
|
tags: ['api', 'OAuth2 Applications'],
|
|
250
257
|
|
|
251
258
|
plugins: {
|
|
259
|
+
mcp: {
|
|
260
|
+
name: 'get_oauth2_app',
|
|
261
|
+
title: 'Get OAuth2 application',
|
|
262
|
+
description: 'Get one OAuth2 application: its provider, client id, scopes, redirect URL and Pub/Sub settings. Client secrets are masked.'
|
|
263
|
+
},
|
|
252
264
|
openapi: {
|
|
253
265
|
responses: apiResponses('Returns the OAuth2 application. Client secrets are masked.', 400, 401, 403, 404, 429, 500)
|
|
254
266
|
}
|
|
@@ -359,6 +371,12 @@ async function init(args) {
|
|
|
359
371
|
tags: ['api', 'OAuth2 Applications'],
|
|
360
372
|
|
|
361
373
|
plugins: {
|
|
374
|
+
mcp: {
|
|
375
|
+
name: 'create_oauth2_app',
|
|
376
|
+
title: 'Create OAuth2 application',
|
|
377
|
+
description:
|
|
378
|
+
'Register an OAuth2 application that accounts can sign in through. Needs the provider and the client credentials created at that provider; a client secret or service key can be written but never read back. Confirm the redirect URL with the user: it is where the provider sends authorization codes and has to match what the provider has on file.'
|
|
379
|
+
},
|
|
362
380
|
openapi: {
|
|
363
381
|
responses: apiResponses('Returns the registered OAuth2 application.', 400, 401, 403, 429, 500)
|
|
364
382
|
}
|
|
@@ -409,6 +427,12 @@ async function init(args) {
|
|
|
409
427
|
tags: ['api', 'OAuth2 Applications'],
|
|
410
428
|
|
|
411
429
|
plugins: {
|
|
430
|
+
mcp: {
|
|
431
|
+
name: 'update_oauth2_app',
|
|
432
|
+
title: 'Update OAuth2 application',
|
|
433
|
+
description:
|
|
434
|
+
'Update an OAuth2 application. Send only the fields to change; a client secret can be replaced but not read back. Changing the redirect URL moves where the provider sends authorization codes, so confirm that with the user.'
|
|
435
|
+
},
|
|
412
436
|
openapi: {
|
|
413
437
|
responses: apiResponses('Returns the updated OAuth2 application.', 400, 401, 403, 404, 429, 500)
|
|
414
438
|
}
|
|
@@ -560,6 +584,12 @@ async function init(args) {
|
|
|
560
584
|
tags: ['api', 'OAuth2 Applications'],
|
|
561
585
|
|
|
562
586
|
plugins: {
|
|
587
|
+
mcp: {
|
|
588
|
+
name: 'delete_oauth2_app',
|
|
589
|
+
title: 'Delete OAuth2 application',
|
|
590
|
+
description:
|
|
591
|
+
'Remove an OAuth2 application. Accounts that signed in through it can no longer refresh their access tokens and stop syncing. Confirm with the user before calling this.'
|
|
592
|
+
},
|
|
563
593
|
openapi: {
|
|
564
594
|
'x-ee-impact': IMPACT.DESTRUCTIVE,
|
|
565
595
|
responses: apiResponses('Returns a deletion marker.', 400, 401, 403, 404, 429, 500)
|
|
@@ -616,6 +646,13 @@ async function init(args) {
|
|
|
616
646
|
tags: ['api', 'OAuth2 Applications'],
|
|
617
647
|
|
|
618
648
|
plugins: {
|
|
649
|
+
mcp: {
|
|
650
|
+
name: 'verify_oauth2_app',
|
|
651
|
+
title: 'Verify OAuth2 application',
|
|
652
|
+
description:
|
|
653
|
+
'Check an OAuth2 application against its provider: the credentials, the Pub/Sub setup where it has one, and optionally the connection of one account that uses it.',
|
|
654
|
+
openWorld: true
|
|
655
|
+
},
|
|
619
656
|
openapi: {
|
|
620
657
|
'x-ee-impact': IMPACT.READONLY,
|
|
621
658
|
responses: apiResponses('Returns the outcome of the credential check against the provider.', 400, 401, 403, 404, 429, 500)
|
|
@@ -162,6 +162,12 @@ async function init(args) {
|
|
|
162
162
|
tags: ['api', 'Outbox'],
|
|
163
163
|
|
|
164
164
|
plugins: {
|
|
165
|
+
mcp: {
|
|
166
|
+
name: 'cancel_queued_message',
|
|
167
|
+
title: 'Cancel queued message',
|
|
168
|
+
description:
|
|
169
|
+
'Cancel a message waiting in the sending queue, by the queue id from get_outbox. A message already handed to the mail server cannot be cancelled.'
|
|
170
|
+
},
|
|
165
171
|
openapi: {
|
|
166
172
|
'x-ee-impact': IMPACT.DESTRUCTIVE,
|
|
167
173
|
responses: apiResponses('Returns a deletion marker. A message already being delivered cannot be removed.', 400, 401, 403, 429, 500)
|
|
@@ -108,6 +108,33 @@ const GROUP = {
|
|
|
108
108
|
// mailbox a reader of the protocol trace as well.
|
|
109
109
|
LOGS: 'logs',
|
|
110
110
|
|
|
111
|
+
// Instance settings and the two queues. A write here reaches the global webhook target and
|
|
112
|
+
// every notification knob, and is disclosed as such wherever the grant is offered. The keys
|
|
113
|
+
// that would make the holder more than a settings editor are refused to a narrowed token by
|
|
114
|
+
// assertNoPrivilegedSettings() in ./route-helpers.js, keyed on PRIVILEGED_SETTINGS_KEYS in
|
|
115
|
+
// lib/privileged-settings.js, which also renders the phrase every description of the rule uses.
|
|
116
|
+
SETTINGS: 'settings',
|
|
117
|
+
|
|
118
|
+
// OAuth2 applications. Secrets are write-only (every read masks them), but a write can move
|
|
119
|
+
// an application's redirect URL, which is where the provider sends authorization codes.
|
|
120
|
+
OAUTH2: 'oauth2',
|
|
121
|
+
|
|
122
|
+
// The license: read it, apply one, remove it
|
|
123
|
+
LICENSE: 'license',
|
|
124
|
+
|
|
125
|
+
// Access tokens: list, inspect, read the audit log of, revoke. Minting is NOT here - it stays
|
|
126
|
+
// in ADMIN, because a token that can mint tokens can widen itself.
|
|
127
|
+
TOKEN: 'token',
|
|
128
|
+
|
|
129
|
+
// Adding accounts and gateways, and reconfiguring them, including where they connect. Its own
|
|
130
|
+
// group rather than a write on `account` or `gateway` because both records keep their stored
|
|
131
|
+
// credential across a partial update, so a change to nothing but `host` makes the next
|
|
132
|
+
// connection authenticate to the new host with the old password - a token issued with write
|
|
133
|
+
// access to accounts before this group existed must not gain that. Disclosed on every screen
|
|
134
|
+
// that offers the grant. `proxy` in these payloads is refused to a narrowed token by
|
|
135
|
+
// assertNoNetworkOverride(), like the submit payloads.
|
|
136
|
+
PROVISIONING: 'provisioning',
|
|
137
|
+
|
|
111
138
|
// Never grantable. See NEVER_GRANTABLE below.
|
|
112
139
|
ADMIN: 'admin'
|
|
113
140
|
};
|
|
@@ -121,6 +148,31 @@ const NEVER_GRANTABLE = new Set([GROUP.ADMIN]);
|
|
|
121
148
|
|
|
122
149
|
const GRANTABLE_GROUPS = Object.values(GROUP).filter(group => !NEVER_GRANTABLE.has(group));
|
|
123
150
|
|
|
151
|
+
// What a two-axis record that omits `groups` reaches: the sections that were grantable when the
|
|
152
|
+
// two-axis form shipped in 2.79.0, and nothing added since. The record's schema promised "omit to
|
|
153
|
+
// allow all of them", and every record written under that promise was written when these were all
|
|
154
|
+
// there was. Reading an absent axis as the live GRANTABLE_GROUPS would have handed every such
|
|
155
|
+
// record the five instance sections the admin split created - a `{ actions: ['read', 'write'] }`
|
|
156
|
+
// token minted through the API on 2.79 would have woken up on 2.80 able to retarget an account's
|
|
157
|
+
// host and move the webhook target. So the instance sections are reachable only by a record that
|
|
158
|
+
// names them, and a section added later joins GRANTABLE_GROUPS and not this list.
|
|
159
|
+
// test/token-permissions-test.js pins it to these thirteen names.
|
|
160
|
+
const IMPLICIT_GROUPS = Object.freeze([
|
|
161
|
+
GROUP.ACCOUNT,
|
|
162
|
+
GROUP.MAILBOX,
|
|
163
|
+
GROUP.MESSAGE,
|
|
164
|
+
GROUP.SUBMIT,
|
|
165
|
+
GROUP.OUTBOX,
|
|
166
|
+
GROUP.EXPORT,
|
|
167
|
+
GROUP.TEMPLATE,
|
|
168
|
+
GROUP.BLOCKLIST,
|
|
169
|
+
GROUP.WEBHOOK,
|
|
170
|
+
GROUP.GATEWAY,
|
|
171
|
+
GROUP.EVENTS,
|
|
172
|
+
GROUP.DIAGNOSTICS,
|
|
173
|
+
GROUP.LOGS
|
|
174
|
+
]);
|
|
175
|
+
|
|
124
176
|
// Every grant a non-HTTP surface can exercise once it has authenticated, rather than the one it
|
|
125
177
|
// nominally performs. These surfaces are checked once at login and never again, so a token is
|
|
126
178
|
// admitted only if it holds ALL of them.
|
|
@@ -164,23 +216,79 @@ const SURFACE_GRANTS = {
|
|
|
164
216
|
{ action: ACTION.SEND, group: GROUP.SUBMIT },
|
|
165
217
|
{ action: ACTION.READ, group: GROUP.OUTBOX },
|
|
166
218
|
{ action: ACTION.READ, group: GROUP.TEMPLATE }
|
|
219
|
+
],
|
|
220
|
+
|
|
221
|
+
// The management half of the MCP endpoint: the same door, checked per request the same way,
|
|
222
|
+
// but a second scope with its own table. A second scope rather than a longer `mcp` list on
|
|
223
|
+
// purpose: the "Full access" level of the consent page used to mint a token with no
|
|
224
|
+
// permissions record, bounded by the `mcp` table alone, and growing that table would have
|
|
225
|
+
// handed every such token the management tools on upgrade. This one leaves every issued
|
|
226
|
+
// credential exactly as wide as it was.
|
|
227
|
+
//
|
|
228
|
+
// Reads about the instance, the writes that operate it, and the deletions an administrator
|
|
229
|
+
// makes. Deliberately absent: `send/submit` (mail, in the table above), `export` (one call
|
|
230
|
+
// archives an account), `events` (a stream, not a tool), `destructive/license` (no agent use
|
|
231
|
+
// case, only harm), and every `admin` route. The three read pairs shared with the mail table
|
|
232
|
+
// are shared on purpose - an agent managing the instance needs to list accounts too.
|
|
233
|
+
'mcp-manage': [
|
|
234
|
+
{ action: ACTION.READ, group: GROUP.ACCOUNT },
|
|
235
|
+
{ action: ACTION.WRITE, group: GROUP.ACCOUNT },
|
|
236
|
+
{ action: ACTION.DESTRUCTIVE, group: GROUP.ACCOUNT },
|
|
237
|
+
{ action: ACTION.READ, group: GROUP.SETTINGS },
|
|
238
|
+
{ action: ACTION.WRITE, group: GROUP.SETTINGS },
|
|
239
|
+
{ action: ACTION.READ, group: GROUP.OAUTH2 },
|
|
240
|
+
{ action: ACTION.WRITE, group: GROUP.OAUTH2 },
|
|
241
|
+
{ action: ACTION.DESTRUCTIVE, group: GROUP.OAUTH2 },
|
|
242
|
+
{ action: ACTION.READ, group: GROUP.LICENSE },
|
|
243
|
+
{ action: ACTION.WRITE, group: GROUP.LICENSE },
|
|
244
|
+
{ action: ACTION.READ, group: GROUP.TOKEN },
|
|
245
|
+
{ action: ACTION.DESTRUCTIVE, group: GROUP.TOKEN },
|
|
246
|
+
{ action: ACTION.READ, group: GROUP.PROVISIONING },
|
|
247
|
+
{ action: ACTION.WRITE, group: GROUP.PROVISIONING },
|
|
248
|
+
{ action: ACTION.READ, group: GROUP.GATEWAY },
|
|
249
|
+
{ action: ACTION.DESTRUCTIVE, group: GROUP.GATEWAY },
|
|
250
|
+
{ action: ACTION.READ, group: GROUP.WEBHOOK },
|
|
251
|
+
{ action: ACTION.READ, group: GROUP.BLOCKLIST },
|
|
252
|
+
{ action: ACTION.WRITE, group: GROUP.BLOCKLIST },
|
|
253
|
+
{ action: ACTION.DESTRUCTIVE, group: GROUP.BLOCKLIST },
|
|
254
|
+
{ action: ACTION.READ, group: GROUP.TEMPLATE },
|
|
255
|
+
{ action: ACTION.WRITE, group: GROUP.TEMPLATE },
|
|
256
|
+
{ action: ACTION.DESTRUCTIVE, group: GROUP.TEMPLATE },
|
|
257
|
+
{ action: ACTION.READ, group: GROUP.OUTBOX },
|
|
258
|
+
{ action: ACTION.DESTRUCTIVE, group: GROUP.OUTBOX },
|
|
259
|
+
{ action: ACTION.READ, group: GROUP.DIAGNOSTICS },
|
|
260
|
+
{ action: ACTION.READ, group: GROUP.LOGS }
|
|
167
261
|
]
|
|
168
262
|
};
|
|
169
263
|
|
|
264
|
+
// The two MCP scopes by what they are for, so the modules that reason about "the management
|
|
265
|
+
// half" and "the mail half" (the access sections, the instructions, the catalog grouping) name
|
|
266
|
+
// them through this rather than spelling the slugs again.
|
|
267
|
+
const MCP_SCOPES = {
|
|
268
|
+
manage: 'mcp-manage',
|
|
269
|
+
mail: 'mcp'
|
|
270
|
+
};
|
|
271
|
+
|
|
170
272
|
// The quantifier over SURFACE_GRANTS differs by surface, and consumers must not hard-code their
|
|
171
273
|
// own: the login-time surfaces (smtp, imap-proxy, metrics) admit a token only if it holds ALL of
|
|
172
274
|
// their grants, because they are checked once and then hand over a session; a per-request
|
|
173
275
|
// surface admits a request when ANY single grant covers it, because every request is checked on
|
|
174
276
|
// its own. The admin token form renders its scope warning from this distinction too.
|
|
175
|
-
const PER_REQUEST_SURFACES = new Set([
|
|
277
|
+
const PER_REQUEST_SURFACES = new Set([MCP_SCOPES.mail, MCP_SCOPES.manage]);
|
|
176
278
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
279
|
+
// The `action:group` spelling of a pair, the key every set of pairs below is built on
|
|
280
|
+
const grantKey = grant => `${grant.action}:${grant.group}`;
|
|
281
|
+
|
|
282
|
+
const grantKeySet = grants => new Set((grants || []).map(grantKey));
|
|
283
|
+
|
|
284
|
+
// One membership set per surface, built once: the per-request predicate below runs for every
|
|
285
|
+
// tool of every tools/list and for every MCP-dispatched request, and the management table has
|
|
286
|
+
// two dozen entries
|
|
287
|
+
const SURFACE_GRANT_KEYS = Object.fromEntries(Object.entries(SURFACE_GRANTS).map(([scope, grants]) => [scope, grantKeySet(grants)]));
|
|
180
288
|
|
|
181
289
|
/**
|
|
182
290
|
* Whether one operation is inside a surface's grant list. This is the per-request quantifier -
|
|
183
|
-
* the api-token strategy asks it for the
|
|
291
|
+
* the api-token strategy asks it for the MCP scopes, and test/mcp-tools-test.js asserts every
|
|
184
292
|
* exposed tool against it, so the guardrail and the enforcement share one predicate.
|
|
185
293
|
*
|
|
186
294
|
* @param {String} scope - a SURFACE_GRANTS key
|
|
@@ -188,7 +296,44 @@ function grantListAdmits(grants, grant) {
|
|
|
188
296
|
* @returns {Boolean}
|
|
189
297
|
*/
|
|
190
298
|
function surfaceAdmits(scope, grant) {
|
|
191
|
-
|
|
299
|
+
const keys = SURFACE_GRANT_KEYS[scope];
|
|
300
|
+
return !!keys && keys.has(grantKey(grant));
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Whether the per-request surface scopes a token holds admit one operation.
|
|
305
|
+
*
|
|
306
|
+
* The rule the api-token strategy applies to an MCP-dispatched request: a token holding `mcp`,
|
|
307
|
+
* `mcp-manage` or both is admitted to a route when any held scope's table covers the route's
|
|
308
|
+
* grant. Written once here so the strategy and tools/list (through surfaceBoundAdmits) cannot
|
|
309
|
+
* disagree about which scope reaches which tool.
|
|
310
|
+
*
|
|
311
|
+
* @param {Array} scopes - the token's scope list
|
|
312
|
+
* @param {{action: String, group: String}} grant - the operation, from routeGrant()
|
|
313
|
+
* @returns {Boolean}
|
|
314
|
+
*/
|
|
315
|
+
function perRequestSurfaceAdmits(scopes, grant) {
|
|
316
|
+
return Array.isArray(scopes) && scopes.some(scope => PER_REQUEST_SURFACES.has(scope) && surfaceAdmits(scope, grant));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Whether a token's scopes leave one operation reachable over MCP at all.
|
|
321
|
+
*
|
|
322
|
+
* A token with no scope list, with `*`, or with `api` reaches every route its permissions allow,
|
|
323
|
+
* so the bound is only the surface tables of the per-request scopes it holds. For tools/list,
|
|
324
|
+
* which advertises a credential the tools it can actually call: the permission record is the
|
|
325
|
+
* other half of that answer, and lib/token-permissions.js owns it.
|
|
326
|
+
*
|
|
327
|
+
* @param {Object} tokenData - the token record, as the auth strategy leaves it in artifacts
|
|
328
|
+
* @param {{action: String, group: String}} grant - the operation, from routeGrant()
|
|
329
|
+
* @returns {Boolean}
|
|
330
|
+
*/
|
|
331
|
+
function surfaceBoundAdmits(tokenData, grant) {
|
|
332
|
+
const scopes = tokenData && tokenData.scopes;
|
|
333
|
+
if (!Array.isArray(scopes) || scopes.includes('*') || scopes.includes('api')) {
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
return perRequestSurfaceAdmits(scopes, grant);
|
|
192
337
|
}
|
|
193
338
|
|
|
194
339
|
/**
|
|
@@ -233,11 +378,13 @@ const SESSION_TOKEN_GRANTS = [
|
|
|
233
378
|
* @param {String} [opts.account] - the account the request names, from request.params
|
|
234
379
|
* @returns {Boolean}
|
|
235
380
|
*/
|
|
381
|
+
const SESSION_TOKEN_GRANT_KEYS = grantKeySet(SESSION_TOKEN_GRANTS);
|
|
382
|
+
|
|
236
383
|
function sessionTokenAdmits(grant, opts) {
|
|
237
384
|
if (!opts || !opts.account) {
|
|
238
385
|
return false;
|
|
239
386
|
}
|
|
240
|
-
return
|
|
387
|
+
return SESSION_TOKEN_GRANT_KEYS.has(grantKey(grant));
|
|
241
388
|
}
|
|
242
389
|
|
|
243
390
|
// Membership sets for the two vocabularies. lib/token-permissions.js rejects a record naming
|
|
@@ -270,7 +417,7 @@ function routeKey(method, path) {
|
|
|
270
417
|
// build rather than drifting.
|
|
271
418
|
const GROUP_ROUTES = {
|
|
272
419
|
// Reading an account and operating on its connection. Creating one and editing its
|
|
273
|
-
// configuration are NOT here - see the note on those two entries under
|
|
420
|
+
// configuration are NOT here - see the note on those two entries under PROVISIONING.
|
|
274
421
|
[GROUP.ACCOUNT]: [
|
|
275
422
|
'GET /v1/accounts',
|
|
276
423
|
'GET /v1/account/{account}',
|
|
@@ -335,9 +482,9 @@ const GROUP_ROUTES = {
|
|
|
335
482
|
|
|
336
483
|
[GROUP.WEBHOOK]: ['GET /v1/webhookRoutes', 'GET /v1/webhookRoutes/webhookRoute/{webhookRoute}'],
|
|
337
484
|
|
|
338
|
-
// Reading a gateway and removing one. The two WRITES are in
|
|
339
|
-
// redirect where the stored relay credentials are sent - so they are deliberately absent
|
|
340
|
-
// rather than listed in both places.
|
|
485
|
+
// Reading a gateway and removing one. The two WRITES are in PROVISIONING below, because they
|
|
486
|
+
// can redirect where the stored relay credentials are sent - so they are deliberately absent
|
|
487
|
+
// here rather than listed in both places.
|
|
341
488
|
[GROUP.GATEWAY]: ['GET /v1/gateways', 'GET /v1/gateway/{gateway}', 'DELETE /v1/gateway/{gateway}'],
|
|
342
489
|
|
|
343
490
|
[GROUP.EVENTS]: ['GET /v1/changes'],
|
|
@@ -357,55 +504,52 @@ const GROUP_ROUTES = {
|
|
|
357
504
|
|
|
358
505
|
[GROUP.LOGS]: ['GET /v1/logs/{account}'],
|
|
359
506
|
|
|
360
|
-
//
|
|
361
|
-
//
|
|
362
|
-
//
|
|
363
|
-
//
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
'PUT /v1/settings/queue/{queue}',
|
|
507
|
+
// The five groups below used to be the admin block. They were split out so an agent that
|
|
508
|
+
// manages the instance can hold them, and each went to a NEW group rather than into one that
|
|
509
|
+
// already existed: a record cannot name a group that did not exist when it was written, and a
|
|
510
|
+
// record that names no groups at all reaches IMPLICIT_GROUPS, which stops at the split, so no
|
|
511
|
+
// token issued before the split gained a route from it. test/api-routes-table-test.js asserts
|
|
512
|
+
// the pre-split groups still hold exactly the routes they held.
|
|
513
|
+
|
|
514
|
+
[GROUP.SETTINGS]: ['GET /v1/settings', 'POST /v1/settings', 'GET /v1/settings/queue/{queue}', 'PUT /v1/settings/queue/{queue}'],
|
|
369
515
|
|
|
516
|
+
[GROUP.OAUTH2]: [
|
|
370
517
|
'GET /v1/oauth2',
|
|
371
518
|
'POST /v1/oauth2',
|
|
372
519
|
'GET /v1/oauth2/{app}',
|
|
373
520
|
'PUT /v1/oauth2/{app}',
|
|
374
521
|
'DELETE /v1/oauth2/{app}',
|
|
375
|
-
'POST /v1/oauth2/{app}/verify'
|
|
522
|
+
'POST /v1/oauth2/{app}/verify'
|
|
523
|
+
],
|
|
376
524
|
|
|
377
|
-
|
|
378
|
-
'POST /v1/license',
|
|
379
|
-
'DELETE /v1/license',
|
|
525
|
+
[GROUP.LICENSE]: ['GET /v1/license', 'POST /v1/license', 'DELETE /v1/license'],
|
|
380
526
|
|
|
381
|
-
|
|
382
|
-
|
|
527
|
+
// Everything about tokens except minting one, which is under ADMIN
|
|
528
|
+
[GROUP.TOKEN]: [
|
|
383
529
|
'GET /v1/tokens',
|
|
384
|
-
|
|
385
|
-
//
|
|
530
|
+
'DELETE /v1/tokens/{token}',
|
|
531
|
+
// Who read whose mail with this credential. The trail is at least as sensitive as the
|
|
532
|
+
// requests in it, which the group description says.
|
|
386
533
|
'GET /v1/tokens/{token}',
|
|
387
534
|
'GET /v1/tokens/{token}/log',
|
|
388
|
-
// Deprecated pre-2.79 aliases
|
|
389
|
-
'POST /v1/token',
|
|
535
|
+
// Deprecated pre-2.79 aliases (see lib/api-routes/token-routes.js)
|
|
390
536
|
'DELETE /v1/token/{token}',
|
|
391
|
-
'GET /v1/tokens/account/{account}'
|
|
392
|
-
|
|
393
|
-
// Returns a live OAuth2 access token for the account: a mail credential in its own right,
|
|
394
|
-
// which outlives any narrowing on the token that fetched it
|
|
395
|
-
'GET /v1/account/{account}/oauth-token',
|
|
537
|
+
'GET /v1/tokens/account/{account}'
|
|
538
|
+
],
|
|
396
539
|
|
|
540
|
+
[GROUP.PROVISIONING]: [
|
|
397
541
|
// Editing an account is a credential operation even when the payload carries no credential,
|
|
398
|
-
// which is why it sits here and not in the
|
|
399
|
-
//
|
|
400
|
-
//
|
|
542
|
+
// which is why it sits here and not in the `account` group. `imap`, `smtp` and `oauth2`
|
|
543
|
+
// accept `partial: true`, and Account.persistUpdate() then merges the STORED object over
|
|
544
|
+
// the payload (lib/account.js:858), so `auth.pass` survives a request that only changes
|
|
401
545
|
// `host`. An 'imap' key also arms the reconnect gate, so the worker promptly authenticates
|
|
402
|
-
// to the new host with the old password. The same route retargets
|
|
403
|
-
//
|
|
404
|
-
//
|
|
546
|
+
// to the new host with the old password. The same route retargets the per-account
|
|
547
|
+
// `webhooks` URL, which would stream future message notifications - body text included, up
|
|
548
|
+
// to notifyTextSize - somewhere else entirely. `proxy` is the one field refused outright.
|
|
405
549
|
'PUT /v1/account/{account}',
|
|
406
550
|
|
|
407
551
|
// Adds an account, so it widens what the instance holds. Grouped with the hosted form below
|
|
408
|
-
// for the same reason, and it can set the same webhook
|
|
552
|
+
// for the same reason, and it can set the same webhook target as the edit above.
|
|
409
553
|
'POST /v1/account',
|
|
410
554
|
|
|
411
555
|
// The same shape as the account edit above, and for the same reason. Gateway.update() writes
|
|
@@ -422,6 +566,27 @@ const GROUP_ROUTES = {
|
|
|
422
566
|
// Connects to a supplied host with supplied credentials
|
|
423
567
|
'POST /v1/verifyAccount',
|
|
424
568
|
|
|
569
|
+
// Offers supplied credentials to the autodiscovery host the address domain's own DNS names,
|
|
570
|
+
// which is why it sits here and not with the credential-free `GET /v1/autoconfig` under
|
|
571
|
+
// diagnostics. It stores nothing, so it is still a read.
|
|
572
|
+
'POST /v1/autoconfig'
|
|
573
|
+
],
|
|
574
|
+
|
|
575
|
+
// Everything that hands out a lasting credential or reads one back. This block is the safety
|
|
576
|
+
// property of the whole model: while a narrowed token cannot reach any of it, it cannot mint a
|
|
577
|
+
// token and cannot read a live provider credential, so it cannot widen itself. The settings and
|
|
578
|
+
// provisioning writes above can change a great deal, but nothing they change hands the caller
|
|
579
|
+
// a credential it did not already hold - the keys that would (operator code, proxies, secrets)
|
|
580
|
+
// are refused to a narrowed token per key.
|
|
581
|
+
[GROUP.ADMIN]: [
|
|
582
|
+
'POST /v1/tokens',
|
|
583
|
+
// Deprecated pre-2.79 alias of the mint (see lib/api-routes/token-routes.js)
|
|
584
|
+
'POST /v1/token',
|
|
585
|
+
|
|
586
|
+
// Returns a live OAuth2 access token for the account: a mail credential in its own right,
|
|
587
|
+
// which outlives any narrowing on the token that fetched it
|
|
588
|
+
'GET /v1/account/{account}/oauth-token',
|
|
589
|
+
|
|
425
590
|
// The deprecated Document Store. Disabled by default and leaving the releases on
|
|
426
591
|
// 2026-10-01, so keeping it out of the grantable vocabulary means the removal does not
|
|
427
592
|
// retire a slug a customer had written into a token.
|
|
@@ -482,11 +647,16 @@ module.exports = {
|
|
|
482
647
|
ACTION,
|
|
483
648
|
GROUP,
|
|
484
649
|
SURFACE_GRANTS,
|
|
650
|
+
MCP_SCOPES,
|
|
485
651
|
PER_REQUEST_SURFACES,
|
|
652
|
+
grantKey,
|
|
486
653
|
surfaceAdmits,
|
|
654
|
+
perRequestSurfaceAdmits,
|
|
655
|
+
surfaceBoundAdmits,
|
|
487
656
|
SESSION_TOKEN_GRANTS,
|
|
488
657
|
sessionTokenAdmits,
|
|
489
658
|
GRANTABLE_GROUPS,
|
|
659
|
+
IMPLICIT_GROUPS,
|
|
490
660
|
ACTION_VALUES,
|
|
491
661
|
GROUP_VALUES,
|
|
492
662
|
NEVER_GRANTABLE,
|
|
@@ -5,6 +5,7 @@ const { failAction } = require('../tools');
|
|
|
5
5
|
const { oauth2Apps } = require('../oauth2-apps');
|
|
6
6
|
const { pubSubErrorSchema, apiResponses } = require('../schemas');
|
|
7
7
|
const { handleError, flattenOAuthAppMeta } = require('./route-helpers');
|
|
8
|
+
const { MCP_MAX_PAGE_SIZE } = require('../consts');
|
|
8
9
|
|
|
9
10
|
async function init(args) {
|
|
10
11
|
const { server, CORS_CONFIG } = args;
|
|
@@ -39,6 +40,13 @@ async function init(args) {
|
|
|
39
40
|
tags: ['api', 'OAuth2 Applications'],
|
|
40
41
|
|
|
41
42
|
plugins: {
|
|
43
|
+
mcp: {
|
|
44
|
+
name: 'get_pubsub_status',
|
|
45
|
+
title: 'Get Gmail Pub/Sub status',
|
|
46
|
+
description:
|
|
47
|
+
'List the Gmail Pub/Sub push subscriptions of the OAuth2 applications and their state, paged. A Gmail account falls back to polling while its subscription is missing.',
|
|
48
|
+
bounds: { pageSize: MCP_MAX_PAGE_SIZE }
|
|
49
|
+
},
|
|
42
50
|
openapi: {
|
|
43
51
|
responses: apiResponses('Returns the Pub/Sub subscription state for each configured Gmail application.', 400, 401, 403, 429, 500)
|
|
44
52
|
}
|