Repository navigation
fix(access): close Payload's own payload-* collections and jobs.access to API clients - #857
Conversation
…s to API clients Payload appends payload-jobs, payload-jobs-stats, payload-locked-documents, payload-preferences, payload-migrations and payload-kv after every plugin has run, so accessPlugin never saw them, and most kept Boolean(user) access. A published client key could queue or rewrite jobs, call /api/payload-jobs/run, overwrite the job-stats global, create document locks, and PATCH another user's preference row into its own. jobs.access (run/queue/cancel) had the same default. restrictPayloadSystemEntities sets their access on the sanitized config, at both buildConfig call sites: admins only for jobs, migrations, job stats and jobs.access; active managers for locks; managers' own rows for preferences, including the /:key endpoints that skip access. An unlisted payload-* entity defaults to admins only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🚅 Deployed to the SahajCloud-pr-857 environment in sahajcloud
1 service not affected by this PR
|
|
@sydevs-bot review |
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The hole is real, the fix sits at the only point that can close it, and the spec reads rows back instead of trusting a status. The diff is the size of its problem.
Two load-bearing claims are unproven: "in-app job callers are unaffected" rests on Payload's jobs.queue default rather than a test, and "both buildConfig call sites" is already three.
Findings
- should-fix —
jobs.access.queueis admin-only now, andenqueueSubmissionScreeningqueues with a clientreq. (systemEntities.ts:52) - should-fix — a third
buildConfigcall site does not apply this. (systemEntities.ts:27) - consider —
guardEndpointsis a knob with one consumer. (systemEntities.ts:68) - consider — two
SYSTEM_COLLECTIONSentries restate the??fallback. (systemEntities.ts:109)
What was checked
buildConfig across src/ tests/ scripts/ seeds/ → three sites. The six slugs across the four sibling checkouts → generated types only. Every jobs.queue/run/cancel caller in src/ → three, none setting overrideAccess.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
|
@sydevs-bot Address review |
|
Four adversarial-review threads answered. Three adopted, one pushed back on. You own this branch, so the adopted work is #858, stacked on it. Merge that and the threads close. They stay open until then.
🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
@sydevs-bot I accept your changes, go ahead and merge all and resolve the conversations. |
|
All four adversarial-review threads are resolved. I cannot merge either PR. No loop session merges anything — Actions owns the merge gate, and both clicks are yours.
🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
#857 squash-landed as c6511bc, so this branch's copy of its commit shares no ancestry with main's and every file it added came back as an add/add. main's `systemEntities.ts` and `payload-system-access.int.spec.ts` are byte-identical to this branch's base, so taking this side loses nothing — it is that same content plus the three commits here. `docs/rules/access.md` conflicted on the one line #858 rewrites ("both call sites" to "every call site"); main's side was the pre-#858 wording. #853's edit to that file elsewhere merged clean and is kept. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01D33Z68cuaxB8VpGSwhgkjY
Only `tests/unit/manager-auth-urls.spec.ts` conflicted: this branch deletes it, and #859 rewrote its `ADMIN_ROUTE` docblock. The deletion stands — `Managers.auth.forgotPassword` is gone, so the reset URL the spec asserted can no longer be built. #859's substance is `tests/int/admin-route-config.int.spec.ts`, which reads the resolved config and merges untouched; the conflicted hunk was a pointer to that spec, not a claim this one made. Three pointers the deletion left dangling are repointed. The integration spec's docblock no longer names the deleted file, and no longer calls the reset mail an `adminUrl()` caller — `invite.ts` and `/account` are the only pair left. `src/payload.config.ts` says the same. `email-templates.spec.ts` points at `manager-invite.spec.ts` for the URL shapes it takes as inputs. `admin.routes.reset` stays pinned with no caller to spell it, since a future one would be stranded the same way. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Rytwy6uzbxca5RgKhJomx3
Problem
Payload appends
payload-jobs,payload-jobs-stats,payload-locked-documents,payload-preferences,payload-migrationsandpayload-kvinsanitizeConfig, after every plugin runs. SoaccessPluginnever sees them, and most keepBoolean(user)access. That is satisfied by any published client API key, including the Atlas widget key that ships in browsers.jobs.access.run/queue/canceldefault to the same thing.Reproduced on a throwaway test schema with a published
wemeditate-app-clientkey, throughhandleEndpoints(the real REST entry point). Before this fix the key could:payload-jobslist/read/create/updateGET /api/payload-jobs/run,/handle-schedulespayload-jobs-statsglobal read/updatepayload-locked-documentslist/create/updatePATCH /api/payload-preferences/:idon another user's rowjobs.queue/run/cancelwithoverrideAccess: falsepayload-kv/payload-migrationsNo write, run or other endpoint was called against production or any Railway environment.
Fix
restrictPayloadSystemEntities(src/plugins/access/systemEntities.ts) sets access on the sanitized config, and bothbuildConfigcall sites apply it (src/payload.config.ts,tests/utils/testHelpers.ts). It cannot run inonInit, because Payload's dev hot reload swaps in a freshly sanitized config without re-runningonInit.payload-jobs,payload-migrations,payload-jobs-stats,jobs.accesspayload-locked-documentspayload-preferences/:keyhandlers skip accesspayload-kvpayload-*In-app job callers (autoRun, the screening kick) leave
overrideAccessattrue, so they are unaffected. Nothing external calls/api/payload-jobs/run.Behaviour change: a non-admin manager can no longer read
payload-jobs(hidden in the admin panel), and can no longer overwrite another manager's preferences.Tests
tests/int/payload-system-access.int.spec.tshas 14 cases:payload-*collection's and global's access functions against a client.With the fix removed, 13 of the 14 fail. The one that still passes is the manager lock-flow guard, which should pass either way.
Local:
pnpm lint(changed files),pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(2196 passed), the new spec (14 passed).🤖 Generated with Claude Code