2FA: the first set-up is confirmed by e-mail (twoFactor.confirmByEmail, 1.18.0)
Security audit 2026-12, F0: inside an account's setup window its password alone enrolled an authenticator of the caller's choosing; the owner was locked out. - /setup-totp for an account without a factor: IAPL checks the code, keeps the secret pending (payload-kv), mails a single-use 30-min link to the account and ties it to the enrolling browser; the package's handler (and its -totp cookie) is never used for a first enrolment - GET /api/iapl/two-factor/confirm = a page with one button; POST confirms (own origin, same browser), ends the account's sessions, signs nobody in - notice mails on every enrolment, change, removal / reset (any path) - mail not working: link to the server log, admin confirms on the account page (POST /api/iapl/two-factor/confirm-pending), doctor rule 2fa-enrolment-mail - options and opt-out (confirmByEmail: false), building blocks exported - tests: HTTP suite on SQLite, MongoDB, Postgres; built-site spec in e2e:built; closed doors and judged routes; docs, AGENT.md, skills, changelog Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
84717804ae
commit
c9d1f4b340
@@ -53,6 +53,7 @@ import { serverText } from './modules/integrations/texts.js'
|
||||
import { buildSystemPagesFields } from './modules/pages/index.js'
|
||||
import { guardAdminEndpoints } from './modules/security/adminSameOrigin.js'
|
||||
import { jobsRunNotice, withJobsRunAccess } from './modules/security/jobsAccess.js'
|
||||
import { buildEnrolmentEndpoints, buildTotpNoticeHooks, resolveConfirmByEmail, startEnrolment } from './modules/security/totp/enrolmentConfirm.js'
|
||||
import { missingImportMapEntries } from './modules/security/totp/importMapCheck.js'
|
||||
import { changedViewKeys, copyViews, SAFE_TOTP_VIEW, wrapTotpViews } from './modules/security/totp/safeBack.js'
|
||||
import { reportRefusedOrigin, requestFromOwnOrigin } from './modules/security/totp/sameOrigin.js'
|
||||
@@ -342,6 +343,8 @@ export const iapl = (options: IaplOptions): Plugin => {
|
||||
// whatever the package registered, also paths a later version adds.
|
||||
const limitVerify = tf.verifyLimit === false ? undefined : buildVerifyLimit(target, { ...tf.verifyLimit, keyPrefix: (typeof tf.verifyLimit?.keyPrefix === 'string' && tf.verifyLimit.keyPrefix.trim()) || (options.storageNames === 'iapl' ? 'iapl' : 'ipal') })
|
||||
const extraOrigins = typeof tf.sameOrigin === 'object' ? (tf.sameOrigin.origins ?? []) : []
|
||||
// First enrolment confirmed by e-mail (on by default, 1.18.0): checked at start like every other switch.
|
||||
const confirmByEmail = resolveConfirmByEmail(tf.confirmByEmail)
|
||||
const guards = {
|
||||
...(limitVerify ? { limitVerify: (req: PayloadRequest) => limitVerify(req), settleVerify: (req: PayloadRequest, correct: boolean) => limitVerify.settle(req, correct) } : {}),
|
||||
...(tf.sameOrigin === false
|
||||
@@ -353,10 +356,21 @@ export const iapl = (options: IaplOptions): Plugin => {
|
||||
return false
|
||||
},
|
||||
}),
|
||||
...(confirmByEmail ? { enrol: (req: PayloadRequest) => startEnrolment(req, { collection: target, options: confirmByEmail }) } : {}),
|
||||
onSetupClosed: (req: PayloadRequest) =>
|
||||
Response.json({ message: serverText(req.i18n as never, 'twoFactorSetupClosed'), ok: false }, { status: 403 }),
|
||||
}
|
||||
config.endpoints = (config.endpoints ?? []).map((e) => (endpointsBefore.has(e) ? e : guardTotpEndpoint(e, target, guards as never)))
|
||||
if (confirmByEmail) {
|
||||
// the link's page and button, and the administrator's confirm of a waiting set-up
|
||||
config.endpoints = [...config.endpoints, ...buildEnrolmentEndpoints({ collection: target, options: confirmByEmail, ...(guards.ownOrigin ? { ownOrigin: guards.ownOrigin } : {}), ...(tf.resetAccess ? { resetAccess: tf.resetAccess } : {}) })]
|
||||
// a notice mail on every enrolment, change and removal / reset, whatever path wrote it
|
||||
const notice = buildTotpNoticeHooks(target, confirmByEmail)
|
||||
config.collections = (config.collections ?? []).map((c) =>
|
||||
c.slug === target ? { ...c, hooks: { ...c.hooks, afterChange: [...(c.hooks?.afterChange ?? []), notice.afterChange], beforeChange: [...(c.hooks?.beforeChange ?? []), notice.beforeChange] } } : c,
|
||||
)
|
||||
}
|
||||
config.custom = { ...config.custom, iapl: { ...(config.custom as { iapl?: object } | undefined)?.iapl, twoFactorConfirmByEmail: confirmByEmail ? { adminConfirm: confirmByEmail.adminConfirm } : false } }
|
||||
// …and the same for endpoints it may put on a collection or a global.
|
||||
config.collections = guardNewEntityEndpoints(config.collections, entityEndpointsBefore, target, guards as never)
|
||||
config.globals = guardNewEntityEndpoints(config.globals, entityEndpointsBefore, target, guards as never)
|
||||
|
||||
Reference in New Issue
Block a user