emailengine-app 2.82.1 → 2.83.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.
Files changed (59) hide show
  1. package/.ncurc.js +8 -1
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +25 -0
  4. package/data/google-crawlers.json +1 -1
  5. package/lib/account.js +16 -3
  6. package/lib/api-routes/account-routes.js +8 -6
  7. package/lib/api-routes/blocklist-routes.js +4 -4
  8. package/lib/api-routes/oauth2-app-routes.js +5 -2
  9. package/lib/api-routes/route-helpers.js +28 -0
  10. package/lib/api-routes/submit-routes.js +6 -5
  11. package/lib/bounce-detect.js +4 -2
  12. package/lib/egress-filter.js +8 -3
  13. package/lib/email-client/gmail-client.js +3 -1
  14. package/lib/email-client/imap-client.js +2 -1
  15. package/lib/email-client/outlook-client.js +106 -47
  16. package/lib/email-client/outlook-fallback-poll.js +30 -0
  17. package/lib/enum-descriptions.js +3 -1
  18. package/lib/imapproxy/imap-core/README.md +1 -0
  19. package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +11 -1
  20. package/lib/imapproxy/proxy-handoff.js +6 -3
  21. package/lib/imapproxy/response-error.js +14 -1
  22. package/lib/oauth/gcp-metadata.js +222 -0
  23. package/lib/oauth/gmail.js +115 -20
  24. package/lib/oauth/mail-ru.js +10 -4
  25. package/lib/oauth/outlook.js +11 -4
  26. package/lib/oauth/token-fetch.js +4 -2
  27. package/lib/oauth/verify-app.js +120 -32
  28. package/lib/oauth2-apps.js +46 -12
  29. package/lib/schemas.js +60 -18
  30. package/lib/tools.js +52 -2
  31. package/lib/ui-routes/admin-entities-routes.js +2 -2
  32. package/lib/ui-routes/auth-routes.js +4 -1
  33. package/lib/ui-routes/gmail-service-auth.js +64 -0
  34. package/lib/ui-routes/oauth-config-routes.js +8 -16
  35. package/lib/ui-routes/outlook-subscription-view.js +36 -0
  36. package/lib/ui-routes/route-helpers.js +2 -14
  37. package/lib/ui-routes/suppression-list-routes.js +2 -2
  38. package/lib/utils/network.js +29 -0
  39. package/lib/webhook-request.js +12 -4
  40. package/lib/webhook-routing.js +34 -11
  41. package/package.json +11 -11
  42. package/sbom.json +1 -1
  43. package/server.js +8 -2
  44. package/static/css/flyonui.css +1 -1
  45. package/static/js/app.js +2 -1
  46. package/static/js/ui.js +6 -1
  47. package/static/licenses.html +18 -28
  48. package/translations/messages.pot +73 -73
  49. package/views/accounts/account.hbs +5 -2
  50. package/views/accounts/edit.hbs +1 -1
  51. package/views/config/imap-proxy.hbs +1 -1
  52. package/views/config/network.hbs +7 -5
  53. package/views/config/oauth/app.hbs +2 -0
  54. package/views/config/smtp.hbs +1 -1
  55. package/views/config/tls.hbs +2 -2
  56. package/views/config/webhooks.hbs +1 -1
  57. package/views/partials/oauth_form.hbs +116 -27
  58. package/workers/api.js +4 -2
  59. package/workers/webhooks.js +18 -7
@@ -111,10 +111,11 @@ Read about setting up {{providerData.comment}} from <a href="{{providerData.tuto
111
111
  <div>
112
112
  <label class="label-text block">Authentication method</label>
113
113
  <input type="hidden" name="authMethod" id="authMethod"
114
- value="{{#if authMethodIsExternalAccount}}externalAccount{{else}}serviceKey{{/if}}" />
114
+ value="{{#if authMethodIsExternalAccount}}externalAccount{{else if authMethodIsMetadataServer}}metadataServer{{else}}serviceKey{{/if}}" />
115
115
  {{#if authMethodLocked}}
116
116
  <p class="mb-1">
117
- <strong>{{#if authMethodIsExternalAccount}}Workload Identity Federation (keyless){{else}}Service
117
+ <strong>{{#if authMethodIsExternalAccount}}Workload Identity Federation (keyless){{else if
118
+ authMethodIsMetadataServer}}Attached service account (Google Cloud){{else}}Service
118
119
  account key{{/if}}</strong>
119
120
  </p>
120
121
  <span class="helper-text">The authentication method is fixed once the application has been created and
@@ -135,10 +136,20 @@ Read about setting up {{providerData.comment}} from <a href="{{providerData.tuto
135
136
  id="auth-method-tab-externalAccount" data-auth-method="externalAccount" role="tab"
136
137
  aria-selected="{{#if authMethodIsExternalAccount}}true{{else}}false{{/if}}">Workload Identity
137
138
  Federation (keyless)</button>
139
+ {{!-- Pub/Sub only: the metadata server's token is the service account's own and
140
+ cannot impersonate a Workspace user. The script at the end of this partial
141
+ shows it while the Cloud Pub/Sub base scope is selected --}}
142
+ <button type="button"
143
+ class="tab auth-method-tab{{#if authMethodIsMetadataServer}} tab-active{{/if}}{{#unless baseScopesPubsub}} hidden{{/unless}}"
144
+ id="auth-method-tab-metadataServer" data-auth-method="metadataServer" data-auth-method-scope="pubsub"
145
+ role="tab" aria-selected="{{#if authMethodIsMetadataServer}}true{{else}}false{{/if}}">Attached
146
+ service account (Google Cloud)</button>
138
147
  </nav>
139
148
  <span class="helper-text">"Service account key" expects a downloaded JSON key file.
140
149
  "Workload Identity Federation" authenticates without a long-lived key, using a credential issued
141
- by your runtime environment.</span>
150
+ by your runtime environment. For a Cloud Pub/Sub application running on Google Cloud, "Attached
151
+ service account" uses the service account of the VM, GKE workload or Cloud Run service itself,
152
+ with nothing to store.</span>
142
153
  {{/if}}
143
154
  </div>
144
155
 
@@ -159,6 +170,22 @@ Read about setting up {{providerData.comment}} from <a href="{{providerData.tuto
159
170
  </div>
160
171
  </div>
161
172
 
173
+ <div class="auth-method-section auth-method-section-metadataServer{{#unless authMethodIsMetadataServer}} hidden{{/unless}}">
174
+ <div class="space-y-2">
175
+ <p class="text-sm">EmailEngine requests access tokens for the service account attached to the
176
+ machine it runs on, from the Google Cloud metadata server. Nothing is stored. Grant that service
177
+ account the <code>Pub/Sub Admin</code> role, and on Compute Engine give the VM the
178
+ <code>cloud-platform</code> access scope.</p>
179
+ {{#if actionCreate}}
180
+ <div class="flex flex-wrap items-center gap-3">
181
+ {{> ui/btn label="Detect from this host" variant="info" id="metadataProbe"
182
+ icon="icon-[tabler--cloud-search]"}}
183
+ <span class="helper-text" id="metadataProbeResult" aria-live="polite"></span>
184
+ </div>
185
+ {{/if}}
186
+ </div>
187
+ </div>
188
+
162
189
  <div>
163
190
  {{#> ui/form-field id="googleProjectId" label="Google Cloud Project ID" error=errors.googleProjectId}}
164
191
  <input type="text" class="input{{#if errors.googleProjectId}} is-invalid{{/if}}" id="googleProjectId"
@@ -169,23 +196,29 @@ Read about setting up {{providerData.comment}} from <a href="{{providerData.tuto
169
196
  {{/ui/form-field}}
170
197
  </div>
171
198
 
172
- <div>
173
- {{#> ui/form-field id="serviceClientEmail" label="Service account email" error=errors.serviceClientEmail}}
174
- <input type="email" class="input{{#if errors.serviceClientEmail}} is-invalid{{/if}}" id="serviceClientEmail"
175
- name="serviceClientEmail" value="{{values.serviceClientEmail}}"
176
- placeholder="Enter the principal of the service, for example &quot;name@project-123.iam.gserviceaccount.com&quot;"
177
- required />
178
- <span class="helper-text">Email address of the Google service account.</span>
179
- {{/ui/form-field}}
180
- </div>
199
+ {{!-- Not used by the attached service account, which the metadata server identifies. The
200
+ inputs of a hidden auth-method section are disabled, so their required attribute cannot
201
+ block the form and their values are not submitted --}}
202
+ <div
203
+ class="auth-method-section auth-method-section-serviceKey auth-method-section-externalAccount space-y-4{{#if authMethodIsMetadataServer}} hidden{{/if}}">
204
+ <div>
205
+ {{#> ui/form-field id="serviceClientEmail" label="Service account email" error=errors.serviceClientEmail}}
206
+ <input type="email" class="input{{#if errors.serviceClientEmail}} is-invalid{{/if}}" id="serviceClientEmail"
207
+ name="serviceClientEmail" value="{{values.serviceClientEmail}}"
208
+ placeholder="Enter the principal of the service, for example &quot;name@project-123.iam.gserviceaccount.com&quot;"
209
+ required {{#if authMethodIsMetadataServer}}disabled{{/if}} />
210
+ <span class="helper-text">Email address of the Google service account.</span>
211
+ {{/ui/form-field}}
212
+ </div>
181
213
 
182
- <div>
183
- {{#> ui/form-field id="serviceClient" label="Service account client ID" error=errors.serviceClient}}
184
- <input type="text" class="input{{#if errors.serviceClient}} is-invalid{{/if}}" id="serviceClient"
185
- name="serviceClient" value="{{values.serviceClient}}" placeholder="Enter service client ID&mldr;"
186
- required />
187
- <span class="helper-text">Numeric client ID used to configure domain-wide delegation.</span>
188
- {{/ui/form-field}}
214
+ <div>
215
+ {{#> ui/form-field id="serviceClient" label="Service account client ID" error=errors.serviceClient}}
216
+ <input type="text" class="input{{#if errors.serviceClient}} is-invalid{{/if}}" id="serviceClient"
217
+ name="serviceClient" value="{{values.serviceClient}}" placeholder="Enter service client ID&mldr;"
218
+ required {{#if authMethodIsMetadataServer}}disabled{{/if}} />
219
+ <span class="helper-text">Numeric client ID used to configure domain-wide delegation.</span>
220
+ {{/ui/form-field}}
221
+ </div>
189
222
  </div>
190
223
 
191
224
  <div class="auth-method-section auth-method-section-serviceKey{{#unless authMethodIsServiceKey}} hidden{{/unless}}">
@@ -1343,24 +1376,80 @@ open=values.skipScopes}}
1343
1376
  document.querySelectorAll('.auth-method-section').forEach(section => {
1344
1377
  let active = section.classList.contains('auth-method-section-' + selected);
1345
1378
  section.classList.toggle('hidden', !active);
1379
+ // a hidden section's required fields must not block the form, nor its values ride along
1380
+ section.querySelectorAll('input, textarea').forEach(field => {
1381
+ field.disabled = !active;
1382
+ });
1346
1383
  });
1347
1384
  };
1385
+ let selectTab = tab => {
1386
+ let selected = tab.getAttribute('data-auth-method');
1387
+ authMethodTabs.forEach(other => {
1388
+ let isActive = other === tab;
1389
+ other.classList.toggle('tab-active', isActive);
1390
+ other.setAttribute('aria-selected', isActive ? 'true' : 'false');
1391
+ });
1392
+ authMethodInput.value = selected;
1393
+ updateSections(selected);
1394
+ };
1348
1395
  authMethodTabs.forEach(tab => {
1349
1396
  tab.addEventListener('click', e => {
1350
1397
  e.preventDefault();
1351
1398
  if (tab.classList.contains('disabled') || tab.classList.contains('tab-active')) {
1352
1399
  return;
1353
1400
  }
1354
- let selected = tab.getAttribute('data-auth-method');
1355
- authMethodTabs.forEach(other => {
1356
- let isActive = other === tab;
1357
- other.classList.toggle('tab-active', isActive);
1358
- other.setAttribute('aria-selected', isActive ? 'true' : 'false');
1359
- });
1360
- authMethodInput.value = selected;
1361
- updateSections(selected);
1401
+ selectTab(tab);
1362
1402
  });
1363
1403
  });
1404
+ // the rendered selection, so a re-rendered form disables the sections it hides from the start
1405
+ updateSections(authMethodInput.value);
1406
+
1407
+ // A method tied to a base scope (the attached service account, Pub/Sub only) is offered
1408
+ // while that scope is selected. Switching away from it while its tab is active falls back
1409
+ // to the key tab, so the form never submits a method the schema refuses for the scope
1410
+ let scopedTabs = document.querySelectorAll('.auth-method-tab[data-auth-method-scope]');
1411
+ let checkScopedTabs = () => {
1412
+ let scopeElm = document.querySelector('.base-scopes-radio:checked');
1413
+ if (!scopeElm) {
1414
+ return;
1415
+ }
1416
+ scopedTabs.forEach(tab => {
1417
+ let offered = tab.getAttribute('data-auth-method-scope') === scopeElm.value;
1418
+ tab.classList.toggle('hidden', !offered);
1419
+ if (!offered && tab.classList.contains('tab-active')) {
1420
+ selectTab(document.getElementById('auth-method-tab-serviceKey'));
1421
+ }
1422
+ });
1423
+ };
1424
+ if (scopedTabs.length) {
1425
+ document.querySelectorAll('.base-scopes-radio').forEach(radioElm => {
1426
+ radioElm.addEventListener('change', checkScopedTabs);
1427
+ });
1428
+ checkScopedTabs();
1429
+ }
1430
+ }
1431
+
1432
+ let metadataProbeElm = document.getElementById('metadataProbe');
1433
+ if (metadataProbeElm) {
1434
+ let resultElm = document.getElementById('metadataProbeResult');
1435
+ metadataProbeElm.addEventListener('click', e => {
1436
+ e.preventDefault();
1437
+ resultElm.textContent = 'Asking the metadata server...';
1438
+ uiBusyAction(metadataProbeElm, () =>
1439
+ uiPostJson('/admin/config/oauth/metadata-probe', {})
1440
+ .then(data => {
1441
+ if (!data || !data.success) {
1442
+ resultElm.textContent = (data && data.error) || 'The metadata server could not be reached';
1443
+ return;
1444
+ }
1445
+ document.getElementById('googleProjectId').value = data.projectId || '';
1446
+ resultElm.textContent = `Service account ${data.serviceAccountEmail}, project ${data.projectId}`;
1447
+ })
1448
+ .catch(err => {
1449
+ resultElm.textContent = err.message;
1450
+ })
1451
+ );
1452
+ });
1364
1453
  }
1365
1454
 
1366
1455
  });
package/workers/api.js CHANGED
@@ -44,7 +44,7 @@ const {
44
44
  setAdminSession,
45
45
  isEndedSession
46
46
  } = require('../lib/tools');
47
- const { matchIp, resolveClientIp, detectAutomatedRequest } = require('../lib/utils/network');
47
+ const { matchIp, resolveClientIp, detectAutomatedRequest, getAccountHttpRoute } = require('../lib/utils/network');
48
48
 
49
49
  const { initSentry } = require('../lib/sentry');
50
50
  initSentry('api');
@@ -2295,7 +2295,9 @@ const init = async () => {
2295
2295
  throw error;
2296
2296
  }
2297
2297
 
2298
- const oAuth2Client = await oauth2Apps.getClient(oauth2App.id);
2298
+ // The code exchange, the profile lookups and any revoke already speak for the account being
2299
+ // set up, so they leave through its route (its own proxy, if the setup named one)
2300
+ const oAuth2Client = await oauth2Apps.getClient(oauth2App.id, { route: await getAccountHttpRoute(redis, accountData) });
2299
2301
 
2300
2302
  // have to use HTML redirect, otherwise samesite=strict cookies are not passed on
2301
2303
  const renderRedirect = httpRedirectUrl =>
@@ -14,7 +14,7 @@ const { readEnvValue, threadStats, getDuration, httpAgent, getServiceSecret, red
14
14
  const { sendWebhookRequest, isUnrecoverableWebhookError } = require('../lib/webhook-request');
15
15
  const { willBeFinalAttempt, isFinalFailedAttempt } = require('../lib/delivery-error');
16
16
  const { validateWebhookTarget } = require('../lib/webhook-egress');
17
- const { resolveTargetUrl, isDeliverableRoute, eventAllowed, deliveryCustomHeaders, isRouteMappingMissing } = require('../lib/webhook-routing');
17
+ const { resolveTargetUrl, isDeliverableRoute, eventAllowed, headerLevels, deliveryCustomHeaders, isRouteMappingMissing } = require('../lib/webhook-routing');
18
18
 
19
19
  const { initSentry } = require('../lib/sentry');
20
20
  initSentry('webhooks');
@@ -272,7 +272,11 @@ const notifyWorker = new Worker(
272
272
  let accountWebhooks = await openAccountField('webhooks', storedWebhooks, job.data.account);
273
273
 
274
274
  // the global setting is only fetched when neither a custom route nor the account override decides the target
275
- let webhooks = resolveTargetUrl(customRoute && customRoute.targetUrl, accountWebhooks, null).url || (await settings.get('webhooks'));
275
+ let target = resolveTargetUrl(customRoute && customRoute.targetUrl, accountWebhooks, null);
276
+ if (!target.url) {
277
+ target = resolveTargetUrl(null, null, await settings.get('webhooks'));
278
+ }
279
+ let webhooks = target.url;
276
280
  if (!webhooks) {
277
281
  // A skipped delivery still reports the job as completed, so without this line a
278
282
  // missing target is indistinguishable from a successful delivery - it reads as the
@@ -289,11 +293,14 @@ const notifyWorker = new Worker(
289
293
  return;
290
294
  }
291
295
 
296
+ // Only the header lists that travel to this target are loaded; lib/webhook-routing.js
297
+ // holds the rule and the reasons
298
+ let levels = headerLevels(target.source);
299
+
292
300
  let accountWebhooksCustomHeaders;
293
- // The account's headers belong to the account's (or the global) target. A custom route is
294
- // an operator-defined endpoint with headers of its own: the account's secrets must not
295
- // travel there, nor override the route's own Authorization.
296
- let accountWebhooksCustomHeadersJson = customRoute ? null : await openAccountField('webhooksCustomHeaders', storedCustomHeaders, job.data.account);
301
+ let accountWebhooksCustomHeadersJson = levels.includes('account')
302
+ ? await openAccountField('webhooksCustomHeaders', storedCustomHeaders, job.data.account)
303
+ : null;
297
304
  if (accountWebhooksCustomHeadersJson) {
298
305
  try {
299
306
  accountWebhooksCustomHeaders = JSON.parse(accountWebhooksCustomHeadersJson);
@@ -425,7 +432,11 @@ const notifyWorker = new Worker(
425
432
  }
426
433
  Object.assign(
427
434
  headers,
428
- deliveryCustomHeaders(customRoute, customRoute ? null : await settings.get('webhooksCustomHeaders'), accountWebhooksCustomHeaders)
435
+ deliveryCustomHeaders(target.source, {
436
+ route: customRoute && customRoute.customHeaders,
437
+ global: levels.includes('global') ? await settings.get('webhooksCustomHeaders') : null,
438
+ account: accountWebhooksCustomHeaders
439
+ })
429
440
  );
430
441
 
431
442
  let start = Date.now();