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
@@ -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',
|
||||
@@ -17,9 +18,9 @@ const i18n: I18nConfig = {
|
||||
const empty = (extra: Partial<Config> = {}): Config =>
|
||||
({ collections: [], secret: 'x', ...extra }) as unknown as Config
|
||||
|
||||
const admin = { id: 1, roles: ['admin'] }
|
||||
const editor = { id: 2, roles: ['editor'] }
|
||||
const user = { id: 3, roles: ['user'] }
|
||||
const admin = { id: 1, collection: 'users', roles: ['admin'] }
|
||||
const editor = { id: 2, collection: 'users', roles: ['editor'] }
|
||||
const user = { id: 3, collection: 'users', roles: ['user'] }
|
||||
|
||||
/** Runs a collection/global access function the way Payload does. */
|
||||
const run = (fn: Access | undefined, u: unknown) =>
|
||||
@@ -52,7 +53,7 @@ describe('injected auth collection', () => {
|
||||
})
|
||||
|
||||
describe('2FA wraps the auth collection people log in with', () => {
|
||||
const totp = () => vi.fn((_: unknown) => (c: Config) => c)
|
||||
const totp = () => vi.fn((o: { collection: string }) => (c: Config) => withTotpParts(c, o.collection))
|
||||
|
||||
test('defaults to access.authCollection, not a literal "users"', async () => {
|
||||
const plugin = totp()
|
||||
|
||||
Reference in New Issue
Block a user