Security: staff checks only for staff collections; 2FA covers what the plugin adds
Staff check (userMeetsRole): the 'no roles field = every account passes' rule applied to the account's own collection, so an account of a second auth collection (customers) passed every staff check. It now applies only to staff collections: the panel's login collection plus the new access.staffCollections. The injected auth collection uses the new adminOrSelfIn(slug), so an account of another collection with the same numeric id is not 'self'. 2FA: @clocklimited/payload-2fa wraps the collections and globals present when it runs; ipalKit's own globals and collections were added later and stayed unwrapped, so a password without the TOTP code opened them over REST and GraphQL. ipal-kit now has its own second-factor check (secondFactorPassed / requireSecondFactor): applied to every collection and global at the end of ipalKit, again in onInit for entities added by plugins listed after it, and inside userMeetsRole and the endpoints that take a project access function. It fails closed: an unrecognised user shape is refused, and startup stops when the injected 2FA plugin lacks the parts the check reads (twoFactor.guard: false opts out). Tests through real HTTP requests (REST and GraphQL) against Payload's route handlers, plus the reference smoke test. Docs, agent guide, skills and the reference skills copy updated; changelog entry without a version. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
bc1045a5b7
commit
0c61ac231b
+4
-2
@@ -5,6 +5,7 @@ import { describe, expect, test, vi } from 'vitest'
|
||||
import type { I18nConfig } from '../src/modules/i18n/types.js'
|
||||
|
||||
import { ipalKit } from '../src/plugin.js'
|
||||
import { withTotpParts } from './helpers.js'
|
||||
|
||||
const i18n: I18nConfig = {
|
||||
defaultLocale: 'pl',
|
||||
@@ -40,7 +41,7 @@ describe('ipalKit — config transform', () => {
|
||||
/no 2FA plugin was injected/,
|
||||
)
|
||||
|
||||
const totp = vi.fn(() => (c: Config) => c)
|
||||
const totp = vi.fn((o: { collection: string }) => (c: Config) => withTotpParts(c, o.collection))
|
||||
await ipalKit({ i18n, twoFactor: { issuer: 'Acme', plugin: totp as never } })(base())
|
||||
expect(totp).toHaveBeenCalledWith(expect.objectContaining({ forceSetup: true, totp: { issuer: 'Acme' } }))
|
||||
})
|
||||
@@ -119,7 +120,8 @@ describe('options that keep features reachable and overridable', () => {
|
||||
test('without `access` (no roles field) admin and editor features stay reachable for logged-in users', async () => {
|
||||
const config = await ipalKit({ consentLog: true, forms: {}, i18n, stats: true, twoFactor: false })(base())
|
||||
const users = config.collections!.find((c) => c.slug === 'users')!
|
||||
const req = (user: unknown) => ({ payload: { collections: { users: { config: users } } }, user }) as never
|
||||
// `admin.user` is what Payload's sanitize fills in: the panel's login collection = the staff collection.
|
||||
const req = (user: unknown) => ({ payload: { collections: { users: { config: users } }, config: { admin: { user: 'users' } } }, user }) as never
|
||||
const member = { id: 1, collection: 'users', email: '[email protected]' }
|
||||
const run = (access: unknown, user: unknown) => (access as (a: { req: unknown }) => unknown)({ req: req(user) })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user