Review round 3: job-queue rules keep Payload's own defaults; a failed 2FA lookup fails closed
Job queue (R3-1): only a rule that exists is wrapped. At config time that is what the project wrote; Payload fills in the rest when it builds the config (3.94.1: run, queue and cancel are all defaultAccess, a logged-in user) and the sweep of the running config wraps those. No default is invented, so a request without a user gets what Payload itself answers. hasTotp false while the account's record carries a TOTP secret (the 2FA package's own lookup failed, R3-4): the account owes its code, not 'not set up yet'. Docs: the two-configs-in-one-process case for calls without a source, and that a half-logged-in editor's browser is refused media files. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
c56f0d41b8
commit
dc5326ea1c
@@ -69,7 +69,10 @@ export function secondFactorPassed({ payload, user }: MaybeReq): boolean {
|
||||
if (typeof u.collection !== 'string') {return false}
|
||||
if (u.collection !== guard.collection) {return true}
|
||||
if (u._strategy === 'totp' || u._strategy === 'api-key') {return true}
|
||||
return u.hasTotp === false
|
||||
// "Not set up yet" only when nothing says otherwise. The package computes `hasTotp` with a second
|
||||
// database read and answers false when that read fails; the secret on the user object itself (it
|
||||
// came with the account's own record) then still says the account has TOTP: refused.
|
||||
return u.hasTotp === false && !(user as { totpSecret?: unknown }).totpSecret
|
||||
}
|
||||
|
||||
const GUARDED = Symbol.for('ipal.secondFactorGuard')
|
||||
@@ -156,18 +159,26 @@ function guardEntity<T extends GuardedEntity>(entity: T, operations: readonly st
|
||||
return { ...entity, access }
|
||||
}
|
||||
|
||||
/**
|
||||
* The job queue has its own rules outside any collection: `jobs.access.run / queue / cancel`
|
||||
* (POST /api/payload-jobs/run, `payload.jobs.queue()` / `.cancel()` with `overrideAccess: false`).
|
||||
*
|
||||
* Payload's defaults are kept exactly, by not inventing any: only a rule that EXISTS is wrapped
|
||||
* ("…and not while the second factor is owed"). At config time that is what the project wrote;
|
||||
* when Payload builds the config it fills the rest in itself (3.94.1, config/defaults.js: `run`,
|
||||
* `queue` and `cancel` are all `defaultAccess`, a logged-in user — the `?? (() => true)` in
|
||||
* queues/localAPI.js is never reached on a built config), and the sweep of the running config
|
||||
* wraps those. So a request without a user gets whatever Payload itself answers.
|
||||
*/
|
||||
const JOB_OPERATIONS = ['cancel', 'queue', 'run'] as const
|
||||
type JobsLike = { access?: AccessMap } | undefined
|
||||
|
||||
/**
|
||||
* The job queue has its own rules outside any collection (`jobs.access.run / queue / cancel`,
|
||||
* by default "logged in"): POST /api/payload-jobs/run and the Local API's queue. Guarded like
|
||||
* an entity, only when the project configured `jobs` at all.
|
||||
*/
|
||||
function guardJobs<T extends JobsLike>(jobs: T): T {
|
||||
if (!jobs) {return jobs}
|
||||
if (!jobs?.access) {return jobs}
|
||||
const access: AccessMap = { ...jobs.access }
|
||||
for (const op of JOB_OPERATIONS) {access[op] = requireSecondFactor(access[op])}
|
||||
for (const op of JOB_OPERATIONS) {
|
||||
if (access[op]) {access[op] = requireSecondFactor(access[op])}
|
||||
}
|
||||
return { ...jobs, access }
|
||||
}
|
||||
|
||||
@@ -210,7 +221,7 @@ export function guardPayloadAccess(payload: Pick<BasePayload, 'config'>): string
|
||||
for (const c of payload.config.collections ?? []) {sweep(c as GuardedEntity, COLLECTION_OPERATIONS)}
|
||||
for (const g of payload.config.globals ?? []) {sweep(g as GuardedEntity, GLOBAL_OPERATIONS)}
|
||||
const jobs = (payload.config as { jobs?: JobsLike }).jobs
|
||||
if (jobs && JOB_OPERATIONS.some((op) => !(jobs.access?.[op] as Guarded | undefined)?.[GUARDED])) {
|
||||
if (jobs?.access && JOB_OPERATIONS.some((op) => jobs.access?.[op] && !(jobs.access[op] as Guarded)[GUARDED])) {
|
||||
jobs.access = guardJobs(jobs).access
|
||||
late.push('jobs')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user