emailengine-app 2.82.2 → 2.83.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 (70) hide show
  1. package/.ncurc.js +8 -1
  2. package/.release-please-manifest.json +1 -1
  3. package/CHANGELOG.md +29 -0
  4. package/data/google-crawlers.json +1 -1
  5. package/lib/account.js +16 -3
  6. package/lib/api-reference/format.js +1 -1
  7. package/lib/api-routes/account-routes.js +8 -6
  8. package/lib/api-routes/blocklist-routes.js +4 -4
  9. package/lib/api-routes/export-routes.js +5 -5
  10. package/lib/api-routes/oauth2-app-routes.js +8 -2
  11. package/lib/api-routes/route-helpers.js +34 -0
  12. package/lib/api-routes/submit-routes.js +6 -5
  13. package/lib/bounce-detect.js +4 -2
  14. package/lib/egress-filter.js +8 -3
  15. package/lib/email-client/gmail-client.js +3 -1
  16. package/lib/email-client/imap-client.js +2 -1
  17. package/lib/email-client/outlook-client.js +11 -2
  18. package/lib/enum-descriptions.js +3 -1
  19. package/lib/imapproxy/imap-core/README.md +1 -0
  20. package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +11 -1
  21. package/lib/imapproxy/proxy-handoff.js +6 -3
  22. package/lib/imapproxy/response-error.js +14 -1
  23. package/lib/oauth/gcp-metadata.js +259 -0
  24. package/lib/oauth/gmail.js +121 -20
  25. package/lib/oauth/mail-ru.js +10 -4
  26. package/lib/oauth/outlook.js +11 -4
  27. package/lib/oauth/token-fetch.js +4 -2
  28. package/lib/oauth/verify-app.js +126 -32
  29. package/lib/oauth2-apps.js +67 -13
  30. package/lib/schemas.js +60 -18
  31. package/lib/swagger-options.js +2 -3
  32. package/lib/tools.js +52 -2
  33. package/lib/ui-routes/admin-entities-routes.js +2 -2
  34. package/lib/ui-routes/auth-routes.js +4 -1
  35. package/lib/ui-routes/gmail-service-auth.js +64 -0
  36. package/lib/ui-routes/oauth-config-routes.js +22 -31
  37. package/lib/ui-routes/oauth-form-context.js +19 -0
  38. package/lib/ui-routes/suppression-list-routes.js +2 -2
  39. package/lib/utils/network.js +29 -0
  40. package/lib/webhook-request.js +12 -4
  41. package/lib/webhook-routing.js +34 -11
  42. package/package.json +11 -11
  43. package/sbom.json +1 -1
  44. package/server.js +8 -2
  45. package/static/css/flyonui.css +1 -1
  46. package/static/js/app.js +2 -1
  47. package/static/js/ui.js +6 -1
  48. package/static/licenses.html +18 -28
  49. package/translations/messages.pot +73 -73
  50. package/views/accounts/account.hbs +0 -5
  51. package/views/accounts/edit.hbs +1 -1
  52. package/views/config/imap-proxy.hbs +1 -1
  53. package/views/config/network.hbs +7 -5
  54. package/views/config/oauth/app.hbs +2 -0
  55. package/views/config/oauth/edit.hbs +0 -10
  56. package/views/config/oauth/new.hbs +0 -10
  57. package/views/config/smtp.hbs +1 -1
  58. package/views/config/tls.hbs +2 -2
  59. package/views/config/webhooks.hbs +1 -1
  60. package/views/partials/oauth_form.hbs +493 -906
  61. package/views/partials/oauth_graph_endpoints.hbs +12 -0
  62. package/views/partials/oauth_pubsub_app_select.hbs +11 -20
  63. package/views/partials/oauth_scope_presets.hbs +21 -0
  64. package/views/partials/ui/choice-tab.hbs +23 -0
  65. package/views/partials/ui/choice-tabs.hbs +32 -0
  66. package/views/partials/ui/radio.hbs +2 -2
  67. package/views/partials/ui/secret-field.hbs +2 -1
  68. package/views/partials/ui/tabs.hbs +1 -2
  69. package/workers/api.js +4 -2
  70. package/workers/webhooks.js +18 -7
@@ -0,0 +1,12 @@
1
+ {{!-- Where Microsoft Graph posts change notifications, shown by both Microsoft providers in their MS
2
+ Graph API mode. mainServiceUrl comes from the page context. --}}
3
+ <div class="space-y-2">
4
+ <p class="text-sm">Microsoft Graph posts change notifications to these two endpoints, which must accept anonymous
5
+ HTTPS <strong>POST</strong> requests from the internet:</p>
6
+ <pre class="ee-code-block"><code>{{mainServiceUrl}}/oauth/msg/lifecycle
7
+ {{mainServiceUrl}}/oauth/msg/notification</code></pre>
8
+ <span class="helper-text">If this instance cannot be reached directly, set <a href="/admin/reference/settings#postV1Settings"
9
+ target="_blank" rel="noopener noreferrer" class="link link-animated"><code>notificationBaseUrl</code></a>
10
+ to a public proxy domain, and Graph posts to <code>https://&lt;proxy-domain&gt;/oauth/msg/...</code>
11
+ instead.</span>
12
+ </div>
@@ -2,29 +2,16 @@
2
2
  interactive `gmail` block and the `gmailService` one: both reach Gmail over the HTTP API, so both want
3
3
  the same control, and the server-side `pubSubApp` field was never provider-specific.
4
4
 
5
- `data-base-scopes="api"` is what reveals it - see checkScopesRadio() at the bottom of oauth_form.hbs. --}}
5
+ It sits in the API panel of the base scope card, and checkScopesRadio() at the bottom of oauth_form.hbs
6
+ disables it while that panel is hidden, so a hidden selection is never submitted. --}}
6
7
 
7
- <div class="card-footer border-base-content/10 border-t px-6 py-4{{#unless baseScopesApi}} hidden{{/unless}}"
8
- data-base-scopes="api">
9
-
10
- <p class="mb-2">
11
- For faster webhook notifications, select a Gmail service account with the Pub/Sub Admin role.
12
- EmailEngine uses it to set up Google Cloud Pub/Sub for accounts managed by this app.
13
- </p>
14
-
15
- <p class="mb-2">
16
- <strong>Note:</strong> This is optional but recommended. With a Pub/Sub service account, EmailEngine
17
- receives changes in near real time. Without one, it falls back to polling each account about every 10
18
- minutes, so webhooks for new, updated, or deleted emails (and bounce detection) still fire, just with up
19
- to a 10-minute delay. Send-only accounts don't require this.
20
- </p>
21
-
22
- <label class="label-text" for="pubSubApp">Select service account to manage webhooks (optional). The service
23
- account must be for the same Google Cloud Project.</label>
24
- <select class="select w-full{{#if errors.pubSubApp}} is-invalid{{/if}}" id="pubSubApp"
8
+ <div>
9
+ <label class="label-text" for="pubSubApp">Pub/Sub app for real-time notifications <span
10
+ class="text-base-content/60">(optional)</span></label>
11
+ <select class="select max-w-xl{{#if errors.pubSubApp}} is-invalid{{/if}}" id="pubSubApp"
25
12
  name="pubSubApp" {{#unless baseScopesApi}}disabled{{/unless}}>
26
13
 
27
- <option value="">Select the service account for your project</option>
14
+ <option value="">No Pub/Sub app - poll for changes</option>
28
15
 
29
16
  {{!-- Nothing disables an option here: the select carries that for the whole control, and
30
17
  filterPubSubApps() in oauth_form.hbs owns the per-option state so the two cannot fight. An
@@ -40,4 +27,8 @@ the same control, and the server-side `pubSubApp` field was never provider-speci
40
27
  {{#if errors.pubSubApp}}
41
28
  <span class="helper-text text-error">{{errors.pubSubApp}}</span>
42
29
  {{/if}}
30
+ <span class="helper-text">Without one, EmailEngine polls each account about every 10 minutes, so webhooks
31
+ still fire, only later. The Pub/Sub app must belong to the same Google Cloud project. No Pub/Sub app yet?
32
+ <a href="/admin/config/oauth/new?provider=gmailService&amp;baseScopes=pubsub" target="_blank"
33
+ rel="noopener" class="link link-animated">Register one</a> in a new tab, then reload this page.</span>
43
34
  </div>
@@ -0,0 +1,21 @@
1
+ {{!-- The scope presets of an API-mode app: each button rewrites the managed entries of the custom
2
+ scope lists at the bottom of the form (updateScopesFromAccountType() in oauth_form.hbs) and leaves any
3
+ other scope there alone.
4
+ Params:
5
+ provider - "gmail" or "outlook", the preset table the buttons use (required) --}}
6
+ <div id="account-type-card-{{provider}}">
7
+ <span class="label-text block mb-2">Scope preset</span>
8
+ <div class="flex flex-wrap gap-2" role="group" aria-label="Scope preset">
9
+ <button type="button" class="btn btn-outline btn-primary btn-sm account-type-btn" data-type="normal"
10
+ data-provider="{{provider}}">Full access</button>
11
+ <button type="button" class="btn btn-outline btn-primary btn-sm account-type-btn"
12
+ data-type="readonly" data-provider="{{provider}}">Read-only</button>
13
+ <button type="button" class="btn btn-outline btn-primary btn-sm account-type-btn"
14
+ data-type="readonlysend" data-provider="{{provider}}">Read-only + send</button>
15
+ <button type="button" class="btn btn-outline btn-primary btn-sm account-type-btn"
16
+ data-type="sendonly" data-provider="{{provider}}">Send-only</button>
17
+ </div>
18
+ <span class="helper-text">Fills in the custom scopes at the bottom of the form, where the exact scopes can
19
+ be reviewed.{{#equals provider "gmail"}} Send-only needs no restricted-scope verification from Google, but
20
+ EmailEngine cannot track what such an account sends.{{/equals}}</span>
21
+ </div>
@@ -0,0 +1,23 @@
1
+ {{!--
2
+ ui/choice-tab - one option of a ui/choice-tabs strip: a radio input laid over
3
+ a tab, so the whole tab is the input's hit target and the tab looks selected
4
+ while the input is checked.
5
+ Params:
6
+ id - input id (required)
7
+ name - radio group name (required)
8
+ value - submitted value (required)
9
+ label - tab text (required)
10
+ checked - true when selected
11
+ class - extra classes on the input, e.g. a page script hook (optional)
12
+ badgeLabel - short badge after the label, e.g. "Pub/Sub only" (optional)
13
+ badgeId - id of that badge, for a script that shows or hides it (optional)
14
+ badgeHidden - true to render the badge hidden (optional)
15
+ There is no disabled state: the tab styling keys on the label, so a disabled
16
+ checked input would still look selected. Add one before a caller needs it.
17
+ --}}
18
+ <label class="tab relative gap-2 whitespace-nowrap has-checked:tab-active has-focus-visible:outline-2 has-focus-visible:outline-primary has-focus-visible:-outline-offset-2" for="{{id}}">
19
+ <input type="radio" class="absolute inset-0 m-0 cursor-pointer appearance-none opacity-0{{#if class}} {{class}}{{/if}}" id="{{id}}" name="{{name}}"
20
+ value="{{value}}" {{#if checked}}checked {{/if}}/>
21
+ {{label}}
22
+ {{#if badgeLabel}}{{> ui/badge label=badgeLabel variant="neutral" soft=true class=(concat "badge-sm" (when badgeHidden " hidden" "")) elId=badgeId icon="" title="" dataName="" dataValue=""}}{{/if}}
23
+ </label>
@@ -0,0 +1,32 @@
1
+ {{!--
2
+ ui/choice-tabs - a radio group drawn as a tab strip, for a form choice whose
3
+ options each reveal their own fields. Block form only; the block holds
4
+ ui/choice-tab items:
5
+ {{#> ui/choice-tabs label="Base scope" heading="What the app connects with" note="Fixed once the app is created"}}
6
+ {{> ui/choice-tab id="scopeImap" name="baseScopes" value="imap" label="IMAP and SMTP" checked=true}}
7
+ {{> ui/choice-tab id="scopeApi" name="baseScopes" value="api" label="Gmail API"}}
8
+ {{/ui/choice-tabs}}
9
+ Unlike ui/tabs (a FlyonUI data-tabs view switcher), the selection is a real
10
+ radio input submitted with the form, so there is no hidden field to keep in
11
+ sync, arrow keys move between options natively and a test can .check() the
12
+ input. Showing the fields of the selected option is the page's job: listen
13
+ for `change` on the radios.
14
+ Params:
15
+ label - aria-label of the group (required)
16
+ heading - visible heading above the strip (optional)
17
+ note - muted note next to the heading, e.g. a constraint (optional)
18
+ elId - element id (optional)
19
+ class - extra classes on the strip (optional)
20
+ --}}
21
+ <div>
22
+ {{#if heading}}
23
+ <div class="flex flex-wrap items-baseline gap-x-2 mb-1">
24
+ <span class="label-text">{{heading}}</span>
25
+ {{#if note}}<span class="text-xs text-base-content/60">{{note}}</span>{{/if}}
26
+ </div>
27
+ {{/if}}
28
+ <div class="tabs tabs-bordered{{#if class}} {{class}}{{/if}}" role="radiogroup" aria-label="{{label}}"{{#if elId}} id="{{elId}}"{{/if}}>
29
+ {{!-- own hash params neutralized against fallthrough into the block --}}
30
+ {{> @partial-block label="" heading="" note="" elId="" class=""}}
31
+ </div>
32
+ </div>
@@ -22,9 +22,9 @@
22
22
  --}}
23
23
  <div class="w-full">
24
24
  <div class="flex items-center gap-2">
25
- <input type="radio" class="radio radio-sm{{#if error}} is-invalid{{/if}}{{#if class}} {{class}}{{/if}}" id="{{id}}" name="{{name}}" value="{{value}}"
25
+ <input type="radio" class="peer radio radio-sm{{#if error}} is-invalid{{/if}}{{#if class}} {{class}}{{/if}}" id="{{id}}" name="{{name}}" value="{{value}}"
26
26
  {{#if checked}}checked {{else}}{{#equals selected value}}checked {{/equals}}{{/if}}{{#if disabled}}disabled {{/if}}>
27
- <label class="label-text p-0" for="{{id}}" {{#if labelTitle}}title="{{labelTitle}}" {{/if}}>{{label}}</label>
27
+ <label class="label-text p-0 peer-disabled:opacity-50 peer-disabled:cursor-not-allowed" for="{{id}}" {{#if labelTitle}}title="{{labelTitle}}" {{/if}}>{{label}}</label>
28
28
  {{#if tooltip}}
29
29
  {{!-- class="" blocks this partial's own class param (meant for the
30
30
  input) from falling through onto the tooltip wrapper --}}
@@ -19,13 +19,14 @@
19
19
  inputClass - extra classes on the input (optional)
20
20
  toggleId - reveal button id (required; used by page scripts/tests)
21
21
  toggleLabel - reveal button aria-label (default "Show password")
22
+ required - true to mark the input required (optional)
22
23
  --}}
23
24
  <div class="join w-full secret-field">
24
25
  <input type="password"
25
26
  class="input join-item grow or-else-all{{#if inputClass}} {{inputClass}}{{/if}}{{#if error}} is-invalid{{/if}}"
26
27
  id="{{id}}" data-target="secret-btns-{{id}}"
27
28
  name="{{#if name}}{{name}}{{else}}{{id}}{{/if}}" value="{{value}}"
28
- {{#if placeholder}}placeholder="{{placeholder}}" {{/if}}data-lpignore="true" autocomplete="off" />
29
+ {{#if placeholder}}placeholder="{{placeholder}}" {{/if}}{{#if required}}required {{/if}}data-lpignore="true" autocomplete="off" />
29
30
  {{!-- solid primary: matches the attached copy button in ui/copy-field --}}
30
31
  <button class="btn btn-primary join-item secret-btns-{{id}}" type="button" id="{{toggleId}}"
31
32
  data-toggle-password='{"target": "#{{id}}"}'
@@ -15,8 +15,7 @@
15
15
  app.tailwind.css, because the three hand-rolled link navs need it too.
16
16
  Panels are the caller's responsibility: each ui/tab target must match a
17
17
  tabpanel element with that id (role="tabpanel" aria-labelledby="<target>-tab").
18
- The auth-method tabs in oauth_form.hbs intentionally do NOT use this partial -
19
- they run a custom script instead of the FlyonUI data-tabs plugin.
18
+ For a form choice submitted as a radio, use ui/choice-tabs instead.
20
19
  --}}
21
20
  <nav class="tabs {{#equals variant 'segment'}}tabs-segment{{else}}tabs-bordered{{/equals}}{{#if class}} {{class}}{{/if}}" aria-label="{{label}}" role="tablist"{{#if elId}} id="{{elId}}"{{/if}} data-tabs>
22
21
  {{!-- own hash params neutralized against fallthrough into the block --}}
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();