Files
Radosław SmolińskiandClaude Fable 5.2 c56f0d41b8 Security review round 2: no exception by name, staff list fails closed, verify limit
R2-1: the sweep skipped every collection whose slug starts with payload-,
so a plugin's payload-... collection added after ipalKit was never guarded.
There is no exception by name or prefix now: every collection and global
is guarded, Payload's own included, and the job queue's run / queue /
cancel rules too.

R2-2: role predicates called without a source fail closed where the staff
collections are not known (browser bundle, middleware, edge): nobody is
staff. They accept req.payload, a config (also the client config) or
{ staffCollections } as the source.

R2-3: the staff list is filed per config / Payload instance; a call without
a source gets only what every config in the process calls staff.

R2-4: payload.config is watched on the instance, so a config swapped in by
a dev reload is guarded before any request or Local API call.

R2-5: verify attempts are limited per account (default 5 in 10 minutes,
twoFactor.verifyLimit), counted in memory, never skipped.

R2-6: a user object without collection owes the second factor; endpoints
the 2FA package may add on collections or globals are guarded too; a
warning names staff collections that 2FA does not cover; docs state what
is not covered, fix the one-argument examples and the doctor example.

HTTP tests for each on payload-2fa beta.7, run on SQLite, Postgres and
MongoDB (test adapter added).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-24 01:46:25 +01:00

26 lines
1.6 KiB
TypeScript

import { mongooseAdapter } from '@payloadcms/db-mongodb'
import { postgresAdapter } from '@payloadcms/db-postgres'
import { sqliteAdapter } from '@payloadcms/db-sqlite'
/**
* The database of the HTTP security tests. SQLite in memory by default; `IPAL_TEST_POSTGRES_URI` points them at a
* real Postgres (numeric ids, like SQLite — the adapters where an id of one auth collection can equal an id of
* another):
* docker run -d --rm -p 127.0.0.1:55432:5432 -e POSTGRES_PASSWORD=test postgres:17
* IPAL_TEST_POSTGRES_URI=postgres://postgres:[email protected]:55432/postgres pnpm vitest run test/securityHttp.test.ts
* `IPAL_TEST_MONGO_URI` points them at MongoDB (what the client sites run):
* docker run -d --rm -p 127.0.0.1:27217:27017 mongo:7
* IPAL_TEST_MONGO_URI=mongodb://127.0.0.1:27217 pnpm vitest run test/securityHttp.test.ts
* Each test file gets its own schema / database (`name`), so the files can run one after another against one server.
*/
/** True on the adapters where ids are numbers counted per collection (an id can repeat across collections). */
export const numericIds = () => !process.env.IPAL_TEST_MONGO_URI
export function testDatabase(name: string) {
const mongo = process.env.IPAL_TEST_MONGO_URI
if (mongo) {return mongooseAdapter({ url: `${mongo.replace(/\/$/, '')}/${name}_${Date.now()}` })}
const uri = process.env.IPAL_TEST_POSTGRES_URI
if (uri) {return postgresAdapter({ pool: { connectionString: uri }, push: true, schemaName: `${name}_${Date.now()}` })}
return sqliteAdapter({ client: { url: 'file::memory:' }, push: true })
}