Skip to content

fix(access): close Payload's own payload-* collections and jobs.access to API clients - #857

Merged
Ardnived merged 1 commit into
mainfrom
fix/payload-system-entities-access
Sep 29, 2026
Merged

Ardnived merged 1 commit into
mainfrom
fix/payload-system-entities-access

Conversation

@antontcymbal

Copy link
Copy Markdown
Contributor

Problem

Payload appends payload-jobs, payload-jobs-stats, payload-locked-documents, payload-preferences, payload-migrations and payload-kv in sanitizeConfig, after every plugin runs. So accessPlugin never sees them, and most keep Boolean(user) access. That is satisfied by any published client API key, including the Atlas widget key that ships in browsers. jobs.access.run/queue/cancel default to the same thing.

Reproduced on a throwaway test schema with a published wemeditate-app-client key, through handleEndpoints (the real REST entry point). Before this fix the key could:

Surface Result
payload-jobs list/read/create/update 200 / 201. A client could queue any task with any input, or rewrite a queued job's input
GET /api/payload-jobs/run, /handle-schedules 200
payload-jobs-stats global read/update 200
payload-locked-documents list/create/update 200 / 201
PATCH /api/payload-preferences/:id on another user's row 200, and the row was reassigned to the client
Local API jobs.queue/run/cancel with overrideAccess: false allowed
payload-kv / payload-migrations 403 / 501 (already closed)

No 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 both buildConfig call sites apply it (src/payload.config.ts, tests/utils/testHelpers.ts). It cannot run in onInit, because Payload's dev hot reload swaps in a freshly sanitized config without re-running onInit.

Entity Access
payload-jobs, payload-migrations, payload-jobs-stats, jobs.access Admins only
payload-locked-documents Active managers. The edit view locks, takes over and releases over REST
payload-preferences Managers, own rows only. Every endpoint refuses a non-manager, because the /:key handlers skip access
payload-kv Nobody
Any other payload-* Admins only, so it fails closed

In-app job callers (autoRun, the screening kick) leave overrideAccess at true, 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.ts has 14 cases:

  • A sweep that checks every payload-* collection's and global's access functions against a client.
  • REST cases that read rows back to confirm each write was refused.
  • Guards that managers keep the lock and preference flows the admin panel uses.

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

…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]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-857 September 28, 2026 17:23 Destroyed
@railway-app

railway-app Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-857 environment in sahajcloud

Service Status Web Updated
SahajCloud ✅ Success (View Logs) Web Sep 28, 2026 at 5:26 pm UTC
1 service not affected by this PR
  • mailpit

@Ardnived

Copy link
Copy Markdown
Contributor

@sydevs-bot review

@sydevs-bot

sydevs-bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🤖 no session running

recent dispatches
  • 23:23Z address-review · attempt 1 · session · done
  • 23:23Z address-review · attempt 1 · session
  • 23:04Z address-review · attempt 1 · session · done
  • 23:04Z address-review · attempt 1 · session
  • 22:34Z adversarial-review · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 28, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 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.queue is admin-only now, and enqueueSubmissionScreening queues with a client req. (systemEntities.ts:52)
  • should-fix — a third buildConfig call site does not apply this. (systemEntities.ts:27)
  • consider — guardEndpoints is a knob with one consumer. (systemEntities.ts:68)
  • consider — two SYSTEM_COLLECTIONS entries 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

Comment thread src/plugins/access/systemEntities.ts Resolved
Comment thread src/plugins/access/systemEntities.ts Resolved
Comment thread src/plugins/access/systemEntities.ts Resolved
Comment thread src/plugins/access/systemEntities.ts Resolved
@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 28, 2026
@Ardnived

Copy link
Copy Markdown
Contributor

@sydevs-bot Address review

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 28, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor

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.

  • Adopted — a case pinning that a client submission still queues screening. Payload defaults overrideAccess to true, so the intake never meets admin-only jobs.access.queue. Nothing named that.
  • Adopted — seeds/tests/test-payload.config.ts is a third buildConfig site and now applies the guard.
  • Adopted — one line saying the SYSTEM_COLLECTIONS table is the inventory.
  • Pushed back — guardEndpoints stays. Wrapping every system collection would gate /api/payload-jobs/run on managers, not admins.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 28, 2026
@Ardnived

Copy link
Copy Markdown
Contributor

@sydevs-bot I accept your changes, go ahead and merge all and resolve the conversations.

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 28, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor

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

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 28, 2026
@Ardnived
Ardnived added this pull request to the merge queue Sep 29, 2026
Merged via the queue into main with commit c6511bc Sep 29, 2026
98 of 105 checks passed
@Ardnived
Ardnived deleted the fix/payload-system-entities-access branch September 29, 2026 03:47
sydevs-bot pushed a commit that referenced this pull request Sep 29, 2026
#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
sydevs-bot pushed a commit that referenced this pull request Sep 29, 2026
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

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-857 — 02aecbc7 Deployed Sep 28, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants