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.
Files changed (155) hide show
  1. package/.ncurc.js +23 -13
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +68 -0
  4. package/config/e2e.toml +2 -1
  5. package/config/test.toml +2 -1
  6. package/data/google-crawlers.json +1 -1
  7. package/lib/account.js +112 -36
  8. package/lib/api-reference/format.js +91 -4
  9. package/lib/api-reference/model.js +144 -19
  10. package/lib/api-reference/schema-tree.js +282 -28
  11. package/lib/api-routes/account-routes.js +80 -34
  12. package/lib/api-routes/blocklist-routes.js +21 -47
  13. package/lib/api-routes/chat-routes.js +10 -12
  14. package/lib/api-routes/delivery-test-routes.js +6 -26
  15. package/lib/api-routes/export-routes.js +2 -0
  16. package/lib/api-routes/gateway-routes.js +52 -11
  17. package/lib/api-routes/license-routes.js +2 -0
  18. package/lib/api-routes/mailbox-routes.js +29 -26
  19. package/lib/api-routes/message-routes.js +27 -21
  20. package/lib/api-routes/oauth2-app-routes.js +11 -29
  21. package/lib/api-routes/operation-impact.js +80 -0
  22. package/lib/api-routes/outbox-routes.js +15 -5
  23. package/lib/api-routes/permission-map.js +401 -0
  24. package/lib/api-routes/route-helpers.js +294 -9
  25. package/lib/api-routes/route-metadata.js +28 -0
  26. package/lib/api-routes/settings-routes.js +66 -38
  27. package/lib/api-routes/stats-routes.js +2 -2
  28. package/lib/api-routes/submit-routes.js +53 -31
  29. package/lib/api-routes/template-routes.js +3 -0
  30. package/lib/api-routes/token-routes.js +526 -72
  31. package/lib/api-routes/webhook-route-routes.js +14 -4
  32. package/lib/arf-detect.js +17 -4
  33. package/lib/auth-token.js +80 -8
  34. package/lib/bounce-detect.js +28 -17
  35. package/lib/consts.js +16 -0
  36. package/lib/db.js +26 -2
  37. package/lib/delivery-error.js +30 -1
  38. package/lib/email-client/base-client.js +27 -41
  39. package/lib/email-client/gmail-client.js +23 -17
  40. package/lib/email-client/imap/mailbox.js +58 -59
  41. package/lib/email-client/imap/subconnection.js +10 -7
  42. package/lib/email-client/imap/sync-operations.js +46 -46
  43. package/lib/email-client/imap-client.js +85 -28
  44. package/lib/email-client/message-builder.js +3 -3
  45. package/lib/email-client/notification-handler.js +1 -1
  46. package/lib/email-client/outlook/graph-api.js +10 -4
  47. package/lib/email-client/outlook-client.js +56 -64
  48. package/lib/email-client/smtp-pool-manager.js +1 -1
  49. package/lib/enum-descriptions.js +92 -2
  50. package/lib/export.js +1 -1
  51. package/lib/field-usage.js +133 -0
  52. package/lib/gateway.js +1 -1
  53. package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +3 -3
  54. package/lib/imapproxy/imap-core/lib/commands/id.js +2 -13
  55. package/lib/imapproxy/imap-core/lib/commands/starttls.js +1 -1
  56. package/lib/imapproxy/imap-core/lib/imap-command.js +21 -5
  57. package/lib/imapproxy/imap-core/lib/imap-connection.js +15 -5
  58. package/lib/imapproxy/imap-server.js +27 -7
  59. package/lib/license-beacon.js +4 -9
  60. package/lib/lists.js +49 -1
  61. package/lib/llm-pre-process.js +5 -5
  62. package/lib/logger.js +5 -1
  63. package/lib/lua/h-set-new-mark.lua +36 -0
  64. package/lib/message-port-stream.js +84 -1
  65. package/lib/metrics-collector.js +2 -2
  66. package/lib/oauth/gmail.js +9 -12
  67. package/lib/oauth/mail-ru.js +5 -7
  68. package/lib/oauth/outlook.js +9 -9
  69. package/lib/oauth/pubsub/google.js +25 -10
  70. package/lib/oauth/scope-checker.js +1 -1
  71. package/lib/oauth2-apps.js +290 -292
  72. package/lib/openapi/build-document.js +20 -8
  73. package/lib/openapi/joi-schema.js +20 -0
  74. package/lib/outbox.js +85 -17
  75. package/lib/pre-process.js +8 -8
  76. package/lib/queue-stats.js +49 -0
  77. package/lib/read-env-value.js +1 -1
  78. package/lib/reconnection-manager.js +2 -2
  79. package/lib/rewrite-text-nodes.js +4 -3
  80. package/lib/routes-ui.js +4 -0
  81. package/lib/schemas.js +218 -162
  82. package/lib/settings.js +98 -5
  83. package/lib/sub-script.js +2 -1
  84. package/lib/swagger-options.js +2 -1
  85. package/lib/templates.js +4 -4
  86. package/lib/threads.js +2 -2
  87. package/lib/token-audit-log.js +231 -0
  88. package/lib/token-permission-view.js +219 -0
  89. package/lib/token-permissions.js +172 -0
  90. package/lib/tokens.js +247 -66
  91. package/lib/tools.js +142 -37
  92. package/lib/ui-routes/account-routes.js +42 -15
  93. package/lib/ui-routes/admin-config-routes.js +18 -10
  94. package/lib/ui-routes/admin-entities-routes.js +117 -38
  95. package/lib/ui-routes/auth-routes.js +30 -24
  96. package/lib/ui-routes/export-routes.js +10 -4
  97. package/lib/ui-routes/oauth-config-routes.js +12 -12
  98. package/lib/ui-routes/reference-routes.js +3 -3
  99. package/lib/ui-routes/route-helpers.js +78 -2
  100. package/lib/ui-routes/settings-page.js +1 -1
  101. package/lib/ui-routes/smtp-test-routes.js +1 -1
  102. package/lib/ui-routes/suppression-list-routes.js +299 -0
  103. package/lib/ui-routes/unsubscribe-routes.js +19 -29
  104. package/lib/utils/decode-headers.js +42 -0
  105. package/lib/utils/header-map.js +48 -0
  106. package/lib/utils/network.js +2 -2
  107. package/lib/utils/unsafe-key.js +59 -0
  108. package/lib/web-safe-html.js +1 -1
  109. package/lib/webhook-routing.js +84 -0
  110. package/lib/webhooks.js +48 -14
  111. package/package.json +11 -10
  112. package/sbom.json +1 -1
  113. package/server.js +116 -55
  114. package/static/css/flyonui.css +1 -1
  115. package/static/css/src/app.tailwind.css +136 -9
  116. package/static/js/reference.js +456 -10
  117. package/static/js/ui.js +43 -0
  118. package/static/licenses.html +51 -41
  119. package/translations/messages.pot +59 -59
  120. package/views/accounts/account.hbs +75 -13
  121. package/views/accounts/browse.hbs +19 -36
  122. package/views/accounts/edit.hbs +2 -2
  123. package/views/config/logging.hbs +6 -0
  124. package/views/config/oauth/app.hbs +0 -2
  125. package/views/config/security.hbs +13 -0
  126. package/views/gateways/edit.hbs +1 -1
  127. package/views/gateways/gateway.hbs +2 -2
  128. package/views/gateways/index.hbs +7 -7
  129. package/views/partials/accounts_table.hbs +7 -7
  130. package/views/partials/oauth_form.hbs +0 -15
  131. package/views/partials/reference/disclosure.hbs +8 -2
  132. package/views/partials/reference/operation.hbs +47 -13
  133. package/views/partials/reference/params.hbs +17 -1
  134. package/views/partials/reference/schema-node.hbs +110 -52
  135. package/views/partials/reference/schema-tools.hbs +25 -0
  136. package/views/partials/reference/try-it.hbs +84 -11
  137. package/views/partials/side_menu.hbs +1 -0
  138. package/views/partials/ui/checkbox.hbs +2 -2
  139. package/views/partials/ui/tabs.hbs +7 -1
  140. package/views/reference/token.hbs +4 -0
  141. package/views/suppression-lists/index.hbs +85 -0
  142. package/views/suppression-lists/list.hbs +87 -0
  143. package/views/templates/index.hbs +10 -4
  144. package/views/templates/template.hbs +1 -1
  145. package/views/tokens/index.hbs +53 -6
  146. package/views/tokens/new.hbs +334 -5
  147. package/workers/api.js +185 -102
  148. package/workers/documents.js +46 -26
  149. package/workers/export.js +20 -8
  150. package/workers/imap-proxy.js +2 -2
  151. package/workers/imap.js +77 -78
  152. package/workers/smtp.js +13 -7
  153. package/workers/submit.js +40 -30
  154. package/workers/webhooks.js +80 -26
  155. package/lib/feature-flags.js +0 -48
@@ -0,0 +1,401 @@
1
+ 'use strict';
2
+
3
+ // The vocabulary a narrowed access token is written in, and the mapping from every registered /v1
4
+ // route onto it. Published per operation into /swagger.json as `x-ee-action` and `x-ee-group`, and
5
+ // read at request time by the api-token strategy, so a customer can see what each endpoint requires
6
+ // and the enforcement cannot disagree with the documentation.
7
+ //
8
+ // Two axes, both subtractive. `actions` says what a token may do, `groups` says what it may touch.
9
+ // Verbs are deliberately absent from the groups: `actions` already separates them, and a
10
+ // `message-delete` group would make two axes say the same thing.
11
+
12
+ const { resolveImpact, IMPACT } = require('./operation-impact');
13
+ const { pluginOptions } = require('./route-metadata');
14
+
15
+ // What a token may be allowed to do. Named apart from the impacts on purpose: `readonly` and
16
+ // `sends` describe a route, while `read` and `send` describe a grant on a credential, and the
17
+ // grant is written by whoever issues the token.
18
+ const ACTION = {
19
+ READ: 'read',
20
+ WRITE: 'write',
21
+ SEND: 'send',
22
+ DESTRUCTIVE: 'destructive'
23
+ };
24
+
25
+ // Splitting DESTRUCTIVE out from WRITE is the point of the axis rather than a detail of it: "an
26
+ // agent that can file and reply but not delete" is one bit, and it is the shape most often asked
27
+ // for.
28
+ //
29
+ // It separates the endpoints, not every route to the outcome, and the difference matters for
30
+ // messages specifically. EmailEngine deletes a message by moving it to Trash, so `write` on
31
+ // `message` - which has to allow filing mail into a folder the caller names - reaches the same end
32
+ // state as the DELETE the same token is refused, and `\Deleted` can be set through the flag update
33
+ // for the same reason. Withholding DESTRUCTIVE from a message grant is therefore a statement of
34
+ // intent about message content rather than a wall, and it is described that way wherever a token is
35
+ // issued. For everything genuinely irreversible - a folder, an export, a template, a gateway, a
36
+ // blocklist entry, a queued message - there is no write-shaped route to the same result, and the
37
+ // axis is a hard boundary. Closing the message case would mean reading a destination folder and a
38
+ // flag name out of a payload and deciding whether they amount to a deletion - a judgement about
39
+ // intent, unlike the one payload rule this model does make (see the note on GROUP.SUBMIT, which
40
+ // refuses a field outright rather than interpreting its value).
41
+ //
42
+ // Has to stay total over IMPACT - an impact with no action here resolves to undefined, which reads
43
+ // as an unclassifiable route and denies. test/api-routes-table-test.js asserts the totality.
44
+ const IMPACT_ACTIONS = {
45
+ [IMPACT.READONLY]: ACTION.READ,
46
+ [IMPACT.WRITE]: ACTION.WRITE,
47
+ [IMPACT.SENDS]: ACTION.SEND,
48
+ [IMPACT.DESTRUCTIVE]: ACTION.DESTRUCTIVE
49
+ };
50
+
51
+ // What a token may be allowed to touch. Cut by what a grant exposes rather than by the tag the
52
+ // documentation files a route under: the display tags group `GET /v1/pubsub/status` with OAuth2
53
+ // client-secret writes, put the instance-wide `GET /v1/changes` stream under Account, and file the
54
+ // harmless `GET /v1/autoconfig` under Settings. Reusing them would mean a grant whose blast radius
55
+ // depends on a documentation decision.
56
+ const GROUP = {
57
+ // Account lifecycle and connection state. Credential reads are NOT here, see ADMIN.
58
+ ACCOUNT: 'account',
59
+
60
+ // Folder shape: create, rename, delete, list
61
+ MAILBOX: 'mailbox',
62
+
63
+ // Mail content, including the bulk actions. The largest group, and where `actions` does most
64
+ // of the work.
65
+ MESSAGE: 'message',
66
+
67
+ // Anything that hands a message to a mail server, including the delivery test. Note this reaches
68
+ // stored mail as well as sending it: a submit payload may carry `reference: {message, action:
69
+ // 'forward'}`, which reads the named message and delivers it. The check is route-level and does
70
+ // not inspect payloads, so `submit` is not a promise of no read access.
71
+ //
72
+ // One payload field is refused anyway, by assertNoNetworkOverride() in ./route-helpers.js:
73
+ // `proxy` decides where a session carrying the account's SMTP credentials connects, so a grant
74
+ // to send mail would otherwise be a route to reading the credential that sends it. That is a
75
+ // narrow exception rather than the start of a payload model - it is the only field here that
76
+ // DISCLOSES a stored credential. `gateway` selects one to send through, which a send grant
77
+ // reasonably covers and which reveals nothing (the same token cannot read GET /v1/gateways to
78
+ // learn the ids), and `baseUrl` only points tracking links at a host of the caller's choosing.
79
+ SUBMIT: 'submit',
80
+
81
+ // The sending queue: inspect and cancel
82
+ OUTBOX: 'outbox',
83
+
84
+ // Bulk export. Its own group because one call archives the whole account, so a token allowed
85
+ // to read messages should not get that for free.
86
+ EXPORT: 'export',
87
+
88
+ TEMPLATE: 'template',
89
+ BLOCKLIST: 'blocklist',
90
+ WEBHOOK: 'webhook',
91
+
92
+ // SMTP gateways, which hold outbound SMTP credentials
93
+ GATEWAY: 'gateway',
94
+
95
+ // The instance-wide change stream. Its own group because it is a firehose over every account
96
+ // rather than a request about one, so it should not ride along with an account grant.
97
+ EVENTS: 'events',
98
+
99
+ // Reads about the instance and its connections. Nothing here carries a credential or the
100
+ // contents of a message - the account log did, which is why it has its own group.
101
+ DIAGNOSTICS: 'diagnostics',
102
+
103
+ // The per-account log. Its own group because it discloses strictly more than any other read:
104
+ // the entries are the raw ImapFlow trace, so folder names, UIDs and untagged ENVELOPE responses
105
+ // carrying subjects and correspondents all land in it, and with EENGINE_LOG_RAW set the server
106
+ // frames go in whole. Granting it alongside `diagnostics` would have hidden mail content behind
107
+ // a word that promises none, and folding it into `message` would have made every reader of a
108
+ // mailbox a reader of the protocol trace as well.
109
+ LOGS: 'logs',
110
+
111
+ // Never grantable. See NEVER_GRANTABLE below.
112
+ ADMIN: 'admin'
113
+ };
114
+
115
+ // Groups a `permissions` record may never name. The enforcement is in lib/token-permissions.js;
116
+ // what lives here is the policy it reads.
117
+ //
118
+ // A deny set rather than an absence from the grantable list, so widening the grantable list can
119
+ // never quietly reopen these.
120
+ const NEVER_GRANTABLE = new Set([GROUP.ADMIN]);
121
+
122
+ const GRANTABLE_GROUPS = Object.values(GROUP).filter(group => !NEVER_GRANTABLE.has(group));
123
+
124
+ // Every grant a non-HTTP surface can exercise once it has authenticated, rather than the one it
125
+ // nominally performs. These surfaces are checked once at login and never again, so a token is
126
+ // admitted only if it holds ALL of them.
127
+ //
128
+ // SMTP really is one operation: the server accepts a message and queues it. The IMAP proxy is not -
129
+ // after login lib/imapproxy/imap-server.js pipes the two sockets together, so the session can STORE
130
+ // \Deleted, EXPUNGE, APPEND, CREATE, DELETE and RENAME. Checking it as a single read would admit a
131
+ // token narrowed to reading and then hand it a session that can destroy the mailbox, which is a
132
+ // promise the surface cannot keep.
133
+ //
134
+ // Lives here rather than in lib/auth-token.js because it is policy that several places read - the
135
+ // admin form shows it to explain why a scope would be unusable - and auth-token.js reaches Redis,
136
+ // which a presentation module has no business loading.
137
+ const SURFACE_GRANTS = {
138
+ smtp: [{ action: ACTION.SEND, group: GROUP.SUBMIT }],
139
+ 'imap-proxy': [
140
+ { action: ACTION.READ, group: GROUP.MESSAGE },
141
+ { action: ACTION.WRITE, group: GROUP.MESSAGE },
142
+ { action: ACTION.DESTRUCTIVE, group: GROUP.MESSAGE },
143
+ { action: ACTION.WRITE, group: GROUP.MAILBOX },
144
+ { action: ACTION.DESTRUCTIVE, group: GROUP.MAILBOX }
145
+ ],
146
+ // Not a submission surface: /metrics is an ordinary api-token route, so this mirrors its entry in
147
+ // GROUP_ROUTES below. Listed with the others because the admin form shows all three together.
148
+ metrics: [{ action: ACTION.READ, group: GROUP.DIAGNOSTICS }]
149
+ };
150
+
151
+ // Membership sets for the two vocabularies. lib/token-permissions.js rejects a record naming
152
+ // anything outside them, which is what makes an unknown value a denial rather than something a
153
+ // reader silently drops.
154
+ //
155
+ // GROUP_VALUES deliberately includes ADMIN even though no record may name it: a record that does is
156
+ // well-formed but refused, which is a different answer from malformed, and the reason for the
157
+ // refusal should be "you may never have this" rather than "I could not read that".
158
+ const ACTION_VALUES = new Set(Object.values(ACTION));
159
+ const GROUP_VALUES = new Set(Object.values(GROUP));
160
+
161
+ /**
162
+ * Identity of a route, in the `METHOD /path` form the rest of the test and helper code already uses
163
+ * for the same purpose, so the two listings of these 82 routes can be diffed against each other.
164
+ * Hapi reports a lowercase method on both `server.table()` entries and a live `request.route`.
165
+ */
166
+ function routeKey(method, path) {
167
+ return `${String(method).toUpperCase()} ${path}`;
168
+ }
169
+
170
+ // Every registered /v1 operation, by group. One entry per route rather than a rule per tag: a rule
171
+ // would give a newly added route the group of whatever tag it happened to carry, where an explicit
172
+ // entry means a new route has no group until someone chooses one, and no group is a denial.
173
+ //
174
+ // Grouped this way round because the access-control surface is then readable in one pass - the ADMIN
175
+ // block below IS the list of everything a narrowed token can never reach, rather than something a
176
+ // reviewer has to assemble by grepping. test/api-routes-table-test.js asserts this and the real
177
+ // route table agree exactly in both directions, so an added, removed or renamed route fails the
178
+ // build rather than drifting.
179
+ const GROUP_ROUTES = {
180
+ // Reading an account and operating on its connection. Creating one and editing its
181
+ // configuration are NOT here - see the note on those two entries under ADMIN.
182
+ [GROUP.ACCOUNT]: [
183
+ 'GET /v1/accounts',
184
+ 'GET /v1/account/{account}',
185
+ 'DELETE /v1/account/{account}',
186
+ 'PUT /v1/account/{account}/flush',
187
+ 'PUT /v1/account/{account}/reconnect',
188
+ 'PUT /v1/account/{account}/sync',
189
+ 'GET /v1/account/{account}/server-signatures'
190
+ ],
191
+
192
+ [GROUP.MAILBOX]: [
193
+ 'GET /v1/account/{account}/mailboxes',
194
+ 'POST /v1/account/{account}/mailbox',
195
+ 'PUT /v1/account/{account}/mailbox',
196
+ 'DELETE /v1/account/{account}/mailbox'
197
+ ],
198
+
199
+ [GROUP.MESSAGE]: [
200
+ 'GET /v1/account/{account}/messages',
201
+ 'POST /v1/account/{account}/search',
202
+ 'GET /v1/account/{account}/message/{message}',
203
+ 'PUT /v1/account/{account}/message/{message}',
204
+ 'DELETE /v1/account/{account}/message/{message}',
205
+ 'PUT /v1/account/{account}/message/{message}/move',
206
+ 'GET /v1/account/{account}/message/{message}/source',
207
+ 'POST /v1/account/{account}/message',
208
+ 'GET /v1/account/{account}/text/{text}',
209
+ 'GET /v1/account/{account}/attachment/{attachment}',
210
+ 'PUT /v1/account/{account}/messages',
211
+ 'PUT /v1/account/{account}/messages/move',
212
+ 'PUT /v1/account/{account}/messages/delete'
213
+ ],
214
+
215
+ [GROUP.SUBMIT]: [
216
+ 'POST /v1/account/{account}/submit',
217
+ 'POST /v1/account/{account}/message/{message}/submit',
218
+ // Sends a real message to a probe address, so it belongs with sending rather than with the
219
+ // diagnostics read that later collects the result
220
+ 'POST /v1/delivery-test/account/{account}'
221
+ ],
222
+
223
+ [GROUP.OUTBOX]: ['GET /v1/outbox', 'GET /v1/outbox/{queueId}', 'DELETE /v1/outbox/{queueId}'],
224
+
225
+ [GROUP.EXPORT]: [
226
+ 'POST /v1/account/{account}/export',
227
+ 'GET /v1/account/{account}/exports',
228
+ 'GET /v1/account/{account}/export/{exportId}',
229
+ 'GET /v1/account/{account}/export/{exportId}/download',
230
+ 'DELETE /v1/account/{account}/export/{exportId}'
231
+ ],
232
+
233
+ [GROUP.TEMPLATE]: [
234
+ 'GET /v1/templates',
235
+ 'POST /v1/templates/template',
236
+ 'GET /v1/templates/template/{template}',
237
+ 'PUT /v1/templates/template/{template}',
238
+ 'DELETE /v1/templates/template/{template}',
239
+ 'DELETE /v1/templates/account/{account}'
240
+ ],
241
+
242
+ [GROUP.BLOCKLIST]: ['GET /v1/blocklists', 'GET /v1/blocklist/{listId}', 'POST /v1/blocklist/{listId}', 'DELETE /v1/blocklist/{listId}'],
243
+
244
+ [GROUP.WEBHOOK]: ['GET /v1/webhookRoutes', 'GET /v1/webhookRoutes/webhookRoute/{webhookRoute}'],
245
+
246
+ // Reading a gateway and removing one. The two WRITES are in ADMIN below, because they can
247
+ // redirect where the stored relay credentials are sent - so they are deliberately absent here
248
+ // rather than listed in both places.
249
+ [GROUP.GATEWAY]: ['GET /v1/gateways', 'GET /v1/gateway/{gateway}', 'DELETE /v1/gateway/{gateway}'],
250
+
251
+ [GROUP.EVENTS]: ['GET /v1/changes'],
252
+
253
+ [GROUP.DIAGNOSTICS]: [
254
+ 'GET /v1/stats',
255
+ 'GET /v1/delivery-test/check/{deliveryTest}',
256
+ 'GET /v1/pubsub/status',
257
+ 'GET /v1/autoconfig',
258
+ // The Prometheus endpoint. Not a /v1 route and registered in workers/api.js rather than
259
+ // lib/api-routes/index.js, so the route table test cannot see it - listed here anyway
260
+ // because it authenticates with the same tokens. Without an entry it resolves to no group,
261
+ // and a narrowed token is refused on it: a `metrics`-scoped token that set any permissions
262
+ // at all became unusable, including one asking for exactly this.
263
+ 'GET /metrics'
264
+ ],
265
+
266
+ [GROUP.LOGS]: ['GET /v1/logs/{account}'],
267
+
268
+ // Everything that hands out a lasting credential or widens what the instance can do. This block
269
+ // is the safety property of the whole model: while a narrowed token cannot reach any of it, it
270
+ // cannot read the settings blob, cannot read a stored OAuth2 credential, and cannot mint or
271
+ // revoke a token, so it cannot widen itself.
272
+ [GROUP.ADMIN]: [
273
+ 'GET /v1/settings',
274
+ 'POST /v1/settings',
275
+ 'GET /v1/settings/queue/{queue}',
276
+ 'PUT /v1/settings/queue/{queue}',
277
+
278
+ 'GET /v1/oauth2',
279
+ 'POST /v1/oauth2',
280
+ 'GET /v1/oauth2/{app}',
281
+ 'PUT /v1/oauth2/{app}',
282
+ 'DELETE /v1/oauth2/{app}',
283
+ 'POST /v1/oauth2/{app}/verify',
284
+
285
+ 'GET /v1/license',
286
+ 'POST /v1/license',
287
+ 'DELETE /v1/license',
288
+
289
+ 'POST /v1/tokens',
290
+ 'DELETE /v1/tokens/{token}',
291
+ 'GET /v1/tokens',
292
+ // Who read whose mail with this credential. Admin because the trail is at least as sensitive
293
+ // as the requests in it, and a narrowed token has no business reading its own audit record.
294
+ 'GET /v1/tokens/{token}',
295
+ 'GET /v1/tokens/{token}/log',
296
+ // Deprecated pre-2.79 aliases of the three above (see lib/api-routes/token-routes.js)
297
+ 'POST /v1/token',
298
+ 'DELETE /v1/token/{token}',
299
+ 'GET /v1/tokens/account/{account}',
300
+
301
+ // Returns a live OAuth2 access token for the account: a mail credential in its own right,
302
+ // which outlives any narrowing on the token that fetched it
303
+ 'GET /v1/account/{account}/oauth-token',
304
+
305
+ // Editing an account is a credential operation even when the payload carries no credential,
306
+ // which is why it sits here and not in the grantable `account` group. `imap`, `smtp` and
307
+ // `oauth2` accept `partial: true`, and Account.persistUpdate() then merges the STORED object
308
+ // over the payload (lib/account.js:858), so `auth.pass` survives a request that only changes
309
+ // `host`. An 'imap' key also arms the reconnect gate, so the worker promptly authenticates
310
+ // to the new host with the old password. The same route retargets `proxy` and the
311
+ // per-account `webhooks` URL, which would stream future message notifications - body text
312
+ // included, up to notifyTextSize - somewhere else entirely.
313
+ 'PUT /v1/account/{account}',
314
+
315
+ // Adds an account, so it widens what the instance holds. Grouped with the hosted form below
316
+ // for the same reason, and it can set the same webhook and proxy targets as the edit above.
317
+ 'POST /v1/account',
318
+
319
+ // The same shape as the account edit above, and for the same reason. Gateway.update() writes
320
+ // only the keys the payload carries (lib/gateway.js:233), so a request setting just `host`
321
+ // leaves the encrypted `user` and `pass` in place - and the next message routed through that
322
+ // gateway performs SMTP AUTH against the new host with the customer's relay credentials.
323
+ // Reading them back is masked; sending them somewhere is not.
324
+ 'POST /v1/gateway',
325
+ 'PUT /v1/gateway/edit/{gateway}',
326
+
327
+ // Mints a hosted account-add URL, so it grows the set of accounts the instance holds
328
+ 'POST /v1/authentication/form',
329
+
330
+ // Connects to a supplied host with supplied credentials
331
+ 'POST /v1/verifyAccount',
332
+
333
+ // The deprecated Document Store. Disabled by default and leaving the releases on
334
+ // 2026-10-01, so keeping it out of the grantable vocabulary means the removal does not
335
+ // retire a slug a customer had written into a token.
336
+ 'POST /v1/chat/{account}',
337
+ 'POST /v1/unified/search'
338
+ ]
339
+ };
340
+
341
+ // Inverted once at load, refusing a route that appears under two groups.
342
+ //
343
+ // The refusal is the point. Building this with `new Map(...)` let the later entry win silently, and
344
+ // it had already happened: the two gateway writes were listed under both `gateway` and `admin`, and
345
+ // only the order of the literal decided that the never-grantable one took effect. The route-table
346
+ // test cannot see it either - it compares this map's size against the route table, and a duplicate
347
+ // leaves the size unchanged. Throwing at load turns "whichever is written last" into a build
348
+ // failure, in a table where one of the two answers is a grant a customer must never be able to hold.
349
+ const ROUTE_GROUPS = new Map();
350
+ for (const [group, routes] of Object.entries(GROUP_ROUTES)) {
351
+ for (const route of routes) {
352
+ if (ROUTE_GROUPS.has(route)) {
353
+ throw new Error(`${route} is listed under two permission groups, ${ROUTE_GROUPS.get(route)} and ${group}`);
354
+ }
355
+ ROUTE_GROUPS.set(route, group);
356
+ }
357
+ }
358
+
359
+ /**
360
+ * Resolves the action an operation requires.
361
+ *
362
+ * @param {String} [declared] - the route's `x-ee-impact`, if it sets one
363
+ * @param {String} method - HTTP method
364
+ * @returns {String|null} one of ACTION, or null when the impact does not resolve
365
+ */
366
+ function resolveAction(declared, method) {
367
+ const impact = resolveImpact(declared, method);
368
+ return impact ? IMPACT_ACTIONS[impact] || null : null;
369
+ }
370
+
371
+ /**
372
+ * The grant a route requires, for a Hapi route from `server.table()` or a live `request.route`.
373
+ *
374
+ * Either half can be null, and null always means deny: an operation whose action or group does not
375
+ * resolve is one this vocabulary does not describe, and guessing is how a route ends up ungoverned.
376
+ * The route table test asserts neither half is ever null for a registered /v1 route, so a null here
377
+ * means the table and the routes have diverged.
378
+ *
379
+ * @param {Object} route - `server.table()` entry or `request.route`
380
+ * @returns {{action: (String|null), group: (String|null)}}
381
+ */
382
+ function routeGrant(route) {
383
+ return {
384
+ action: resolveAction(pluginOptions(route)['x-ee-impact'], route && route.method),
385
+ group: ROUTE_GROUPS.get(routeKey(route && route.method, route && route.path)) || null
386
+ };
387
+ }
388
+
389
+ module.exports = {
390
+ ACTION,
391
+ GROUP,
392
+ SURFACE_GRANTS,
393
+ GRANTABLE_GROUPS,
394
+ ACTION_VALUES,
395
+ GROUP_VALUES,
396
+ NEVER_GRANTABLE,
397
+ IMPACT_ACTIONS,
398
+ ROUTE_GROUPS,
399
+ routeKey,
400
+ routeGrant
401
+ };