Skip to content

fix(access): narrow activity-log contact addresses to the region that owns the event - #1054

Closed
Ardnived wants to merge 1 commit into
mainfrom
claude/fix-1047-log-addresses
Closed

Ardnived wants to merge 1 commit into
mainfrom
claude/fix-1047-log-addresses

Conversation

@Ardnived

@Ardnived Ardnived commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • An activity-log entry that records a contact address now shows that address only to a reader with business with the event: an admin, the address's owner, or a manager whose region subtree holds the event (or who manages it). Everyone else still sees that the reminder or delivery happened, to whom, and when.
  • Both logs that hold addresses opt in: Events.activityLog reminders (destination, cells.delivery) and user-submissions.activityLog deliveries (cells.sentTo).
  • Four paths that skip an afterRead projection are closed with it: where/sort filtering, write-back of a redacted log, duplicate, and previewEvent's override read.

The decision this implements, from the maintainer, Ardnived (2026-10-30), overriding the ticket's options A/B/C:

Region managers should be able to see the email addresses of managers on sub-regions and events within their region. They need to be able to contact these users.

Change outline

Contract — what a manager reads off a log entry

 GET /api/events/:id   as an atlas-manager outside the event's region subtree
   activityLog[]: { kind: 'reminder', at, stage, level, role, region, channel,
                    manager: { id, name },
                    cells: { activity, who } }
-                   destination: '[email protected]'
-                   cells.delivery: { label: 'email', text: '[email protected]' }
   activityLog[]: { kind: 'verification', …, cells: { delivery: 'Saved' } }   # untouched — a method, not an address

 GET /api/user-submissions/:id   as the same manager, a proposal from elsewhere
   activityLog[]: { type: 'delivery', at, ok, cells: { activity: 'Delivered' } }
-                   cells.sentTo: '[email protected]'

Deleted, not blanked, which is the projection a denied field lock makes. LogTable renders an empty cell, and the row's JSON drawer shows no address.

Behaviour — who sees an address

 regionScopedAddressVisibility(locate)                 src/plugins/access/logAddressVisibility.ts
   admin                                     → every address
   not an active manager                     → none          # allowlist: no user, inactive, a third auth collection
+  the entry is their own                    → that entry    # by the entry's manager.id; by email only where it names nobody
+  isEventInScope(ownedRegionIds, user, ev)  → every address # region ∈ owned subtree, or ev.manager == user
   else                                      → own entries only

 isEventInScope                                         src/plugins/access/regionSubtreeAccess.ts
+  extracted from scopeRegionSubtreeWrite's single-event branch — one predicate for
+  "may write this event" and "may read its contacts", over the existing resolveOwnedRegionIds

Where each document is placed:

  • An event: its own region/manager, loaded with select when the read omitted them (eventAddressScope).
  • A user-submission: the target event for an update proposal; the routing region for a new-event proposal, using submissionRoutingRegionId, the chain deliverProposal mails up (UserSubmissions/logAddressScope.ts).

Flow — the opt-in, per collection

 logField({ …, addresses?: { types, keys, visibility } })     src/fields/logField.ts
   no `addresses`                         → exactly as before; every log keeps today's default
+  afterRead     redact, unless overrideAccess === true        # the read the field lock also exempts
+  read lock     no row in hand (`doc` undefined) → admin only # a query, a distinct read, /api/access
+  beforeChange  restore any entry that is exactly a stored one minus its addresses
+  beforeDuplicate → []

 Events.activityLog           types: ['reminder'], keys: ['destination', 'cells.delivery']
 user-submissions.activityLog types: ['delivery'], keys: ['cells.sentTo']

Joined — the copy an override read carried

 loadTargetEvent(req, id)                               src/collections/UserSubmissions/hooks/computeReviewFields.ts
   findByID events, overrideAccess: true
+    select: { activityLog: false }
 → previewEvent   # read by every manager, so the target event's whole log rode along

Preview

Railway builds this PR at a host keyed on its number. A fresh preview carries one admin and no events, so it shows the "admin sees everything" half only.

  • The preview's Events list (/admin/collections/events) is unchanged for an admin.

Data: not seeded. The narrowing needs an event with reminder entries in two regions, plus an atlas-manager session in each; a preview has no way to provision either. The integration specs cover that half instead.

Test results

  • Lean gate: ✓ lint, format, typecheck, typecheck:tests, unit lane (233 files / 2973 tests)
  • Targeted specs, 116 passed:
    • event-verification (48, 12 new)
    • user-submissions-access (19, 11 new)
    • managers-access (12)
    • user-submissions-review-lifecycle (37)
  • Unit: log-field (15, 6 new)
  • Build: N/A. Railway builds the preview.
  • Every new case was run against the unfixed code. With src/ reverted, 5 event cases and 4 submission cases fail: the outsider reads (full, select-narrowed, REST, depth-1 populated), the own-address-only case, the previewEvent copy, and the filter refusal. The visible-to cases cannot fail against old code, so each was mutation-checked against the fix instead:
    • scope branch disabled → the region-manager and event-manager cases fail;
    • restore hook disabled → both write-back cases fail;
    • doc-less lock and duplicate hook disabled → the filter and duplicate cases fail.

Manual verification

  1. On a database with two regions, sign in as an atlas-manager who manages neither region of a reminded event.
  2. Open that event's Verification tab: every row still shows Event and Who, and Delivery is empty on reminder rows only. Click a row: the JSON has channel and no destination.
  3. Sign in as the manager of the event's country. The same tab shows every address.
  4. As the outsider, open /api/events?where[activityLog.destination][like]=a. It answers 400, The following path cannot be queried.
  5. As the outsider, reject a proposal from another region. Then, as an admin, the proposal's delivery entry still shows Sent to.

Notes for reviewer

Event's own manager → sees the escalated region managers' addresses. I went this way because the reminder escalates about their event to those region managers. "They need to be able to contact these users" reads in both directions on that chain, and region managers already receive the event manager's contact card in the escalation email. It also makes visibility exactly isEventInScope, the predicate that already decides who may write the event. One test of "has business with this event" now serves both. The alternative (event manager sees only their own address) would need a second, narrower predicate that nothing else uses.

This overrides #1047's criterion "user-submissions.activityLog renders exactly as it does today." The ticket read that log as carrying no contact detail, citing the review entries, which store a managerId only. DeliverSubmissions also writes cells.sentTo, and on a proposal that is the address the review mail went to — so that log narrows too, and an outsider's Sent to cell on a proposal is now empty.

This closes the exposure only together with #1045. On main today, every narrowed entry still carries manager.id, and an atlas-manager can read GET /api/managers/<id> for that row's email and contactDetails (#908). #1045 closes that. The two branches merge cleanly (git merge-tree against claude/fix-908-manager-field-locks): this PR adds no code to stripLockedFieldsOnSelfRead or adminOnly.ts, and its docs edits sit outside #1045's hunks. Once both land, a region manager reads a sub-region manager's address in the log but not off their managers row. That is the maintainer's rule applied to the log only. Widening managers to match is a separate decision.

where on the JSON column: a manager could filter by its contents. Before this, as an outsider, where[activityLog.destination][equals] and [like] both matched. like is a substring match, so an address could be read out a prefix at a time. The whole-column [activityLog][like] hit a raw SQL error instead.

The fix lives in the lock, not in a hook. Payload builds the field policies for query validation with no document (getEntityPermissions, fetchData: false), so a narrowed log answers that question for admins only. Payload's own validator then refuses every path shape, including the three the adversarial review found my first beforeOperation guard missed:

  • an uppercase OR/AND;
  • a path through a join (regions.events, managers.managedEvents, users.submissions);
  • a relationship hop (user-submissions?where[event.activityLog…]).

sort and findDistinct are refused the same way. Every read of a row passes doc; the admin edit view's docAccessOperation passes the fetched row. A case pins that the Verification tab still renders for a non-admin.

The write-back was a real data-loss bug, not a hypothetical. An outsider can update proposals (managerSubmissionScope covers every proposal). The admin form posts back the redacted log it rendered, and applyReview appends to the redacted doc its own update's afterRead left. Either path erased sentTo from storage. restoreLogAddresses puts back only an entry that is exactly a stored entry minus its addresses, so a writer gets nothing that was not already stored. Events have no equivalent exposure: their updaters are exactly the readers isEventInScope admits. The hook covers them anyway.

Adversarial review (fresh subagent, handed the diff only). Its findings, and how each was handled:

  • Fixed:
    • Query-guard bypasses (uppercase OR/AND, joins, relationship hops). Replaced the guard with the doc-less lock above.
    • duplicate copying the source's whole log into a draft the caller re-homes to their own region. Added beforeDuplicate: [() => []]. The case uses an unmanaged event, which syncVerificationOnSave leaves alone, so only the hook empties it.
    • Verification entries' cells.delivery ('Saved', 'Email link') were being stripped. Added types, so only reminder and delivery entries narrow.
    • Own-address by handle let a manager add a guessed handle to their own contactDetails and confirm whose it was. "Own" now uses the entry's manager.id, and email only where an entry names nobody.
    • N+1 event loads on a submissions list (now memoized per request), and trash: true on the routing load.
    • A dead data.parent versions branch: Payload hands the hook the version snapshot itself. Removed.
    • The tests that could not fail: covered by the mutation runs above. The API-client submission case now says plainly that it guards the collection restriction, not the narrowing.
  • Kept, with reasons:
    • resolveOwnedRegionIds(req) joining a write's transaction inside afterRead. The same memoized call already runs inside every atlas-manager write's access check, and it only reads. The two gate loads that are new here take no req.
    • Versions decide from the snapshot's own region/manager. readVersions is already update-scoped, so this cannot leak. A select-narrowed version read falls back to own-only.
    • A subscribe delivery's sentTo is '<provider> list <id>' — a mailing list, not a person — and types does not reach it, since DeliverSubmissions logs every intake's outcome as the one delivery type. No carve-out, because managerSubmissionScope gives no non-admin a subscribe or registration row at all (accessConfigs.ts:92, pinned at user-submissions-access.int.spec.ts:211), and an admin sees every address. Widening that scope would need one here.
  • Not fixed (low):
    • A transport error message that names the recipient lands in cells.activity of a failed delivery.
    • Reminder entries written before this PR for a manager with an empty name stored the address as the name. Names are required, and ExpireEvents no longer falls back to the address.
Detail

Every read path checked:

  • REST and local find/findByID, as each reader
  • select[activityLog]=true: no region/manager on the row, so the decision loads them with a two-column select
  • depth population and joins: the field hook runs per populated document with the reader's access
  • versions, as above
  • the admin edit view, which uses getDocumentData with overrideAccess: false, and its field permissions
  • LogTable and VerificationStageField, which read form state only
  • previewEvent/proposedChanges, now selecting the log out
  • where/sort/joins/relationship hops/findDistinct, all refused
  • bulk update by where, refused
  • duplicate, emptied
  • dashboards, the Atlas sidebar, ImportResultsField, SEO/sitemap and geojson: all select without activityLog, or are client-only
  • the verify page: a server component that never sends the log
  • GraphQL is disabled, and REST /distinct is not routed in Payload 3.90.2

Jobs keep the address. ExpireEvents, DeliverSubmissions, ScreenSubmissions and SendSessionReminders read at the local API's default overrideAccess: true, where the hook stands down. The update operation reads originalDoc the same way, which is what the restore compares against.

No migration, no type change. custom, hooks and access change no column; payload-types.ts is unchanged.

Review passes run: the adversarial subagent above, over the whole diff. /simplify, /code-review and /security-review were not run separately.

Closes #1047

🤖 Generated with Claude Code

… owns the event

An event's reminder entries record the email or messaging handle each
verification reminder went to, and a proposal's delivery entries the
address its review mail went to. logField's read lock admitted every
manager, and atlas-manager reads events and proposals project-wide, so
any of them read the contact details of managers in other regions.

logField gains an opt-in `addresses` option naming the entry types and
keys that hold an address. An entry whose address the reader may not see
comes back without those keys; the rest of the entry stays. A reader sees
it as an admin, as the recipient the entry names, or when isEventInScope
holds (the event's region is in their owned subtree, or they manage the
event) — the predicate atlas-manager's event writes already pass, now
shared with them. A user-submission is placed by its target event, else
the region intake routed it to.

Paths that skip an afterRead projection are closed alongside it:
- the lock answers a read with no row in hand (a where/sort path,
  through a join or a relationship hop, a distinct read) for admins only,
  so a filter cannot test a guessed address;
- a write restores addresses a redacted read removed, so the admin form
  and applyReview do not erase them on save;
- a duplicate starts with no log;
- previewEvent's override read of the target event excludes activityLog.

Closes #1047

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@railway-app

railway-app Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

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

Service Status Web Updated
SahajCloud ✅ Success (View Logs) Web Oct 30, 2026 at 9:33 pm UTC
1 service not affected by this PR
  • mailpit

@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-1054 October 30, 2026 21:29 Destroyed
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 30, 2026
@sydevs-bot

sydevs-bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🤖 no session running

recent dispatches
  • 22:55Z address-review · attempt 1 · session · done
  • 22:55Z address-review · attempt 1 · session
  • 22:46Z review-pr · attempt 2 · session · done
  • 22:46Z review-pr · attempt 2 · session
  • 21:42Z review-pr · attempt 1 · session · timed out

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

@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Oct 30, 2026
@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 30, 2026
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 30, 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 narrowing is right, and isEventInScope is the best thing in the diff: one predicate now answers "may write this event" and "may read its contacts", instead of a second rule nothing else uses, identical to the branch it replaced. Scope is option A plus the maintainer's widening, nothing more.

My one real doubt is the aggregate. logField grows five pieces — the addresses option, the afterRead, a doc-less read lock, a write-back restore, a duplicate hook — to protect a value the entry may not need to store at all. Each piece is forced by the approach; the approach is the question.

The user-submissions half contradicts the ticket's criterion "renders exactly as it does today" — correctly, since cells.sentTo really is an address, but the body should say it overrides that criterion.

Findings

  • should-fix — the address need not be stored; manager.id + channel already identify it (src/fields/logField.ts:330).
  • should-fix — a subscribe delivery's sentTo is a list id, redacted against what the body claims (src/collections/UserSubmissions/fields.ts:606).

What was checked

  • Ticket #1047 against the diff. No payload-types.ts or responseTypes.ts change, so no consumer repo is involved.
  • buildReminderEntry writes both kind and type: 'reminder' (lib/eventVerification/log.ts:148), so the types match hits.
  • The same log's other sentTo writers (SendSessionReminders.ts:250, SendPostEventFollowUps.ts:137) record a registrant's email and stay out of types. senderEmailField carries no lock, so that address is readable on the row regardless — a deliberate exclusion, not a gap.
  • regionHint is in a collapsible (no data level), so routingColumns' key check and select name real keys.
  • Preview serves 200; not signed in — a fresh one has one admin, no events.

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


Generated by Claude Code

Comment thread src/fields/logField.ts Resolved
@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 30, 2026
@sydevs-bot sydevs-bot moved this from Working to Pending in SYDevelopers Technical Roadmap Oct 30, 2026
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 30, 2026
@sydevs-bot sydevs-bot moved this from Pending to Working in SYDevelopers Technical Roadmap Oct 30, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor

Both adversarial-review threads answered. Nothing to commit, and the branch already sits on main's head, so no merge either.

Rebutted — why the address is stored. A submissions delivery entry carries no manager and no channel, and its sentTo is often the form's recipient, not a manager row. A reminder entry carries both, but pickChannel reads a manager-edited contactDetails identifier, else their email — so a derived address says where it goes now, not where it went.

Rebutted — a subscribe sentTo. True of the entry, not of the reader: types does not exclude a subscribe delivery, but managerSubmissionScope gives no non-admin a subscribe or registration row. The body's claim was wrong; it now says this.

The body also records that this PR overrides #1047's criterion "renders exactly as it does today".

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


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 30, 2026
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Oct 30, 2026
Ardnived added a commit that referenced this pull request Oct 31, 2026
…r-field-locks

Stacks #1045 on #1054, whose isEventInScope the region widening reuses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Ardnived

Copy link
Copy Markdown
Contributor Author

Folded into #1045 by the maintainer's decision to ship the two contact-detail fixes as one PR. #1045's branch carries every commit from this one, merged in at 7664d876, and its body now covers both (Part 2 is this PR's description). #1047 now closes from #1045.

🤖 Generated with Claude Code

@Ardnived Ardnived closed this Oct 31, 2026
@sydevs-bot sydevs-bot moved this from Awaiting to Done in SYDevelopers Technical Roadmap Oct 31, 2026
Ardnived added a commit that referenced this pull request Nov 5, 2026
…r-field-locks

Stacks #1045 on #1054, whose isEventInScope the region widening reuses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-1054 — 5a137aa2 Deployed Oct 30, 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.

fix(access): an event's activity log leaks a manager's contact details

2 participants