M1 (1): stored secrets are write-only

smtpPassword and turnstileSecretKey in the Site integrations global are returned
as '********' to every read that goes through access control (REST, GraphQL, the
panel's form state); the Local API with access control off still gets the value.
A save that sends nothing, an empty value or the mask keeps the stored one;
'[[clear]]' removes it. MaskedField says that a value is set and offers to
remove it. Off: secrets: { writeOnly: false }. writeOnlySecret(s) and the hooks
are exported for a project's own fields.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 00:39:12 +01:00
co-authored by Claude Fable 5.2
parent cff355a541
commit 8fa71238ce
11 changed files with 345 additions and 35 deletions
+11 -2
View File
@@ -1,6 +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 { indexNowFields } from '../../modules/seo/indexNow.js'
import { analyticsFields } from './fields/analytics.js'
import { smtpFields } from './fields/smtp.js'
@@ -9,6 +10,12 @@ import { turnstileFields } from './fields/turnstile.js'
type BuildSiteIntegrationsArgs = {
/** Extra fields injected by the client project */
additionalFields?: Field[]
/**
* The stored secrets (`smtpPassword`, `turnstileSecretKey`) are write-only: reads through
* access control get `SECRET_MASK`, never the value (modules/secrets/writeOnly.ts). Default
* true; `false` = the value is returned to whoever may read the global, as before.
*/
writeOnlySecrets?: boolean
}
/**
@@ -25,7 +32,9 @@ type BuildSiteIntegrationsArgs = {
*/
export function buildSiteIntegrations({
additionalFields,
writeOnlySecrets: writeOnly = true,
}: BuildSiteIntegrationsArgs = {}): GlobalConfig {
const secret = (fields: Field[]) => (writeOnly ? writeOnlySecrets(fields, INTEGRATION_SECRET_FIELDS) : fields)
return {
slug: 'site-integrations',
access: {
@@ -48,10 +57,10 @@ export function buildSiteIntegrations({
en: 'Cloudflare Turnstile checks that forms are sent by people, not bots.',
pl: 'Cloudflare Turnstile sprawdza, czy formularze wysyłają ludzie, a nie boty.',
},
fields: turnstileFields,
fields: secret(turnstileFields),
label: { en: 'Spam protection', pl: 'Ochrona przed spamem' },
},
{ fields: smtpFields, label: { en: 'E-mail sending', pl: 'Wysyłka e-mail' } },
{ fields: secret(smtpFields), label: { en: 'E-mail sending', pl: 'Wysyłka e-mail' } },
{ fields: indexNowFields, label: { en: 'IndexNow', pl: 'IndexNow' } },
...(additionalFields?.length
? [{ fields: additionalFields, label: { en: 'More', pl: 'Więcej' } }]