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
+10 -5
View File
@@ -91,10 +91,11 @@ describe('reading', () => {
describe('saving', () => {
test('another field alone: the secrets stay, and the answer does not carry them', async () => {
const res = await save({ smtpHost: 'smtp2.example.com' })
// (a field the SMTP password belongs to — server, port, user — asks for it again: writeOnlySecretsBound.test.ts)
const res = await save({ smtpFromName: 'The site' })
expect(res.status).toBe(200)
expect(await res.text()).not.toContain('S3CRET')
expect(await stored()).toMatchObject({ smtpHost: 'smtp2.example.com', smtpPassword: SMTP, turnstileSecretKey: TURNSTILE })
expect(await stored()).toMatchObject({ smtpFromName: 'The site', smtpPassword: SMTP, turnstileSecretKey: TURNSTILE })
})
test('what the panel sends back when nothing was typed (the mask), an empty value, null: kept', async () => {
@@ -132,9 +133,13 @@ describe('saving', () => {
test('GraphQL mutation: the mask keeps, a value replaces', async () => {
await payload.updateGlobal({ slug: 'site-integrations' as never, data: { smtpPassword: SMTP } as never })
let out = await gql(`mutation { updateSiteIntegration(data: { smtpPassword: "${SECRET_MASK}", smtpUser: "mailer2" }) { smtpPassword smtpUser } }`)
let out = await gql(`mutation { updateSiteIntegration(data: { smtpPassword: "${SECRET_MASK}", smtpFromName: "By GraphQL" }) { smtpPassword smtpFromName } }`)
expect(out.errors).toBeUndefined()
expect(out.data?.updateSiteIntegration).toMatchObject({ smtpPassword: SECRET_MASK, smtpUser: 'mailer2' })
expect(out.data?.updateSiteIntegration).toMatchObject({ smtpFromName: 'By GraphQL', smtpPassword: SECRET_MASK })
// a field the password belongs to, without the password: refused here as over REST
const moved = await gql(`mutation { updateSiteIntegration(data: { smtpPassword: "${SECRET_MASK}", smtpHost: "other.example.com" }) { smtpHost } }`)
expect(moved.errors?.length).toBeGreaterThan(0)
expect((await stored()).smtpHost).not.toBe('other.example.com')
expect((await stored()).smtpPassword).toBe(SMTP)
out = await gql('mutation { updateSiteIntegration(data: { smtpPassword: "S3CRET-by-graphql" }) { smtpPassword } }')
expect(JSON.stringify(out)).not.toContain('S3CRET')
@@ -155,7 +160,7 @@ describe('the building blocks', () => {
for (const nothing of [undefined, null, '', SECRET_MASK]) {expect(write(nothing, { token: 'old' })).toBe('old')}
expect(write(SECRET_CLEAR, { token: 'old' })).toBeNull()
expect(write(SECRET_MASK, undefined)).toBeNull() // nothing stored: never the mask itself
expect(write(SECRET_MASK, { token: SECRET_MASK })).toBe(SECRET_MASK) // (a stored mask is left; it cannot get there through these hooks)
expect(write(SECRET_MASK, { token: SECRET_MASK })).toBeNull() // a stored mask is not a secret: never written back
expect(write('', { group: { items: [{ token: 'deep' }] } }, ['group', 'items', 0, 'token'])).toBe('deep')
})