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
+16
-2
@@ -320,10 +320,12 @@ describe('requireSetup x safeBack x guard', () => {
|
||||
const wrapped = totpViews.filter((v) => typeof v.Component === 'object' && v.Component.path === '@intecion/ipal-kit/admin#SafeTotpView').length
|
||||
expect(wrapped).toBe(options.safeBack === false ? 0 : 4)
|
||||
|
||||
// setup required needs ipal-kit's own check; with either off there is no window field and no notice
|
||||
// setup required needs ipal-kit's own check; with either off there is no status field, hook or notice
|
||||
const setupOn = options.requireSetup !== false && options.guard !== false
|
||||
const users = config.collections?.find((c) => c.slug === 'users')
|
||||
expect(Boolean(users?.fields.some((f) => 'name' in f && f.name === 'totpSetupFrom'))).toBe(setupOn)
|
||||
// the data field whenever 2FA is on (the schema does not follow the switches); the panel's status field with the mode
|
||||
expect(Boolean(users?.fields.some((f) => 'name' in f && f.name === 'totpSetupFrom'))).toBe(true)
|
||||
expect(Boolean(users?.fields.some((f) => 'name' in f && f.name === 'totpSetupStatus'))).toBe(setupOn)
|
||||
// the administrator's reset (a lost phone) comes with ipal-kit's own check, also when setup is not required
|
||||
expect(Boolean(config.endpoints?.some((e) => e.path === '/ipal/two-factor/reset'))).toBe(options.guard !== false)
|
||||
const provider = JSON.stringify(config.admin?.components?.providers ?? [])
|
||||
@@ -335,6 +337,18 @@ describe('requireSetup x safeBack x guard', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('requireSetup.setupNotice', () => {
|
||||
const providers = async (requireSetup?: Record<string, unknown>) =>
|
||||
JSON.stringify((await ipalKit({ access: { authCollection: 'users' }, i18n, twoFactor: { issuer: 'E', plugin: payloadTotpBeta7, requireSetup } as never })({ collections: [], secret: 'x' } as unknown as Config)).admin?.components?.providers ?? [])
|
||||
|
||||
test('on by default; false removes the notice, not the lock', async () => {
|
||||
expect(await providers()).toContain('"requireSetup":true')
|
||||
expect(await providers({ setupNotice: false })).not.toContain('"requireSetup":true')
|
||||
const config = await ipalKit({ access: { authCollection: 'users' }, i18n, twoFactor: { issuer: 'E', plugin: payloadTotpBeta7, requireSetup: { setupNotice: false } } as never })({ collections: [], secret: 'x' } as unknown as Config)
|
||||
expect((config.custom as { ipal: { twoFactor: { requireSetup: boolean } } }).ipal.twoFactor.requireSetup).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('a 2FA factory that hands back the same view objects on every call', () => {
|
||||
const views = {
|
||||
SetupTOTP: { Component: { path: 'pkg/rsc#TOTPSetup' }, path: 'setup-totp' },
|
||||
|
||||
Reference in New Issue
Block a user