M1 review: account rules before 2FA, the SMTP password stays with its server, the rest of the findings

M1-1 the first-user route is the plugin's own endpoint in front of Payload's; nothing is read from the path.
M1-2 the account rules are put on the collections before the 2FA package wraps them.
M1-6 the admin rule only where the roles are the plugin's; other staff collections: an account of that collection.
     update / delete get the matching defaults (accounts.adminOnlyWrite); doctor rule staff-accounts-open.
M1-5 access.firstUserAdmin: false with a role below the panel role: the default panel role steps aside, an explicit one is refused.
M1-3 a save that changes the SMTP server, port, user or encryption must send the password again (secrets.reenterOnChange);
     new panel field smtpRequireTls.
M1-4 a restore of a version masks the secrets (maskSecretsOnRestore).
M1-7 a refused origin is logged once with the ways to allow it; default ports are normalised.
Minors: m1 day boundary, m3 e-mail check on reset and bulk update, m4 text of 'all', m5 the mask is never kept.
The account suite runs with 2FA off and on.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 00:39:23 +01:00
co-authored by Claude Fable 5.2
parent 81cee02e78
commit 1141c749de
28 changed files with 1557 additions and 457 deletions
+17 -2
View File
@@ -1,7 +1,7 @@
import type { Field, GlobalConfig } from 'payload'
import { userMeetsRole } from '../../modules/access/index.js'
import { INTEGRATION_SECRET_FIELDS, writeOnlySecrets } from '../../modules/secrets/writeOnly.js'
import { INTEGRATION_SECRET_FIELDS, maskSecretsOnRestore, SMTP_PASSWORD_BOUND_TO, writeOnlySecrets } from '../../modules/secrets/writeOnly.js'
import { indexNowFields } from '../../modules/seo/indexNow.js'
import { analyticsFields } from './fields/analytics.js'
import { smtpFields } from './fields/smtp.js'
@@ -10,6 +10,12 @@ import { turnstileFields } from './fields/turnstile.js'
type BuildSiteIntegrationsArgs = {
/** Extra fields injected by the client project */
additionalFields?: Field[]
/**
* A save in the panel that changes the SMTP server, port, user name, transport or "require
* encryption" must send the password again (or remove it). Default true; needs write-only
* secrets. `false` = the stored password follows the new server, as before.
*/
reenterSecretOnChange?: boolean
/**
* The stored secrets (`smtpPassword`, `turnstileSecretKey`) are write-only: reads through
* access control get `SECRET_MASK`, never the value (modules/secrets/writeOnly.ts). Default
@@ -32,9 +38,16 @@ type BuildSiteIntegrationsArgs = {
*/
export function buildSiteIntegrations({
additionalFields,
reenterSecretOnChange = true,
writeOnlySecrets: writeOnly = true,
}: BuildSiteIntegrationsArgs = {}): GlobalConfig {
const secret = (fields: Field[]) => (writeOnly ? writeOnlySecrets(fields, INTEGRATION_SECRET_FIELDS) : fields)
const secret = (fields: Field[]) =>
writeOnly ? writeOnlySecrets(fields, INTEGRATION_SECRET_FIELDS, reenterSecretOnChange
? {
// not when the save switches to Microsoft Graph: the password is not used there, and its field is hidden
smtpPassword: { appliesWhen: (data) => data.emailTransport !== 'graph', boundTo: SMTP_PASSWORD_BOUND_TO },
}
: {}) : fields
return {
slug: 'site-integrations',
access: {
@@ -69,6 +82,8 @@ export function buildSiteIntegrations({
},
],
hooks: {
// a restore answers with the version document: the secrets are masked there too
...(writeOnly ? { afterRead: [maskSecretsOnRestore] } : {}),
beforeChange: [
// Keys edited in the panel → clear that integration's old status, so a stale
// "not working" banner doesn't linger until the next form submission.