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
@@ -219,3 +219,34 @@ test('admin: sign in through 2FA, agency credit, panel link preview', async ({ p
|
||||
await expect(page).toHaveTitle(/Dashboard|Pulpit/, { timeout: 20_000 })
|
||||
await expect(page.getByText(/Intecion/).first()).toBeVisible()
|
||||
})
|
||||
|
||||
// 2FA covers what the plugin adds, over the API too (REST and GraphQL): a correct password without the code
|
||||
// from the authenticator app opens neither the settings nor visitors' data; the code does.
|
||||
test('API: a staff password without the 2FA code opens nothing; with the code it does', async ({ playwright, baseURL }) => {
|
||||
const { E2E_ADMIN_EMAIL: email, E2E_ADMIN_PASSWORD: password, E2E_TOTP_SECRET: secret } = process.env
|
||||
test.skip(!email || !password || !secret, 'E2E_* test admin not configured')
|
||||
const api = await playwright.request.newContext({ baseURL }) // its own cookie jar
|
||||
const login = await api.post('/api/users/login', { data: { email, password } })
|
||||
expect(login.status()).toBe(200)
|
||||
|
||||
const guarded = ['/api/globals/site-integrations', '/api/form-submissions', '/api/consent-records', '/api/users', '/api/globals/site-settings', '/api/forms']
|
||||
for (const path of guarded) {
|
||||
const res = await api.get(path)
|
||||
expect(res.status(), `${path} without the code`).toBe(403)
|
||||
expect(await res.text()).not.toContain('e2e-sink') // the SMTP password create-test-admin.ts stored
|
||||
}
|
||||
expect((await api.post('/api/globals/site-settings', { data: {} })).status()).toBe(403)
|
||||
expect((await api.post('/api/ipal/test-email', { data: { to: '[email protected]' } })).status()).toBe(403)
|
||||
const query = '{ SiteIntegration { smtpPassword } FormSubmissions { totalDocs } }'
|
||||
const before = await (await api.post('/api/graphql', { data: { query } })).json()
|
||||
expect(before.errors?.length).toBeGreaterThan(0)
|
||||
expect(JSON.stringify(before)).not.toContain('e2e-sink')
|
||||
|
||||
const verify = await api.post('/api/verify-totp', { data: { token: totp(secret!) } })
|
||||
expect((await verify.json()).ok).toBe(true)
|
||||
for (const path of guarded) {expect((await api.get(path)).status(), `${path} with the code`).toBe(200)}
|
||||
const after = await (await api.post('/api/graphql', { data: { query } })).json()
|
||||
expect(after.errors).toBeUndefined()
|
||||
expect(after.data.SiteIntegration.smtpPassword).toBe('e2e-sink')
|
||||
await api.dispose()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user