Repository navigation
fix(access): a published client key reads every manager's name and email - #825
Conversation
`managers` sat in no project. For read that is not restrictive — implicit read treats "no project" as shared, so every published API key, the Atlas widget's browser key included, could list every manager's name and email address. Directly through `GET /api/managers`, and at `depth >= 1` through `Events.manager`, `Regions.managers`, `Pages.managers`, `Clients.managers` and `Clients.primaryContact`. `RESTRICTED_COLLECTIONS` is the mechanism for exactly this, and `users` is the precedent: restricted for the same reason, with `atlas-manager` given its read back explicitly. No client role gets a compensating grant. Nothing in SahajCloud, SahajAtlasWeb or WeMeditateWeb asks a client to read a manager — every SahajAtlasWeb fetcher passes an explicit `select` and none names `manager`, and WeMeditateWeb narrows `EMBEDDED_FORM_SELECT` expressly so a form's `recipient` never reaches the browser. `atlas-manager` gets `managers: ['read']`, because it holds create/update on events and regions and so resolves both pickers. Collection-wide on purpose: a picker exists to list *other* managers, so a self-scoped `Where` would empty it. `web-translator` gets nothing — `Pages.managers` is `adminOnlyFieldAccess` on update, and `translate` reaches localized fields only. The cost is a raw id in the Page Editors sidebar for that one role on that one field. The four relationship fields need no lock of their own: populate refuses the related read and falls back to the bare id, which Payload's own `relationshipPopulationPromise` states outright. `Forms.recipient`'s existing lock becomes defence in depth, so its `⚠` — which justified itself by saying `managers` was unrestricted — is corrected rather than kept as a false claim. Admin navigation is unaffected: `createHidden` gates on write permission, and no role grants write on `managers`. Document-level manager access is unaffected: every query in `documentManagers.ts` passes `overrideAccess: true`. Refs #821 Co-authored-by: Claude <[email protected]>
The sixth path to a manager's address, and the one restricting the `managers` collection cannot close: this field holds a *copy* of the address, not a relationship to the manager, so no collection-level rule reaches it. It carried no field access, and `events` is in the `sahaj-atlas` project, so `sahaj-atlas-client` read it at any depth. It is where registration updates are redirected, and its placeholder is `Event Manager` — blank means the event manager, so a non-blank value is an address someone chose to expose to the CMS, not to the widget. The widget never asks for it: SahajAtlasWeb's event fetcher selects `contactPhone` and `contactName` only. `managersOnlyFieldAccess` is the same helper `Forms.recipient` carries and admits any manager, so `atlas-manager` still reads and writes it. `contactEmail` beside it stays open — that one is the address a seeker is meant to write to. Refs #821 Co-authored-by: Claude <[email protected]>
`tests/int/managers-access.int.spec.ts` covers all six paths through `payload.find` with `overrideAccess: false`, shaped like `user-submissions-access.int.spec.ts`. A `hasPermission` assertion would not do: a collection's own `access` block outranks the generated one, so the predicate can answer "denied" while the composed config still serves rows. The one `hasPermission` case is about role configuration — that no client role carries a grant — which is what a predicate is right for. Two vacuous-pass traps are closed explicitly. A client read carrying no `select` is refused 400 by the usage plugin before access runs, so a bare `rejects.toThrow()` would go green against a wide-open collection: every read declares `select`, and the refusal asserts 403. And a populate that falls back to a bare id looks identical to a relationship that was never seeded, so the first case reads every fixture back as an admin and asserts the manager's email is really there. Each of the three defects was reintroduced and watched fail: dropping the `RESTRICTED_COLLECTIONS` entry reds 5 cases, dropping the field lock reds 1, dropping the `atlas-manager` grant reds 2. `atlas-report-issue-form.int.spec.ts` asserted a populated `recipient` for a `web-translator`. That role holds no `managers` grant now, so the value is a bare id — the accepted cost, not a regression. The case now asserts the field survives and carries the recipient's id, which still tells "the lock let it through" apart from "the lock stripped it", and a new sibling case pins the other half: an `atlas-manager`, which has the grant, still gets the populated manager. Refs #821 Co-authored-by: Claude <[email protected]>
`docs/rules/access.md` named `managers` as sitting in no project and so "shared, readable by every role". That sentence was written as a description of the mechanism and was the documentation half of #821 — it described the exposure without anyone reading it as one. It now names the restricted set correctly, says no client role gets a grant back, and records the one accepted cost: `web-translator` renders a raw id in the Page Editors sidebar. The field-lock section gains `Events.registrationNotificationEmail` as its fourth field, and states the distinction that section previously had no reason to draw — a collection-level restriction reaches a relationship, a field lock is what reaches a denormalized copy. `Forms.recipient`'s justification moves with it, since the lock is now defence in depth. The `clients` paragraph is left to #822. Refs #821 Co-authored-by: Claude <[email protected]>
A seventh path to a manager's address, found reviewing the six this ticket set out to close. `logField` declared `create` and `update` access and no `read`, so the column was readable by anyone who could read the document — and `Events.activityLog` sits on a collection in the `sahaj-atlas` project. `GET /api/events?select[activityLog]=true` with the widget's published browser key returned it. What it holds is not incidental. A reminder entry records `destination`, "the address/handle the reminder went to" — a manager's email, or a WhatsApp, Telegram or WeChat handle from their contact details. Escalation entries add the region managers above the event, who have no relationship to it at all. And `actorFromUser` falls back to an address when a manager has no name, so `by.name` can be one too. Restricting the `managers` collection cannot reach this: a JSON column holds copies, not a relationship. The lock goes in the factory rather than on the field, so `user-submissions.activityLog` inherits it and so does the next consumer. `!== 'clients'` rather than `managersOnlyFieldAccess`, matching the two keys beside it: the admin verify action writes this log with `overrideAccess: false`, so the predicate has to admit whatever the two write keys already admit. Refs #821 Co-authored-by: Claude <[email protected]>
From the review pass over the branch. Behaviour is unchanged except for
one test that was not testing what it said.
- The `⚠` on the `RESTRICTED_COLLECTIONS` entry enumerated the six paths
and contradicted itself doing it — "five of them close here" over a list
of one endpoint and five fields, then "those four fields". A census also
goes stale the day a field is added. It now states the rule that does
not: this entry reaches a relationship, never a copy.
- `Forms.recipient`'s comment narrated what this branch did to the
previous comment. `docs/rules/code-comments.md` rules that out, and the
durable half is the last sentence.
- The new spec built its own client request. `createClientAuthenticatedRequest`
and `idOnlySelect` already exist, and the latter's JSDoc owns the
400-vs-403 hazard the header was restating.
- `it('still reads contactEmail')` selected and asserted `contactName`.
The event fixture now seeds a contactEmail and the case reads it back —
it is the contrast both locks lean on, so it has to be the field tested.
- `statusOf` was nine lines and one call site for what
`rejects.toMatchObject({ status: 403 })` says inline.
- The `atlas-report-issue-form` case added for the `atlas-manager` grant
duplicated the managers-access spec's own, from the wrong file and with
a fixture seeded mid-test. Dropped; the redundant `toHaveProperty`
beside it went with it.
Refs #821
Co-authored-by: Claude <[email protected]>
Follows the code. The field-lock section became a four-bullet list, one
per locked field, so the next lock is added without re-flowing a
ten-line paragraph carrying three `⚠`.
The distinction the section now leads with is the one this ticket paid
for twice: `RESTRICTED_COLLECTIONS` reaches a relationship to a
collection, and only a field lock reaches a copy of its data.
`Events.registrationNotificationEmail` and `Events.activityLog` are both
copies, and neither was closed by the list.
Also corrects the description of `managersOnlyFieldAccess`. It was
written as a denylist ("denies any caller whose collection is clients")
and is spelled as an allowlist, which denies an anonymous caller too.
Refs #821
Co-authored-by: Claude <[email protected]>
|
🚅 Deployed to the SahajCloud-pr-825 environment in sahajcloud
1 service not affected by this PR
|
|
🤖 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 diff is the size of its ticket: ~60 production lines over five files, plus a 315-line spec. Events.activityLog is a real seventh path, and the logField factory is the right level to lock it. No blockers. Both findings are about the new prose and the new predicate, not the fix.
Findings
consider— the newreadis a denylist, whileaccess.mdin this same diff calls the lock an allowlist (src/fields/logField.ts:222).consider— "reaches a relationship, not a copy" is stated five times in four files (src/plugins/access/config/projects.ts:175).
Checked
atlas-manager is the only role with write on events or regions, so one grant is right. hasPermission denies a null user and users is non-auth, so the denylist is equivalent today. Swept every overrideAccess: false read in src/: gateRegistration.ts:48 reads an event as a client and touches no locked field; the atlas seo, sitemap and geojson selects name none. Both consumer repos name the locked fields only in generated types.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The `read` predicate reads as inconsistent beside `access.md`, which calls `managersOnlyFieldAccess` an allowlist in the same diff. The predicate stays: all three keys must admit the same callers, because the verify action writes the log at `overrideAccess: false` with a manager's own permissions. The comment now carries the equivalence proof instead of leaving the reader to re-derive it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016YoK9Qzru3y85rHHRvVcCr
The rule stood five times across four files. The two call-site comments earn their place, because that is where someone trips over it. The restricted-list entry now carries the grant plus a pointer, and `access.md` states the rule once, in the section that owns the list, rather than restating it two sections later. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_016YoK9Qzru3y85rHHRvVcCr
|
Both adversarial findings adopted. Pushed
Nothing rebutted, nothing asked. Comment-only: 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
The comment said "denormalized" and "reaches a relationship, never a copy" — accurate, and unreadable to anyone who has not read docs/rules/access.md. State the same fact in ordinary words: the field holds a copy of an address, and hiding the collection does not hide a copy. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BAN4NMPCSiP6gco2Kjp21Q
24 lines for a three-key access block. Every rule survives — the admin.readOnly caveat, why the verify action must not be denied, and why read is a denylist — stated once each instead of as a narrative. The full story stays in docs/rules/access.md. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BAN4NMPCSiP6gco2Kjp21Q
|
Both findings adopted, both threads resolved. Pushed
Nothing rebutted, nothing asked. Comment-only again: 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
`main` landed #825, which restricts `managers` and edits the same three places this branch does. Both restrictions are wanted, so every hunk keeps both sides. - `RESTRICTED_COLLECTIONS` holds `managers` and `clients`. Both docblock entries stay. The holding-pattern note said `managers` was the one collection left outside the set and that #821 blocked the real fix; #825 settled that, so the note now says all four out-of-project collections are named and the set fails open on the fifth. - `permissions.ts` step 4a keeps `main`'s pointer to `config/projects.ts` and this branch's note that self-access already answered a client's own row. - `docs/rules/access.md` keeps both ⚠ sets. `clients` is no longer an example of "in no project, so shared", the field-lock list is five fields rather than four, and the two claims each side made about the other's collection being unrestricted are corrected. `managers-access.int.spec.ts` needed two fixes the merge exposed. It passed `String(client.id)` to `createClientAuthenticatedRequest`, which takes a `number` on this branch — the stringified id denies a client its own row through the self-access bypass. And its depth-1 `clients` case read a list, which restricting the collection now refuses outright: the case is split into the 403 and a self-access `findByID` of the caller's own row, which is where #821's property still has to hold. Both were watched failing with the restriction dropped. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_0191PvAdP7nkRiqAno9irxaE
Summary
managersjoinsRESTRICTED_COLLECTIONS. No client role gets a grant back;atlas-managergets the only one, because it picks onEvents.managerandRegions.managers.eventshold a manager's address as a value, which no collection-level rule reaches:registrationNotificationEmail, andactivityLog— a seventh path found during review, not in the ticket.tests/int/managers-access.int.spec.tsasserts every path throughoverrideAccess: false. Each of four defects was reintroduced and watched fail.Changes
src/plugins/access/config/projects.ts—'managers'in the restricted setsrc/plugins/access/config/roles.ts—atlas-managergainsmanagers: ['read']src/collections/Events/Events.ts—managersOnlyFieldAccessonregistrationNotificationEmailsrc/fields/logField.ts— the factory'saccessgains aread, so everyactivityLoginherits itsrc/collections/Forms/fields.ts,src/plugins/access/permissions.ts— comments the change makes falsedocs/rules/access.md—managersin the restricted list, and the field-lock section rebuilt around the four fields that carry the locktests/int/managers-access.int.spec.ts(new), andtests/int/atlas-report-issue-form.int.spec.ts, whoseForms.recipientcase now asserts a bare id — that is what separates the lock passing the field through from the lock stripping itPreview
The API half needs a published client key, so it is not a link — the integration spec is the evidence.
Migration
None. Field access and role grants are runtime config; no column changes, so
db:migrations:createwas not run.Test results
lint,typecheck,typecheck:tests,test:unit(2144 passed)logFieldis sharedEvery review round since has been comment-only —
git diff 3139dd3..HEADchanges no non-comment TypeScript line — so the lean gate was re-run each time and the integration lane was not.Manual verification
sahaj-atlas-clientkey,GET /api/managers?select[id]=true→ 403.GET /api/events?select[activityLog]=true&select[registrationNotificationEmail]=truewith that key → neither key present.atlas-manager, open an event and confirm the Manager picker lists other managers.web-translator, open a page's Page Editors sidebar: it now shows a raw id instead of a name. Intended — see Notes.Notes for reviewer
The seventh path is the part worth your attention.
logFielddeclaredcreateandupdateaccess and noread. A reminder entry recordsdestination— "the address/handle the reminder went to", a manager's email or a WhatsApp/Telegram/WeChat handle — and escalations log the region managers above the event too.GET /api/events?select[activityLog]=truereturned all of it to the widget's browser key. The lock went in the factory, souser-submissions.activityLogand the next consumer inherit it.One accepted regression, already settled on the ticket:
web-translatorloses thePages.managerspicker label and renders a raw id. Cosmetic, one role, one admin field.A latent trap found while reviewing, not touched here.
applyFieldAccessForTranslatableCollectionsinjects role-aware field access only where!field.access, so a hand-writtenaccessblock silently replaces it. Harmless today —eventsis not translatable — but it would bite ifeventsever gained atranslategrant.Detail
Why the four relationship fields need no lock. Payload's
relationshipPopulationPromisepopulates through the dataloader at the parent'soverrideAccess, withdisableErrors: true, and falls back to the bare id when the related read returns nothing — its own comment says "ids are visible regardless of access controls". Verified innode_modules, and asserted forevents,regionsandclientsin the new spec.Fixture pre-mortem, and it caught something. The
activityLogfixture assumes an event's log survives a write. It does not:syncVerificationOnSave(src/collections/Events/hooks/syncVerificationOnSave.ts) resetsactivityLogto a singlere-saveentry on any managed save, so a log passed to the create is discarded. The seed now writes undercontext: { skipVerifyHook: true }and builds the entry through the realbuildReminderEntry. Without that, the assertion would have passed vacuously — the first fixture case is what caught it.Why
!== 'clients'onlogFieldrather thanmanagersOnlyFieldAccess. The admin verify action writes the log withoverrideAccess: false, soreadhas to admit whatever the two write keys beside it already admit. An anonymous caller never reaches it —hasPermissiondenies a null user at collection level. The code now carries that equivalence itself, rather than leaving it here.clientsatdepth >= 1. The ticket warns this check goes vacuous if #822 restrictsclientsfirst. It asserts on a row the key can read today; if #822 lands first, that case needs revisiting.Adopted from the adversarial review pass. Two
considerfindings, both about the new prose.logField'sreadnow states why it stays a denylist (ca14320). The relationship-vs-copy rule stands once, atdocs/rules/access.md:210, instead of five times across four files (8d40d21) — the two call-site comments stay, because that is where someone trips over it.Adopted from @Ardnived's review. Both findings landed on those same two comments, and both are fixed.
Events.registrationNotificationEmail's lock is now explained in ordinary words — a copy of an address, and hiding the collection does not hide a copy — instead of "denormalized" and "reaches a relationship, never a copy" (a5ed0ec).logField's access comment is 11 lines instead of 24, with all three rules kept and the narrative left todocs/rules/access.md(89b2f19).Dismissed review findings. Lifting
managerReqintotests/utils/testHelpers.ts, and exporting a sharedmanagersOnlyAccessobject to replace the four hand-copied three-key literals — both are refactors of code this PR does not otherwise touch, so they widen the diff past the ticket. Worth filing separately. The reviewer also suggested dropping thecreate/updateassertions from the client-roles case as unreachable; kept, because the acceptance criterion is "no client role holds amanagersgrant", not "no read grant".Also checked and clean: every
collection: 'managers'call site undersrc/passesoverrideAccess: trueor relies on the Local API default, so no server-side reader degrades. The atlas SEO, sitemap and geojson endpoints read atoverrideAccess: falsewith explicit selects that never name a manager.managerswas already in the OpenAPI spec's always-hidden set.Closes #821
🤖 Generated with Claude Code
https://claude.ai/code/session_01TU4aJFfuUtqbPqfvp9fqnc
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code