emailengine-app 2.79.0 → 2.79.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +79 -0
- package/bin/emailengine.js +8 -1
- package/config/default.toml +6 -0
- package/data/google-crawlers.json +1 -1
- package/lib/account.js +137 -19
- package/lib/api-routes/account-routes.js +13 -1
- package/lib/api-routes/index.js +12 -0
- package/lib/api-routes/mailbox-routes.js +6 -0
- package/lib/api-routes/mcp-oauth-routes.js +259 -0
- package/lib/api-routes/mcp-routes.js +172 -0
- package/lib/api-routes/message-routes.js +125 -4
- package/lib/api-routes/outbox-routes.js +7 -0
- package/lib/api-routes/permission-map.js +101 -1
- package/lib/api-routes/route-helpers.js +87 -4
- package/lib/api-routes/route-metadata.js +24 -4
- package/lib/api-routes/settings-routes.js +37 -14
- package/lib/api-routes/submit-routes.js +41 -0
- package/lib/api-routes/template-routes.js +7 -0
- package/lib/api-routes/token-routes.js +292 -122
- package/lib/arf-detect.js +17 -4
- package/lib/bounce-detect.js +28 -17
- package/lib/consts.js +36 -1
- package/lib/db.js +6 -0
- package/lib/email-client/base-client.js +102 -117
- package/lib/email-client/gmail-client.js +91 -29
- package/lib/email-client/imap/mailbox.js +175 -101
- package/lib/email-client/imap-client.js +49 -2
- package/lib/email-client/outlook-client.js +20 -24
- package/lib/enum-descriptions.js +2 -1
- package/lib/field-usage.js +17 -1
- package/lib/lua/h-set-new-mark.lua +36 -0
- package/lib/lua/s-list-accounts.lua +5 -2
- package/lib/mcp/index.js +29 -0
- package/lib/mcp/inject.js +70 -0
- package/lib/mcp/json-schema.js +120 -0
- package/lib/mcp/listen.js +171 -0
- package/lib/mcp/oauth.js +324 -0
- package/lib/mcp/protocol.js +489 -0
- package/lib/mcp/resources.js +139 -0
- package/lib/mcp/tools.js +655 -0
- package/lib/message-port-stream.js +84 -1
- package/lib/oauth2-apps.js +84 -15
- package/lib/openapi/build-document.js +5 -1
- package/lib/openapi/index.js +3 -1
- package/lib/response-stream.js +52 -21
- package/lib/routes-ui.js +4 -0
- package/lib/schemas.js +26 -5
- package/lib/settings.js +23 -9
- package/lib/token-audit-log.js +32 -9
- package/lib/token-permission-view.js +104 -8
- package/lib/tokens.js +194 -68
- package/lib/tools.js +96 -0
- package/lib/ui-routes/account-routes.js +55 -6
- package/lib/ui-routes/admin-config-routes.js +114 -1
- package/lib/ui-routes/admin-entities-routes.js +103 -19
- package/lib/ui-routes/auth-routes.js +13 -0
- package/lib/ui-routes/mcp-consent-routes.js +330 -0
- package/lib/ui-routes/oauth-config-routes.js +7 -7
- package/lib/ui-routes/route-helpers.js +143 -1
- package/lib/ui-routes/suppression-list-routes.js +14 -9
- package/lib/utils/decode-headers.js +42 -0
- package/lib/utils/header-map.js +48 -0
- package/lib/utils/network.js +9 -1
- package/lib/utils/unsafe-key.js +59 -0
- package/lib/web-safe-html.js +61 -0
- package/lib/webhook-routing.js +6 -2
- package/lib/webhooks.js +31 -8
- package/package.json +9 -8
- package/sbom.json +1 -1
- package/scripts/README.md +25 -0
- package/scripts/build-icon.js +77 -0
- package/server.js +39 -17
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +98 -0
- package/static/emailengine.ico +0 -0
- package/static/js/ui.js +465 -1
- package/static/licenses.html +42 -22
- package/translations/messages.pot +57 -57
- package/views/accounts/account.hbs +8 -8
- package/views/accounts/browse.hbs +1 -1
- package/views/accounts/edit.hbs +2 -2
- package/views/config/mcp.hbs +361 -0
- package/views/config/oauth/index.hbs +7 -0
- package/views/gateways/edit.hbs +1 -1
- package/views/gateways/gateway.hbs +2 -2
- package/views/gateways/index.hbs +7 -7
- package/views/layout/prompt.hbs +62 -0
- package/views/mcp/authorize.hbs +136 -0
- package/views/partials/accounts_table.hbs +7 -7
- package/views/partials/head_assets.hbs +3 -3
- package/views/partials/mcp_access_levels.hbs +13 -0
- package/views/partials/mcp_account_limit.hbs +14 -0
- package/views/partials/mcp_tool_count.hbs +19 -0
- package/views/partials/side_menu.hbs +1 -0
- package/views/partials/ui/account-picker.hbs +59 -0
- package/views/partials/ui/code-block.hbs +26 -0
- package/views/partials/ui/menu-item.hbs +5 -0
- package/views/partials/ui/radio.hbs +41 -0
- package/views/partials/ui/tab.hbs +15 -10
- package/views/partials/ui/tabs.hbs +8 -5
- package/views/suppression-lists/list.hbs +1 -1
- package/views/templates/index.hbs +2 -2
- package/views/templates/template.hbs +5 -4
- package/views/tokens/index.hbs +30 -4
- package/views/tokens/new.hbs +517 -239
- package/winconf.js +148 -48
- package/workers/api.js +239 -95
- package/workers/imap.js +65 -72
- package/workers/webhooks.js +21 -1
|
@@ -54,7 +54,7 @@ const tokenReferenceSchema = Joi.string()
|
|
|
54
54
|
.length(64)
|
|
55
55
|
.hex()
|
|
56
56
|
.required()
|
|
57
|
-
.example('
|
|
57
|
+
.example('1bc12baf7f0d5e51fe0a4e0eda06e1be5b8d6cc2c66b95dc0fbe4d2e9f5d5e1a')
|
|
58
58
|
.description('The access token value, or the token id from a listing')
|
|
59
59
|
.label('TokenReference');
|
|
60
60
|
|
|
@@ -62,7 +62,7 @@ const tokenIdParamSchema = Joi.string()
|
|
|
62
62
|
.length(64)
|
|
63
63
|
.hex()
|
|
64
64
|
.required()
|
|
65
|
-
.example('
|
|
65
|
+
.example('1bc12baf7f0d5e51fe0a4e0eda06e1be5b8d6cc2c66b95dc0fbe4d2e9f5d5e1a')
|
|
66
66
|
.description('The token id, as reported by POST /v1/tokens and the token listing')
|
|
67
67
|
.label('TokenIdParam');
|
|
68
68
|
|
|
@@ -112,56 +112,140 @@ const tokenListItemFields = {
|
|
|
112
112
|
async function init(args) {
|
|
113
113
|
const { server, call, CORS_CONFIG } = args;
|
|
114
114
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
// The provision and delete routes are registered twice - the current path and the
|
|
116
|
+
// deprecated pre-2.79 alias at the bottom of this file - so the handlers and the request/
|
|
117
|
+
// response schemas are shared. Sharing the schema INSTANCES matters beyond reuse: the
|
|
118
|
+
// OpenAPI generator names components after joi labels, and two different schema objects
|
|
119
|
+
// carrying the same label would come out numbered (CreateToken1).
|
|
120
|
+
const createTokenPayloadSchema = Joi.object({
|
|
121
|
+
account: accountIdSchema.description('Bind the token to one account. Omit for an instance-wide token, which then has to set `permissions`'),
|
|
122
|
+
|
|
123
|
+
description: Joi.string().empty('').trim().max(1024).required().example('Token description').description('Token description'),
|
|
124
|
+
|
|
125
|
+
scopes: Joi.array()
|
|
126
|
+
.items(Joi.string().valid('api', 'smtp', 'imap-proxy', 'mcp').meta({ enumDescriptions: ENUM_DESCRIPTIONS.tokenScope }).label('TokenScope'))
|
|
127
|
+
.single()
|
|
128
|
+
.default(['api'])
|
|
129
|
+
.required()
|
|
130
|
+
.description(
|
|
131
|
+
'Token permission scopes: "api" for REST API access, "smtp" for SMTP submission, "imap-proxy" for IMAP proxy authentication, "mcp" for the MCP endpoint only'
|
|
132
|
+
)
|
|
133
|
+
.label('Scopes'),
|
|
134
|
+
|
|
135
|
+
metadata: tokenMetadataSchema,
|
|
136
|
+
|
|
137
|
+
restrictions: tokenRestrictionsSchema,
|
|
138
|
+
|
|
139
|
+
// An unbound token reaches instance-wide endpoints and every account, so it may
|
|
140
|
+
// only be issued narrowed. A bound one is already limited to its account, so the
|
|
141
|
+
// narrowing stays optional there.
|
|
142
|
+
// `.invalid(null)` matters as much as `.required()`: tokenPermissionsSchema allows
|
|
143
|
+
// null so the admin form can post "not narrowed", and joi's required() is a
|
|
144
|
+
// presence check that an explicit null satisfies. Without this, sending
|
|
145
|
+
// `permissions: null` with no account - which any template rendering an unset
|
|
146
|
+
// variable produces - passed the rule and minted a full instance-wide token.
|
|
147
|
+
permissions: tokenPermissionsSchema.when('account', {
|
|
148
|
+
is: Joi.exist(),
|
|
149
|
+
otherwise: tokenPermissionsSchema.required().invalid(null).messages({
|
|
150
|
+
'any.required': 'A token with no account must set permissions, so that an instance-wide credential is always a narrowed one',
|
|
151
|
+
'any.invalid': 'A token with no account must set permissions, so that an instance-wide credential is always a narrowed one'
|
|
152
|
+
})
|
|
153
|
+
}),
|
|
154
|
+
|
|
155
|
+
// provision() has always accepted an expiry; the route did not, so until now the
|
|
156
|
+
// API could not mint a short-lived token at all. A narrow token that never
|
|
157
|
+
// expires is only half of what a per-task credential is for.
|
|
158
|
+
expires: Joi.date()
|
|
159
|
+
.iso()
|
|
160
|
+
.greater('now')
|
|
161
|
+
.example('2021-02-17T14:43:18.860Z')
|
|
162
|
+
.description('Optional time when this token stops working. Omit for a token that never expires')
|
|
163
|
+
// Distinct from the TokenExpires the listing uses: a joi label is a public
|
|
164
|
+
// type name in the generated document, so reusing it would collide and the
|
|
165
|
+
// generator would number one of them
|
|
166
|
+
.label('CreateTokenExpires'),
|
|
167
|
+
|
|
168
|
+
ip: ipSchema.description('IP address of the requester').label('TokenIP')
|
|
169
|
+
}).label('CreateToken');
|
|
170
|
+
|
|
171
|
+
const createTokenResponseSchema = Joi.object({
|
|
172
|
+
token: Joi.string()
|
|
173
|
+
.length(64)
|
|
174
|
+
.hex()
|
|
175
|
+
.required()
|
|
176
|
+
.example('9a6d24f8f43e01b1f2c4f11a5c5b8e51fe0a4e0eda06e1be5b8d6cc2c66b95dc')
|
|
177
|
+
.description('The access token. This is the only time it is returned - store it now'),
|
|
178
|
+
id: tokenIdSchema.required().description('Identifier for this token, as reported by the token listings')
|
|
179
|
+
}).label('CreateTokenResponse');
|
|
180
|
+
|
|
181
|
+
const deleteTokenParamsSchema = Joi.object({
|
|
182
|
+
token: tokenReferenceSchema
|
|
183
|
+
}).label('DeleteTokenRequest');
|
|
184
|
+
|
|
185
|
+
const deleteTokenResponseSchema = Joi.object({
|
|
186
|
+
deleted: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(true).description('Was the token deleted')
|
|
187
|
+
}).label('DeleteTokenRequestResponse');
|
|
188
|
+
|
|
189
|
+
const provisionTokenHandler = async request => {
|
|
190
|
+
let accountObject = new Account({
|
|
191
|
+
redis,
|
|
192
|
+
account: request.payload.account,
|
|
193
|
+
call,
|
|
194
|
+
secret: await getSecret(),
|
|
195
|
+
timeout: request.headers['x-ee-timeout']
|
|
196
|
+
});
|
|
118
197
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
198
|
+
try {
|
|
199
|
+
// Nothing invalidates an access token once it is minted, so a token handed to an
|
|
200
|
+
// anonymous caller keeps working indefinitely. This route normally requires a real
|
|
201
|
+
// credential (`auth: {strategy: 'api-token', mode: 'required'}`) and a caller
|
|
202
|
+
// presenting one is trusted, but the `disableTokens` setting rewrites a
|
|
203
|
+
// credential-less request to `access_token=preauth` and the strategy accepts it,
|
|
204
|
+
// marking the credentials `{preauth: true}`. That anonymous caller must never mint a
|
|
205
|
+
// lasting token - whether or not an admin password happens to be set - so refuse it
|
|
206
|
+
// here (headless provisioning uses the CLI or EENGINE_PREPARED_TOKEN, not this route).
|
|
207
|
+
if (request.auth.credentials?.preauth) {
|
|
208
|
+
throw Boom.forbidden('Can not provision an access token for an unauthenticated request');
|
|
209
|
+
}
|
|
127
210
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
211
|
+
// An account-bound token is validated against a real account; an instance-wide one has
|
|
212
|
+
// nothing to validate. The schema already refuses an unbound token that is not
|
|
213
|
+
// narrowed, so reaching here without an account means `permissions` is set.
|
|
214
|
+
//
|
|
215
|
+
// Safe because this route sits in the never-grantable `admin` group and has no
|
|
216
|
+
// `{account}` parameter, so an account-bound token is refused by the binding check and
|
|
217
|
+
// a narrowed one by the group check. The caller is therefore always a full-privilege
|
|
218
|
+
// root token, and every token it can mint here is strictly narrower than what it
|
|
219
|
+
// already holds.
|
|
220
|
+
if (request.payload.account) {
|
|
221
|
+
// throws if account does not exist
|
|
222
|
+
await accountObject.loadAccountData();
|
|
223
|
+
}
|
|
140
224
|
|
|
141
|
-
|
|
142
|
-
// nothing to validate. The schema already refuses an unbound token that is not
|
|
143
|
-
// narrowed, so reaching here without an account means `permissions` is set.
|
|
144
|
-
//
|
|
145
|
-
// Safe because this route sits in the never-grantable `admin` group and has no
|
|
146
|
-
// `{account}` parameter, so an account-bound token is refused by the binding check and
|
|
147
|
-
// a narrowed one by the group check. The caller is therefore always a full-privilege
|
|
148
|
-
// root token, and every token it can mint here is strictly narrower than what it
|
|
149
|
-
// already holds.
|
|
150
|
-
if (request.payload.account) {
|
|
151
|
-
// throws if account does not exist
|
|
152
|
-
await accountObject.loadAccountData();
|
|
153
|
-
}
|
|
225
|
+
let token = await tokens.provision(Object.assign({}, request.payload, { remoteAddress: request.app.ip }));
|
|
154
226
|
|
|
155
|
-
|
|
227
|
+
// The id as well as the value: the value is never shown again and the listings report
|
|
228
|
+
// only the id, so returning the value alone left a caller unable to say which of its
|
|
229
|
+
// own tokens it had just created without hashing it themselves.
|
|
230
|
+
return { token, id: tokens.tokenId(token) };
|
|
231
|
+
} catch (err) {
|
|
232
|
+
handleError(request, err);
|
|
233
|
+
}
|
|
234
|
+
};
|
|
156
235
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
236
|
+
const deleteTokenHandler = async request => {
|
|
237
|
+
try {
|
|
238
|
+
return { deleted: await tokens.delete(request.params.token, { remoteAddress: request.app.ip }) };
|
|
239
|
+
} catch (err) {
|
|
240
|
+
handleError(request, err);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
server.route({
|
|
245
|
+
method: 'POST',
|
|
246
|
+
path: '/v1/tokens',
|
|
247
|
+
|
|
248
|
+
handler: provisionTokenHandler,
|
|
165
249
|
|
|
166
250
|
options: {
|
|
167
251
|
description: 'Provision an access token',
|
|
@@ -191,68 +275,11 @@ async function init(args) {
|
|
|
191
275
|
},
|
|
192
276
|
failAction,
|
|
193
277
|
|
|
194
|
-
payload:
|
|
195
|
-
account: accountIdSchema.description('Bind the token to one account. Omit for an instance-wide token, which then has to set `permissions`'),
|
|
196
|
-
|
|
197
|
-
description: Joi.string().empty('').trim().max(1024).required().example('Token description').description('Token description'),
|
|
198
|
-
|
|
199
|
-
scopes: Joi.array()
|
|
200
|
-
.items(Joi.string().valid('api', 'smtp', 'imap-proxy').meta({ enumDescriptions: ENUM_DESCRIPTIONS.tokenScope }).label('TokenScope'))
|
|
201
|
-
.single()
|
|
202
|
-
.default(['api'])
|
|
203
|
-
.required()
|
|
204
|
-
.description(
|
|
205
|
-
'Token permission scopes: "api" for REST API access, "smtp" for SMTP submission, "imap-proxy" for IMAP proxy authentication'
|
|
206
|
-
)
|
|
207
|
-
.label('Scopes'),
|
|
208
|
-
|
|
209
|
-
metadata: tokenMetadataSchema,
|
|
210
|
-
|
|
211
|
-
restrictions: tokenRestrictionsSchema,
|
|
212
|
-
|
|
213
|
-
// An unbound token reaches instance-wide endpoints and every account, so it may
|
|
214
|
-
// only be issued narrowed. A bound one is already limited to its account, so the
|
|
215
|
-
// narrowing stays optional there.
|
|
216
|
-
// `.invalid(null)` matters as much as `.required()`: tokenPermissionsSchema allows
|
|
217
|
-
// null so the admin form can post "not narrowed", and joi's required() is a
|
|
218
|
-
// presence check that an explicit null satisfies. Without this, sending
|
|
219
|
-
// `permissions: null` with no account - which any template rendering an unset
|
|
220
|
-
// variable produces - passed the rule and minted a full instance-wide token.
|
|
221
|
-
permissions: tokenPermissionsSchema.when('account', {
|
|
222
|
-
is: Joi.exist(),
|
|
223
|
-
otherwise: tokenPermissionsSchema.required().invalid(null).messages({
|
|
224
|
-
'any.required': 'A token with no account must set permissions, so that an instance-wide credential is always a narrowed one',
|
|
225
|
-
'any.invalid': 'A token with no account must set permissions, so that an instance-wide credential is always a narrowed one'
|
|
226
|
-
})
|
|
227
|
-
}),
|
|
228
|
-
|
|
229
|
-
// provision() has always accepted an expiry; the route did not, so until now the
|
|
230
|
-
// API could not mint a short-lived token at all. A narrow token that never
|
|
231
|
-
// expires is only half of what a per-task credential is for.
|
|
232
|
-
expires: Joi.date()
|
|
233
|
-
.iso()
|
|
234
|
-
.greater('now')
|
|
235
|
-
.example('2021-02-17T14:43:18.860Z')
|
|
236
|
-
.description('Optional time when this token stops working. Omit for a token that never expires')
|
|
237
|
-
// Distinct from the TokenExpires the listing uses: a joi label is a public
|
|
238
|
-
// type name in the generated document, so reusing it would collide and the
|
|
239
|
-
// generator would number one of them
|
|
240
|
-
.label('CreateTokenExpires'),
|
|
241
|
-
|
|
242
|
-
ip: ipSchema.description('IP address of the requester').label('TokenIP')
|
|
243
|
-
}).label('CreateToken')
|
|
278
|
+
payload: createTokenPayloadSchema
|
|
244
279
|
},
|
|
245
280
|
|
|
246
281
|
response: {
|
|
247
|
-
schema:
|
|
248
|
-
token: Joi.string()
|
|
249
|
-
.length(64)
|
|
250
|
-
.hex()
|
|
251
|
-
.required()
|
|
252
|
-
.example('123456')
|
|
253
|
-
.description('The access token. This is the only time it is returned - store it now'),
|
|
254
|
-
id: tokenIdSchema.required().description('Identifier for this token, as reported by the token listings')
|
|
255
|
-
}).label('CreateTokenResponse'),
|
|
282
|
+
schema: createTokenResponseSchema,
|
|
256
283
|
failAction: 'log'
|
|
257
284
|
}
|
|
258
285
|
}
|
|
@@ -262,13 +289,7 @@ async function init(args) {
|
|
|
262
289
|
method: 'DELETE',
|
|
263
290
|
path: '/v1/tokens/{token}',
|
|
264
291
|
|
|
265
|
-
|
|
266
|
-
try {
|
|
267
|
-
return { deleted: await tokens.delete(request.params.token, { remoteAddress: request.app.ip }) };
|
|
268
|
-
} catch (err) {
|
|
269
|
-
handleError(request, err);
|
|
270
|
-
}
|
|
271
|
-
},
|
|
292
|
+
handler: deleteTokenHandler,
|
|
272
293
|
options: {
|
|
273
294
|
description: 'Remove a token',
|
|
274
295
|
notes: 'Delete an access token',
|
|
@@ -295,15 +316,11 @@ async function init(args) {
|
|
|
295
316
|
},
|
|
296
317
|
failAction,
|
|
297
318
|
|
|
298
|
-
params:
|
|
299
|
-
token: tokenReferenceSchema
|
|
300
|
-
}).label('DeleteTokenRequest')
|
|
319
|
+
params: deleteTokenParamsSchema
|
|
301
320
|
},
|
|
302
321
|
|
|
303
322
|
response: {
|
|
304
|
-
schema:
|
|
305
|
-
deleted: Joi.boolean().truthy('Y', 'true', '1').falsy('N', 'false', 0).default(true).description('Was the token deleted')
|
|
306
|
-
}).label('DeleteTokenRequestResponse'),
|
|
323
|
+
schema: deleteTokenResponseSchema,
|
|
307
324
|
failAction: 'log'
|
|
308
325
|
}
|
|
309
326
|
}
|
|
@@ -538,9 +555,9 @@ async function init(args) {
|
|
|
538
555
|
pageSize: Joi.number()
|
|
539
556
|
.integer()
|
|
540
557
|
.min(1)
|
|
541
|
-
.max(tokenAuditLog.
|
|
542
|
-
.default(
|
|
543
|
-
.example(
|
|
558
|
+
.max(tokenAuditLog.MAX_PAGE_SIZE)
|
|
559
|
+
.default(tokenAuditLog.DEFAULT_LOG_PAGE_SIZE)
|
|
560
|
+
.example(tokenAuditLog.DEFAULT_LOG_PAGE_SIZE)
|
|
544
561
|
.description('How many entries per page')
|
|
545
562
|
.label('PageSize')
|
|
546
563
|
}).label('TokenLogQuery')
|
|
@@ -596,6 +613,159 @@ async function init(args) {
|
|
|
596
613
|
}
|
|
597
614
|
}
|
|
598
615
|
});
|
|
616
|
+
|
|
617
|
+
// --------------------------------------------------------------------------------------------
|
|
618
|
+
// Deprecated aliases. v2.79.0 renamed the token endpoints (POST /v1/token -> POST /v1/tokens,
|
|
619
|
+
// DELETE /v1/token/{token} -> DELETE /v1/tokens/{token}) and folded the per-account listing
|
|
620
|
+
// into GET /v1/tokens?account=..., which handed every pre-2.79 integration that provisions,
|
|
621
|
+
// revokes or lists tokens a 404 from a minor upgrade - token-rotation pipelines failing
|
|
622
|
+
// first. The old paths stay registered against the same handlers and schema instances, but are
|
|
623
|
+
// left OUT of the published document and the API reference (plugins.openapi.deprecated - see
|
|
624
|
+
// lib/openapi/build-document.js): they exist for old integrations to keep working, and
|
|
625
|
+
// documenting them would steer new ones onto retired paths.
|
|
626
|
+
|
|
627
|
+
server.route({
|
|
628
|
+
method: 'POST',
|
|
629
|
+
path: '/v1/token',
|
|
630
|
+
|
|
631
|
+
handler: provisionTokenHandler,
|
|
632
|
+
|
|
633
|
+
options: {
|
|
634
|
+
description: 'Provision an access token (deprecated)',
|
|
635
|
+
notes: 'Deprecated alias of `POST /v1/tokens`, which behaves identically - use that path instead.',
|
|
636
|
+
tags: ['api', 'Access Tokens'],
|
|
637
|
+
|
|
638
|
+
plugins: {
|
|
639
|
+
openapi: {
|
|
640
|
+
deprecated: true,
|
|
641
|
+
responses: apiResponses('Returns the new token value. This is the only time it is shown - store it now.', 400, 401, 403, 404, 429, 500)
|
|
642
|
+
}
|
|
643
|
+
},
|
|
644
|
+
|
|
645
|
+
auth: {
|
|
646
|
+
strategy: 'api-token',
|
|
647
|
+
mode: 'required'
|
|
648
|
+
},
|
|
649
|
+
cors: CORS_CONFIG,
|
|
650
|
+
|
|
651
|
+
validate: {
|
|
652
|
+
options: {
|
|
653
|
+
stripUnknown: false,
|
|
654
|
+
abortEarly: false,
|
|
655
|
+
convert: true
|
|
656
|
+
},
|
|
657
|
+
failAction,
|
|
658
|
+
|
|
659
|
+
payload: createTokenPayloadSchema
|
|
660
|
+
},
|
|
661
|
+
|
|
662
|
+
response: {
|
|
663
|
+
schema: createTokenResponseSchema,
|
|
664
|
+
failAction: 'log'
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
server.route({
|
|
670
|
+
method: 'DELETE',
|
|
671
|
+
path: '/v1/token/{token}',
|
|
672
|
+
|
|
673
|
+
handler: deleteTokenHandler,
|
|
674
|
+
options: {
|
|
675
|
+
description: 'Remove a token (deprecated)',
|
|
676
|
+
notes: 'Deprecated alias of `DELETE /v1/tokens/{token}`, which behaves identically - use that path instead.',
|
|
677
|
+
tags: ['api', 'Access Tokens'],
|
|
678
|
+
|
|
679
|
+
plugins: {
|
|
680
|
+
openapi: {
|
|
681
|
+
deprecated: true,
|
|
682
|
+
'x-ee-impact': IMPACT.DESTRUCTIVE,
|
|
683
|
+
responses: apiResponses('Returns a deletion marker. The token stops working immediately.', 400, 401, 403, 429, 500)
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
|
|
687
|
+
auth: {
|
|
688
|
+
strategy: 'api-token',
|
|
689
|
+
mode: 'required'
|
|
690
|
+
},
|
|
691
|
+
cors: CORS_CONFIG,
|
|
692
|
+
|
|
693
|
+
validate: {
|
|
694
|
+
options: {
|
|
695
|
+
stripUnknown: false,
|
|
696
|
+
abortEarly: false,
|
|
697
|
+
convert: true
|
|
698
|
+
},
|
|
699
|
+
failAction,
|
|
700
|
+
|
|
701
|
+
params: deleteTokenParamsSchema
|
|
702
|
+
},
|
|
703
|
+
|
|
704
|
+
response: {
|
|
705
|
+
schema: deleteTokenResponseSchema,
|
|
706
|
+
failAction: 'log'
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
server.route({
|
|
712
|
+
method: 'GET',
|
|
713
|
+
path: '/v1/tokens/account/{account}',
|
|
714
|
+
|
|
715
|
+
async handler(request) {
|
|
716
|
+
try {
|
|
717
|
+
// The pre-2.79 response shape: the account's tokens with no paging metadata
|
|
718
|
+
return { tokens: (await tokens.list(request.params.account, 0, 1000)).tokens };
|
|
719
|
+
} catch (err) {
|
|
720
|
+
handleError(request, err);
|
|
721
|
+
}
|
|
722
|
+
},
|
|
723
|
+
|
|
724
|
+
options: {
|
|
725
|
+
description: 'List account tokens (deprecated)',
|
|
726
|
+
notes: 'Deprecated alias for listing the access tokens of one account - use `GET /v1/tokens` with the `account` argument instead, which also pages the listing.',
|
|
727
|
+
tags: ['api', 'Access Tokens'],
|
|
728
|
+
|
|
729
|
+
plugins: {
|
|
730
|
+
openapi: {
|
|
731
|
+
deprecated: true,
|
|
732
|
+
responses: apiResponses('Returns the access tokens scoped to the account.', 400, 401, 403, 429, 500)
|
|
733
|
+
}
|
|
734
|
+
},
|
|
735
|
+
|
|
736
|
+
auth: {
|
|
737
|
+
strategy: 'api-token',
|
|
738
|
+
mode: 'required'
|
|
739
|
+
},
|
|
740
|
+
cors: CORS_CONFIG,
|
|
741
|
+
|
|
742
|
+
validate: {
|
|
743
|
+
options: {
|
|
744
|
+
stripUnknown: false,
|
|
745
|
+
abortEarly: false,
|
|
746
|
+
convert: true
|
|
747
|
+
},
|
|
748
|
+
failAction,
|
|
749
|
+
params: Joi.object({
|
|
750
|
+
account: accountIdSchema.required()
|
|
751
|
+
})
|
|
752
|
+
},
|
|
753
|
+
|
|
754
|
+
response: {
|
|
755
|
+
schema: Joi.object({
|
|
756
|
+
tokens: Joi.array()
|
|
757
|
+
.items(
|
|
758
|
+
Joi.object({
|
|
759
|
+
account: accountIdSchema.required(),
|
|
760
|
+
...tokenListItemFields
|
|
761
|
+
}).label('AccountTokensItem')
|
|
762
|
+
)
|
|
763
|
+
.label('AccountTokensEntries')
|
|
764
|
+
}).label('AccountsTokensResponse'),
|
|
765
|
+
failAction: 'log'
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
});
|
|
599
769
|
}
|
|
600
770
|
|
|
601
771
|
module.exports = init;
|
package/lib/arf-detect.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
const libmime = require('libmime');
|
|
4
4
|
const addressparser = require('nodemailer/lib/addressparser');
|
|
5
5
|
const { toCamelCase } = require('./utils/to-camel-case');
|
|
6
|
+
const { decodeHeaders } = require('./utils/decode-headers');
|
|
7
|
+
const { isUnsafeTransformedKey } = require('./utils/unsafe-key');
|
|
6
8
|
|
|
7
9
|
const ARF_SINGLE = [
|
|
8
10
|
'feedback-type',
|
|
@@ -33,7 +35,7 @@ const arfDetect = async messageInfo => {
|
|
|
33
35
|
case 'message/feedback-report': {
|
|
34
36
|
// found a feedback report
|
|
35
37
|
|
|
36
|
-
const contents =
|
|
38
|
+
const contents = decodeHeaders((attachment.content || '').toString());
|
|
37
39
|
|
|
38
40
|
Object.keys(contents).forEach(key => {
|
|
39
41
|
let value = contents[key];
|
|
@@ -88,7 +90,7 @@ const arfDetect = async messageInfo => {
|
|
|
88
90
|
contents = contents.substr(0, headerPos.index);
|
|
89
91
|
}
|
|
90
92
|
|
|
91
|
-
const headers =
|
|
93
|
+
const headers = decodeHeaders(contents);
|
|
92
94
|
|
|
93
95
|
// Hotmail original recipient X-HmXmrOriginalRecipient
|
|
94
96
|
const addresses = addressparser([].concat(headers['x-hmxmroriginalrecipient'] || []).join(', '))
|
|
@@ -110,7 +112,7 @@ const arfDetect = async messageInfo => {
|
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
let sourceIp = [].concat(headers['x-sender-ip'] || []).pop();
|
|
113
|
-
if (sourceIp && !report['source-ip']) {
|
|
115
|
+
if (sourceIp && !report.arf['source-ip']) {
|
|
114
116
|
report.arf['source-ip'] = sourceIp;
|
|
115
117
|
}
|
|
116
118
|
|
|
@@ -211,10 +213,21 @@ function camelCaseComplaint(report) {
|
|
|
211
213
|
|
|
212
214
|
for (let subKey of ['arf', 'headers']) {
|
|
213
215
|
for (let key of Object.keys(report[subKey])) {
|
|
216
|
+
// decodeHeaders() dropped the prototype-shaped names at the parse boundary, but
|
|
217
|
+
// toCamelCase() re-creates one out of a name that boundary had no reason to refuse:
|
|
218
|
+
// "_-_proto__" camelCases into "__proto__" (a prototype swap) and "to-string" into
|
|
219
|
+
// "toString" (an own property shadowing the method), hence the transformed-key test
|
|
220
|
+
// covering every Object.prototype member. A feedback report is an attacker-supplied
|
|
221
|
+
// attachment, so the name is theirs to choose.
|
|
222
|
+
let displayKey = toCamelCase(key);
|
|
223
|
+
if (isUnsafeTransformedKey(displayKey)) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
|
|
214
227
|
if (!complaint[subKey]) {
|
|
215
228
|
complaint[subKey] = {};
|
|
216
229
|
}
|
|
217
|
-
complaint[subKey][
|
|
230
|
+
complaint[subKey][displayKey] = report[subKey][key];
|
|
218
231
|
}
|
|
219
232
|
}
|
|
220
233
|
|
package/lib/bounce-detect.js
CHANGED
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
* @requires mailparser - For parsing email messages
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
const
|
|
25
|
+
const { decodeHeaders } = require('./utils/decode-headers');
|
|
26
|
+
const { isUnsafeTransformedKey } = require('./utils/unsafe-key');
|
|
27
|
+
const { pushHeaderValue } = require('./utils/header-map');
|
|
26
28
|
const simpleParser = require('mailparser').simpleParser;
|
|
27
29
|
const { toCamelCase } = require('./utils/to-camel-case');
|
|
28
30
|
|
|
@@ -45,7 +47,7 @@ function splitAddressType(value) {
|
|
|
45
47
|
*
|
|
46
48
|
* A DSN body is not a single header block. RFC 3464 splits it into a per-message block and a
|
|
47
49
|
* separate per-recipient block for every reported address, with an empty line between them.
|
|
48
|
-
*
|
|
50
|
+
* decodeHeaders() stops at the first empty line, as that is where a header block ends,
|
|
49
51
|
* so each block is decoded on its own.
|
|
50
52
|
*
|
|
51
53
|
* @param {string|Buffer} content - Raw message/delivery-status body
|
|
@@ -57,7 +59,7 @@ function decodeDeliveryStatusBlocks(content) {
|
|
|
57
59
|
.toString()
|
|
58
60
|
.replace(/\r\n|\r/g, '\n')
|
|
59
61
|
.split(/\n{2,}/)
|
|
60
|
-
.map(block =>
|
|
62
|
+
.map(block => decodeHeaders(block))
|
|
61
63
|
// A block of nothing but a continuation line decodes to a single empty key, which is
|
|
62
64
|
// not a header and would otherwise be merged into the result
|
|
63
65
|
.filter(entries => Object.keys(entries).some(key => key))
|
|
@@ -126,14 +128,23 @@ function parseDeliveryReport(content) {
|
|
|
126
128
|
let structured = {};
|
|
127
129
|
|
|
128
130
|
for (let key of Object.keys(entries)) {
|
|
129
|
-
|
|
130
|
-
// it would hand the value to the Object.prototype setter and swap the report's prototype,
|
|
131
|
-
// and defining it as an own property instead leaves a key msgpack refuses to decode
|
|
132
|
-
if (!key || key === '__proto__') {
|
|
131
|
+
if (!key) {
|
|
133
132
|
continue;
|
|
134
133
|
}
|
|
135
134
|
|
|
135
|
+
// The field names come from the message. "__proto__" names no DSN field, while assigning
|
|
136
|
+
// it would hand the value to the Object.prototype setter and swap the report's prototype,
|
|
137
|
+
// and defining it as an own property instead leaves a key msgpack refuses to decode.
|
|
138
|
+
//
|
|
139
|
+
// Checked on the camelCased key rather than the raw name: decodeHeaders() already dropped
|
|
140
|
+
// the raw name at the parse boundary, but toCamelCase() re-creates it out of a name that
|
|
141
|
+
// boundary had no reason to refuse - "_-_proto__" camelCases straight into "__proto__",
|
|
142
|
+
// and "to-string" into "toString", which as an own property shadows the method on the
|
|
143
|
+
// published report - hence the transformed-key test covering every Object.prototype member.
|
|
136
144
|
let displayKey = toCamelCase(key);
|
|
145
|
+
if (isUnsafeTransformedKey(displayKey)) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
137
148
|
let value = entries[key].at(-1);
|
|
138
149
|
|
|
139
150
|
if (typeof value !== 'string') {
|
|
@@ -247,7 +258,7 @@ function parseDeliveryStatus(content) {
|
|
|
247
258
|
* Takes decoded entries rather than the raw attachment, as every caller has just decoded the
|
|
248
259
|
* same content, most of them to keep as the reported message headers.
|
|
249
260
|
*
|
|
250
|
-
* @param {Object} entries - Header entries from
|
|
261
|
+
* @param {Object} entries - Header entries from decodeHeaders()
|
|
251
262
|
* @returns {Object} Parsed header information
|
|
252
263
|
* @returns {string} [returns.messageId] - The Message-ID header value
|
|
253
264
|
*/
|
|
@@ -359,7 +370,7 @@ async function bounceDetect(sourceStream) {
|
|
|
359
370
|
|
|
360
371
|
// Process RFC822 headers attachment (contains headers of the original message)
|
|
361
372
|
if (messageHeaders) {
|
|
362
|
-
parsedMessageHeaders =
|
|
373
|
+
parsedMessageHeaders = decodeHeaders((messageHeaders.content || '').toString().trim());
|
|
363
374
|
result = Object.assign(result, parseDeliveryHeaders(parsedMessageHeaders));
|
|
364
375
|
}
|
|
365
376
|
|
|
@@ -374,11 +385,11 @@ async function bounceDetect(sourceStream) {
|
|
|
374
385
|
|
|
375
386
|
if (parsedOriginal.headerLines && Array.isArray(parsedOriginal.headerLines)) {
|
|
376
387
|
parsedOriginal.headerLines.forEach(entry => {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
//
|
|
381
|
-
headers
|
|
388
|
+
// Preserve the original header value (after the key and colon).
|
|
389
|
+
// pushHeaderValue() skips names that resolve to an Object.prototype member,
|
|
390
|
+
// which a bare `!headers[key]` probe would have pushed onto, throwing out of
|
|
391
|
+
// the whole block and losing every header of the bounced message
|
|
392
|
+
pushHeaderValue(headers, entry.key, entry.line.substring(entry.key.length + 1).trim());
|
|
382
393
|
});
|
|
383
394
|
}
|
|
384
395
|
|
|
@@ -402,7 +413,7 @@ async function bounceDetect(sourceStream) {
|
|
|
402
413
|
if (!messageHeaders) {
|
|
403
414
|
messageHeaders = originalAttachments.find(attachment => attachment.contentType?.toLowerCase() === 'text/rfc822-headers');
|
|
404
415
|
if (messageHeaders) {
|
|
405
|
-
let headerEntries =
|
|
416
|
+
let headerEntries = decodeHeaders((messageHeaders.content || '').toString().trim());
|
|
406
417
|
result = Object.assign(result, parseDeliveryHeaders(headerEntries));
|
|
407
418
|
}
|
|
408
419
|
}
|
|
@@ -459,7 +470,7 @@ async function bounceDetect(sourceStream) {
|
|
|
459
470
|
// Additional validation: content should look like email headers
|
|
460
471
|
// Check for common header patterns (Received:, Message-ID:, Date:, From:)
|
|
461
472
|
if (/^\s*(Received|Message-ID|Date|From):/im.test(headerContent)) {
|
|
462
|
-
let headers =
|
|
473
|
+
let headers = decodeHeaders(headerContent);
|
|
463
474
|
if (headers && headers['message-id']) {
|
|
464
475
|
parsedMessageHeaders = headers;
|
|
465
476
|
result = Object.assign(result, parseDeliveryHeaders(headers));
|
|
@@ -905,7 +916,7 @@ async function bounceDetect(sourceStream) {
|
|
|
905
916
|
let end = text.substr(m.index + m[0].length).match(/\r?\n\r?\n|$/);
|
|
906
917
|
if (end) {
|
|
907
918
|
let headers = text.substr(m.index, m[0].length + end.index).trim();
|
|
908
|
-
let entries =
|
|
919
|
+
let entries = decodeHeaders(headers);
|
|
909
920
|
if (entries['message-id'] && entries['message-id'].length) {
|
|
910
921
|
result.messageId = entries['message-id'][0].trim();
|
|
911
922
|
// Only use these headers if we haven't found headers elsewhere
|