2FA setup required: review fixes (SR-1 to SR-9)
SR-1: /api/ipal/admin-icon sends the upload security headers (sandbox policy, nosniff) with the bytes: an SVG is shown, never run. fetchPublicImage stops reading at the size limit. SR-2: requireSetup.exempt exempts only on exactly true; an async function, and a windowHours that is not a number or false, stop the start. SR-3: on Postgres / SQLite the missing column makes every login fail: the log says so, the docs call the migration a required step of the same deploy, and ipal-doctor reports a SQL project without it. SR-4: an admin's reset also ends the account's sessions. SR-5: the reset needs a session that entered its own TOTP code by default. SR-6: the doctor's import-map rule covers TwoFactorStatusField and TwoFactorAlert. SR-7: building blocks exported; dashboard notice, status field, setup notice and the server-side image fetch can be switched off one by one. SR-8: totpSetupFrom is on the 2FA collection whenever 2FA is on. SR-9: both ways out of "every administrator is blocked" in security.md. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
9d2ab43438
commit
75a6f5209e
@@ -198,6 +198,13 @@ export const layoutRules: DoctorRule[] = [
|
||||
if (/payloadTotp/.test(cfg)) {
|
||||
need.push('@clocklimited/payload-2fa/rsc#TOTPSetup')
|
||||
if (!lt(v, '1.14.2')) {need.push('@intecion/ipal-kit/admin#TotpRedirectProvider')}
|
||||
// "2FA setup required": the status / reset control on the account and the dashboard notice — when the
|
||||
// installed plugin has them and the config does not switch them (or the mode) off. Without them the
|
||||
// panel shows no "Reopen setup": the documented way out of a blocked account is missing.
|
||||
const adminExports = ctx.read('node_modules/@intecion/ipal-kit/dist/exports/admin.js')
|
||||
const modeOff = /requireSetup\s*:\s*false|guard\s*:\s*false/.test(cfg)
|
||||
if (/\bTwoFactorStatusField\b/.test(adminExports) && !modeOff && !/statusField\s*:\s*false/.test(cfg)) {need.push('@intecion/ipal-kit/admin#TwoFactorStatusField')}
|
||||
if (/\bTwoFactorAlert\b/.test(adminExports) && !modeOff && !/dashboardNotice\s*:\s*false/.test(cfg)) {need.push('@intecion/ipal-kit/admin#TwoFactorAlert')}
|
||||
// the back-link check in front of the 2FA screens (twoFactor.safeBack) — when the installed plugin has it
|
||||
if (/\bSafeTotpView\b/.test(ctx.read('node_modules/@intecion/ipal-kit/dist/exports/admin.js')) && !/safeBack\s*:\s*false/.test(cfg)) {
|
||||
need.push('@intecion/ipal-kit/admin#SafeTotpView')
|
||||
|
||||
@@ -108,6 +108,23 @@ export const securityRules: DoctorRule[] = [
|
||||
else if (!ctx.installed('@clocklimited/payload-2fa')) {out.push({ fix: 'pnpm add @clocklimited/payload-2fa', message: '@clocklimited/payload-2fa is not installed', severity: 'error' })}
|
||||
if (/requireSetup\s*:\s*false/.test(code)) {out.push({ file: configFile(ctx) ?? undefined, fix: 'remove twoFactor.requireSetup: false (or record the reason in ipal-doctor.json)', message: 'twoFactor.requireSetup is off: an account that has not set 2FA up opens everything with its password alone', severity: 'warning' })}
|
||||
if (/windowHours\s*:\s*(?:false|0)\b/.test(code)) {out.push({ file: configFile(ctx) ?? undefined, fix: 'twoFactor.requireSetup.windowHours: 72 (the default)', message: 'no time limit for 2FA setup: an account that never sets it up can be taken over with its password at any time', severity: 'info' })}
|
||||
// Postgres / SQLite: the 2FA collection has the column `totp_setup_from` (whenever 2FA is on). Without a
|
||||
// migration that adds it, every query on the collection fails in production — nobody can log in.
|
||||
const sqlAdapter = ['@payloadcms/db-postgres', '@payloadcms/db-vercel-postgres', '@payloadcms/db-sqlite', '@payloadcms/db-d1-sqlite'].some((name) => ctx.installed(name))
|
||||
const pluginHasColumn = /totpSetupFrom/.test(ctx.read('node_modules/@intecion/ipal-kit/dist/modules/security/totp/secondFactor.js'))
|
||||
if (sqlAdapter && pluginHasColumn && /payloadTotp/.test(code)) {
|
||||
const dirs = [`${ctx.src}migrations`, 'migrations'].filter((dir) => ctx.exists(dir))
|
||||
const files = dirs.flatMap((dir) => ctx.list(dir).filter((name) => /\.(?:ts|js|mjs|sql|json)$/.test(name)).map((name) => `${dir}/${name}`))
|
||||
if (!files.some((file) => /totp_setup_from|totpSetupFrom/.test(ctx.read(file)))) {
|
||||
out.push({
|
||||
fix: 'pnpm payload migrate:create, commit the migration, and run it (pnpm payload migrate) in the same deploy, before the new version serves requests',
|
||||
message: files.length
|
||||
? 'no migration adds the 2FA column `totp_setup_from`: in production every login would answer 500 — nobody could sign in to the panel'
|
||||
: 'a SQL database and no migrations folder: the 2FA column `totp_setup_from` must exist before this version runs in production (migrate:create), or nobody can sign in',
|
||||
severity: files.length ? 'error' : 'warning',
|
||||
})
|
||||
}
|
||||
}
|
||||
if (ctx.deep?.usersWithout2fa) {
|
||||
const closed = ctx.deep.usersSetupClosed ?? 0
|
||||
out.push({
|
||||
|
||||
Reference in New Issue
Block a user