Mail relay: the access-key field is off by default (mail.relay.accessKeyField)

A token issued by hand is set by a developer: setRelayToken() from a script, or mail.relay.token.
The panel field and its route take a token only when the project switches the field on. Docs and
AGENT.md say when such a token is needed and how to set it; a token of another host is refused on
every way in.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 22:25:34 +01:00
co-authored by Claude Fable 5.2
parent 1a11cefffa
commit edee3a321f
11 changed files with 87 additions and 21 deletions
@@ -8,6 +8,7 @@ import { RELAY_CONNECT_PATH, RELAY_DISCONNECT_PATH, RELAY_STATUS_PATH } from '..
type Window = { limit: number; remaining: number }
type State = {
accessKeyField?: boolean
error?: string
message?: string
ok?: boolean
@@ -37,7 +38,8 @@ const warn = { ...line, color: 'var(--theme-warning-600, #b45309)' } as const
* in effect (the Intecion mail service, the site's SMTP server, Microsoft Graph), and for the mail
* service: the state, the address mail leaves from, where replies go, what is left of the limits, and
* a sender name the service did not accept. "Check now" asks the service; "Connect again" and
* "Disconnect" act on the site's connection. No token is ever shown or sent to this component.
* "Disconnect" act on the site's connection; "Enter an access key" is there only with
* `mail.relay.accessKeyField: true`. No token is ever shown or sent to this component.
*
* Rendered by IntegrationStatusBanner on the e-mail tab (`mailRelay` prop) — it has no import-map entry of its
* own; a project's own panel can import it from `/admin`. Texts: `mailRelay*` keys.
@@ -133,12 +135,14 @@ export const MailRelayStatus = () => {
{text('mailRelayDisconnect')}
</button>
) : null}
<button className="btn btn--style-none btn--size-small" onClick={() => setShowToken((v) => !v)} style={{ margin: 0, textDecoration: 'underline' }} type="button">
{text('mailRelayToken')}
</button>
{state.accessKeyField ? (
<button className="btn btn--style-none btn--size-small" onClick={() => setShowToken((v) => !v)} style={{ margin: 0, textDecoration: 'underline' }} type="button">
{text('mailRelayToken')}
</button>
) : null}
</div>
)}
{showToken ? (
{showToken && state.accessKeyField ? (
<div style={{ marginTop: '.75rem' }}>
<p style={{ fontSize: '.85rem', margin: 0, opacity: 0.75 }}>{text('mailRelayTokenHint')}</p>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '.5rem', marginTop: '.35rem' }}>
+7
View File
@@ -9,6 +9,13 @@ import { RELAY_BASE_URL } from './constants.js'
* switches the transport, the enrolment and the confirm route off.
*/
export type RelayOptions = {
/**
* Show "Enter an access key" in the panel's state block, and let its route store a token an admin pastes.
* Default `false`: a token issued by hand (for a site the service cannot call back) is set by a developer —
* `setRelayToken(payload, token)` in a script, or `token` below. `true` gives admins the field. Either way a
* token of another site is refused.
*/
accessKeyField?: boolean
/**
* "Forgot password" is a visitor's lever like a form: the service lets `account` mail use the site's
* whole hour. So the plugin limits it itself, per address and per visitor (the request's address).
+7 -1
View File
@@ -24,6 +24,8 @@ type Settings = {
/** What the state block on the e-mail tab shows. Never a token, never a password. */
export type MailPanelState = {
/** `mail.relay.accessKeyField`: the panel shows "Enter an access key". Off by default. */
accessKeyField?: boolean
/** The address the service calls this site back at. */
confirmUrl?: string
/** Enabled in the project (`mail.relay` is not `false`). */
@@ -60,6 +62,7 @@ export async function mailPanelState(req: Pick<PayloadRequest, 'payload'>, own:
}
const api = payload.config.routes?.api ?? '/api'
return {
...(options?.accessKeyField === true ? { accessKeyField: true } : {}),
...(status?.host ? { confirmUrl: `https://${status.host}${api}${RELAY_CONFIRM_PATH}` } : {}),
relay: status ? { ...status, senderAddress: status.senderAddress ?? RELAY_SENDER_ADDRESS } : null,
replyAddress: typeof settings.smtpFromAddress === 'string' && settings.smtpFromAddress.trim() ? settings.smtpFromAddress.trim() : null,
@@ -104,7 +107,8 @@ async function answer(req: PayloadRequest, own: false | RelayOptions | undefined
/**
* The three admin-only routes behind the state block on Site integrations → E-mail sending:
* GET /api/iapl/mail-relay/status the transport in effect and the site's state (`?refresh=1` asks the service)
* POST /api/iapl/mail-relay/connect enrol now — or, with `{ token }`, store a token Intecion issued by hand
* POST /api/iapl/mail-relay/connect enrol now — or, with `{ token }` and `mail.relay.accessKeyField: true`,
* store a token Intecion issued by hand (refused otherwise)
* POST /api/iapl/mail-relay/disconnect give the token up; nothing is sent through the service until "Connect again"
* None of them ever answers with a token.
*/
@@ -133,6 +137,8 @@ export function relayPanelEndpoints(own?: false | RelayOptions): Endpoint[] {
/* no body: plain "connect again" */
}
if (typeof body.token === 'string' && body.token.trim()) {
// the field is off unless the project switched it on: a token is then set in code or by a script only
if (options.accessKeyField !== true) {return json({ error: serverText(i18n, 'mailRelayForbidden'), ok: false }, 403)}
const pasted = body.token.trim()
if (!/^ims_[\w-]{43}$/.test(pasted)) {return json({ error: serverText(i18n, 'mailRelayTokenInvalid'), ok: false }, 400)}
// Ask the service whose token this is BEFORE it replaces anything: a token of another site, or one the