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:
co-authored by
Claude Fable 5.2
parent
1a11cefffa
commit
edee3a321f
@@ -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).
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user