Repository navigation
fix(registrations): close three holes in the repeat-signup merge - #1098
Conversation
`findRepeatRegistration` took the newest row among `accepted`, `pending` and `failed`. A sender can hold an active row and a newer `failed` one — legacy duplicates exist, and a `failed` row is left standing beside the seat it never confirmed — and the newest is then the dead row. Two things went wrong at once: the merge folded into it, leaving the active registration untouched and the event a seat over its limit, and `gateRegistration` read it through `isActiveRegistration`, so a full event refused `event_full` to a registrant who does hold a seat. An active row now outranks a newer inactive one, newest-first within each. The lookup reads every mergeable row for that sender and event rather than one: a cap would be the number above which the active row stops being found, and the set is a handful by construction. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjUy482mZhJtYQqv8S1
The merge is keyed on an address nobody verified, so a signup naming someone else's address reaches their row: it replaces the registrant's answers and session, puts the row back to `pending` with the screening verdict cleared, and has a fresh confirmation mailed to them. `user-submissions` keeps no versions, and the log entry carried no old values, so nothing could restore one. The entry now carries the replaced status, session, answers and screening verdict as machine data, with the previous name and status muted beside the entry so an overwrite is visible to a manager rather than only readable from the column. No answer becomes a log column: `activity` and `sentTo` are still the only two the field declares. This bounds the damage. Whether an unverified address may reach an existing row at all is still open on the review thread. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjUy482mZhJtYQqv8S1
A create's `select` is a query parameter, and no gate polices one:
`validateClientQueryParamsHook` returns on anything that is not a read. It
narrows the `afterRead` projection that Payload hands the `afterChange` hooks,
so `POST /api/user-submissions?select[id]=true` left `doc` as `{ id }` —
`doc.type` undefined, and `mergeRepeatRegistration` returned at its first
guard.
`gateRegistration` judges `data`, which no query parameter touches, and had
already waived `event_full` for the seat the fold-in was going to keep. So the
waiver was granted and never paid for: anyone holding the widget's public
client key could register once, then add rows past `registrationLimit` one
`select` at a time, and the one-active-registration-per-sender invariant the
waiver rests on stopped holding at the same time.
The hook now takes `type`, `event` and `user` from `data`, the same input the
gate judged. `doc.id` stays: Payload returns the new row's id whatever the
projection asks for.
The new case drives the real REST pipeline, because the local API cannot carry
a `select`. Against the old guards it leaves two rows on a one-seat event.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjUy482mZhJtYQqv8S1
…d on The merge wrote `client: data.client` — the calling key — onto the existing row, at `overrideAccess: true` on a client's behalf. `client` is what `DeliverSubmissions` renders the registrant's confirmation branding from, and `systemFieldAccess` closes it to every client write for exactly this reason: a caller able to set it can attribute a row to another service. Several `clients` rows carry `sahaj-atlas-client`, one per national organisation. So one organisation's key could fold into a registrant another organisation's key had created, re-attribute the row to itself, and — the merge also resets `status` and clears the verdict — have the confirmation re-sent to that registrant under its own name, logo and support address. The row now keeps the key it arrived on, as it keeps its `id`, `uuid` and `createdAt`. Which key sent the update is recorded on the activity-log entry. Whether a repeat signup through a second host site should re-brand the confirmation is a product question, and is not assumed here. The same commit stops the entry's muted line quoting the sender's own text. After one overwrite the stored name is whatever the last caller sent, so rendering it in the admin table made the record of what was replaced sender-authored — the forged history `logField`'s write lock refuses. It now names the previous status, a server-set enum, and nothing else. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjUy482mZhJtYQqv8S1
…limit `docs/rules/api-clients.md` is where a consumer reads what happens after the 201, and it still described a create that always adds a row. A repeat signup now returns the existing row's `id` and `uuid` instead, which is a behaviour an integrator can observe and has to expect. The hook's own ⚠ claimed the activity-log entry is the record the overwritten values leave. It is, but only for a while: `appendLogEntry` keeps the most recent `DEFAULT_LOG_LIMIT` entries and drops the oldest, and a public caller appends one per repeat signup — so enough of them roll the original values out of the column, and nothing else holds them. Said plainly here rather than left for the next reader to discover. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjUy482mZhJtYQqv8S1
…r can reach it Open question 2 on #1093, settled as option A. The activity-log entry is the only record of what a repeat signup replaced, and `appendLogEntry` caps the column at DEFAULT_LOG_LIMIT — so enough further signups for one address and event roll the original values out of it. A forged signup is therefore recoverable only until it is repeated, which is what option A on question 1 leans on. A merge that replaces an `accepted` row now also reports to Sentry at `warning`, fingerprinted on the row so repeats against one registration group into one issue rather than arriving as unrelated reports. The recurrence is the signal. Nothing reachable from a client key can roll that away, it needs no schema and no migration, and this collection's jobs already report there. Question 1 is settled as option A too, and the status set is where that decision lives: `accepted` stays mergeable. Refusing it would put a confirmed registrant's own repeat signup on a second row, a second seat and a second confirmation — the defect the merge exists to fix, back for the case that happens most. Reporting the overwrite is what makes keeping it answerable. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZCvvJ6ufDPXM1YJsE
…e projection #1093's first defect was not one hook's. A create's `select` is a query parameter the caller sets and nothing polices — `validateClientQueryParamsHook` returns on anything that is not a read, and `docs/rules/api-clients.md` states plainly that writes are unaffected. It narrows the `afterRead` projection payload hands every `afterChange` hook, so `POST …?select[id]=true` emptied `doc` of all but `id` and three more hooks on this collection returned at their first guard: - `queueScreening` read `doc.status`, so screening was never queued. An unscreened row gets no disposable-address check, no content scan, no `spam` verdict and no abuse strike, and is delivered as though one had cleared it. This is worse than the `registrationLimit` bypass the ticket was filed for. - `syncFullness` read `doc.type` and `doc.event`, so the event's `registrationsFull` flag was never recomputed. - `spawnSubscribeFromRegistration` read `doc.type` and `doc.submissionData`, so a registrant who ticked the mailing-list box left no consent record anywhere — the silence that column was replaced to stop. Each now reads `data`. `syncFullness` also runs on update, where `data` is only the patch, so it falls back to `doc` for a column that write did not touch; no client holds update here, so the narrowable half is the create. `doc.id` stays throughout — payload returns the new row's id whatever the projection asks for. `syncCommunityFeedback` reads `data` too, for consistency with `gateEventFeedback` beside it, which already did. That one is not reachable: no client may write `eventFeedback`, and the vote's one writer is the feedback page's server action. Said so at the line rather than implying a fourth hole. A unit guard now reads these hooks' own source and fails on a guard that gates on `doc`, because each of these was a one-word fix and a reviewer will not catch the next one. The integration spec drives the real narrowed request for the three that were reachable. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZCvvJ6ufDPXM1YJsE
The rule the code now follows was written nowhere. `docs/rules/api-clients.md` said "writes are unaffected" by the query-parameter gate as a reassurance; it is also the reason a hook on a client-writable collection cannot trust `doc`, so that consequence is now stated beside the claim. `src/plugins/formBuilder/AGENTS.md` already explained that these hooks check `type` for themselves. It now says where they read it from, and names the unit guard that holds it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZCvvJ6ufDPXM1YJsE
The 201 echoed the surviving row's `createdAt` and `updatedAt`. A merge therefore replied with a timestamp from the past where a fresh signup replies with now — so anyone holding a key, and the Atlas widget's key ships in every host page, could ask "is this address registered for this event?" for any pair they cared to name, and read the answer off the response. Attendance of a meditation class, for an arbitrary list of addresses. `id` and `uuid` stay: they are the published contract, and the `uuid` is what keys the registrant's calendar entry so a re-sent confirmation moves it rather than adding one. The timestamps were not part of that, and the row keeps its own `createdAt` either way — the spec still asserts it. Found by the branch-level security sweep. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZCvvJ6ufDPXM1YJsE
The guard spec this branch adds is the 242nd unit spec, and `tests/PERF.md` is the single writer of that figure — so the lane went red on its own file count, which is what that pin exists for. The case count was already 14 behind before this branch; both are now what the lane reports. No timing is re-measured, so every `s` figure stands as its own session recorded it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjZCvvJ6ufDPXM1YJsE
|
🚅 Deployed to the SahajCloud-pr-1098 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
1 question for the reviewer, one per thread.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
|
🤖 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 #1093 asks for: the three fixes, the sibling hooks the same root cause reached, and both open questions decided and applied. Nothing is smuggled in — each joined hook edit shares one cause, and the body names it. Two things are worth a second look. The rule this lands on is applied by hand in four hooks and policed by a spec that reads source text, when the gate that already owns client select sees the same create one layer up. And the response change is described as closing an existence oracle that it only narrows.
Findings
- should-fix — the per-hook rule replaces a one-line fix at the gate that owns
select(src/plugins/formBuilder/AGENTS.md) - should-fix —
idstill answers "is this address registered?", and the body says the oracle is closed (mergeRepeatRegistration.ts:164) - consider —
reportOverwrittenConfirmationis machinery against a harm nobody has counted (mergeRepeatRegistration.ts:177)
What was checked
Read whole on the branch: the four hooks, logField.ts, statuses.ts, lib/registrations/active.ts, plugins/usage/hooks.ts with its usagePlugin wiring, and both new specs. Ladder: isActiveRegistration and STATUS_LABELS are reused, not added; LogEntry's [machine: string] index and z.looseObject already carry replaced and submittedVia, so no schema grew; the source-reading spec matches three the body names. MERGEABLE_STATUSES is a fourth status vocabulary beside INACTIVE_STATUSES — correct, but the fold-in target is now read across two modules. Both preview links answer 200, and previewUrl on main carries no seed, so the body's empty-data line is accurate. No contract surface in contractSync is touched. Reviewer profile read.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
The 201 no longer carries the surviving row's timestamps, and the change was described as closing the existence oracle they opened. It narrows it. `id` is a Postgres serial and the response names the surviving row, so a caller holding the id of its own signup can still tell an earlier row from a fresh one. Returning the created row's id instead is not the fix: the hook deletes that row, and the id is what a client re-sending a signup keys on. So state the residue at the line and in the client contract, where a reader looks before trusting the claim. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWg9hN2tgTuGDpzV9k
The report said where it goes and not who acts on one, which is what separates a protection from a second record of the same overwrite. The reader is whoever watches this service's Sentry project; the action is restoring the row from the `replaced` entry the same hook wrote. That also states the report's own bound: the entry it points at is dropped after `DEFAULT_LOG_LIMIT` further signups, so an issue whose event count has passed that names an overwrite nothing can undo. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWg9hN2tgTuGDpzV9k
|
Addressed the review's three findings. Pushed 6460fb9 — comments and documentation only, no executable line changed (
Gate green: lint, format, both typechecks, 242 unit files, plus repeat-registration and narrow-select. Q1 stays open and waits on you. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
Approved, but this thread still waits on you, and the ruleset will not merge until it is resolved: #1098 (comment). Reply there, or resolve it. 🤖 sydevs dispatcher |
|
Q1 answered A. No code changed, and nothing is pushed.
Merged No gate run: no line changed. Head stays 6460fb9. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Both sides re-measured the unit lane, so all four of #1098's documentation figures conflicted: this branch at 250 files / 3375 tests, main at 242 / 3143. Neither is the merged tree. `tests/PERF.md` is the single writer of that figure and `perf-figures-pinned.spec.ts` counts the specs off disk, so the number is measurable rather than arguable: the lane reports 251 files and 3382 tests here. That figure goes into PERF.md and all four consumers, including the Tier 2 target line in `docs/rules/testing-reqs.md` that merged cleanly on this branch's side and quoted 3375 too. No timing is re-measured, so every `s` figure stands as its own session recorded it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXtY6kx6xNFuKgsZ4a
Four pinned test figures conflicted: both sides added unit specs and each re-stated its own count. The merged tree holds both sets, so the figure is the union, re-measured rather than added up — 245 / 3179, where arithmetic on the two sides would have said 3186. main's #1098 hardens the UserSubmissions afterChange hooks against a narrow `select`; this branch widens a read's `select` from a field's declaration. They do not meet: UserSubmissions declares no virtual-field inputs, so the plugin mounts no hook there. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjV1RG4adu2HctZNdbS
All four conflicts were one fact: the unit lane's file and test counts. Both sides re-measured them from the merge base's 241 files / 3129 tests — main to 242 / 3143, this branch to 245 / 3174 — so neither side is right once both sets of new specs are in the tree. The four docs that state the figure are recounted against the merged tree rather than resolved to a side: 246 files / 3181 tests, measured, not summed. No code file was touched by both sides. Main's repeat-signup merge (#1098) does not reach the preview fixture: no two fixture registrations share an event and registrant, so the merge never fires, and queueScreening still skips a row created with a terminal status. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVF4nZoxSyr4TMq6Ct
Summary
afterChangehooks onuser-submissionsgated on the same narrowable projection, and one of them skipped screening entirely. Joined here by the same root cause.idstill answers is stated in the contract rather than claimed closed.Change outline
Flow — a client create, and the four hooks the narrowed projection reached
The ticket named one hook. A create's
selectis a caller-set query parameter that nothing polices, so it narrows theafterReadprojection payload hands everyafterChangehook on the collection.POST /api/user-submissions?select[id]=true doc = { id } gateRegistration (beforeValidate) # judges `data` — unaffected afterChange: - mergeRepeatRegistration doc.type → undefined → returned early # the ticket's defect 1 + mergeRepeatRegistration data.type # already fixed on this branch - queueScreening doc.status → undefined → returned early # screening NEVER queued + queueScreening data.status - syncFullness doc.type → undefined → returned early # fullness flag never recomputed + syncFullness data.type ?? doc.type # also runs on update - spawnSubscribe… doc.type → undefined → returned early # consent record never written + spawnSubscribe… data.type syncCommunityFeedback data.type ?? doc.type # consistency only; see belowdoc.idstays everywhere — payload returns the new row's id whatever the projection asks for.Behaviour — the two decisions
Contract — what the 201 names
idnames the surviving row and ids are serials, so ordering still answers whether a row existed for an address — narrowed, not closed. Returning the created row's id is not the alternative: this hook deletes that row, and the id is what a client re-sending a signup keys on.docs/rules/api-clients.mdstates the residue.Files — one new rule, made mechanical
Preview
A Railway preview carries no content, and this change is server-side with no page of its own — the observable surface is a registration's activity log, which needs a seeded registration to show anything.
activityLogcarries theregistration-updateentry, with the status, session and answers it replacedData: not seeded yet.
previewUrl.seedis unset for this repo, so this run has no seed command to drive the preview with; both links land on empty lists until someone registers through it. The integration specs are what actually exercise the change.Test results
Every new assertion was watched to fail against its defect first, including by reverting each hook and re-running. The review round added comments and documentation only —
comment-fingerprint.mjsreports the one code file's hash unchanged — so the lean gate and the two registration specs were re-run and nothing else was.Manual verification
registrationLimit: 1,POST /api/user-submissions?select[id]=truetwice from one client key with the samesenderEmailandevent: 201 twice, one row. (Covered by a spec over the real REST pipeline, but it is the ticket's own checklist item.)registration-updateentry reads correctly in the admin activity-log table — the muted line is nowPreviously Accepted, built from the server-set status enum and never from sender text.Notes for reviewer
The security sweep found one HIGH issue I did not fix, because fixing it reverses a decision the ticket records. The merge selects its target by
(event, user)with noclientterm, anduseris the upsert of an unverifiedsenderEmail. So with the Atlas key — which ships in every host page — plus a victim's address and a published event id, a caller can overwrite that registrant's row: answers, session (or null it, bypassingstartingAt'supdate: () => false), status reset, screening verdict cleared, and a re-sent confirmation that moves their calendar entry via the retaineduuid.d0c9e13on this branch fixed the attribution half of that boundary and left the targeting half open.That is Q1 exactly, and the ticket recommends A. I built A and did not flip it, because B costs the commonest case a second row, seat and confirmation. The new evidence materially strengthens B, so it is a question thread on the line rather than a line here. Scoping the merge to the submitting key is a third option the ticket did not consider — it narrows the attack to same-organisation only, so it is a mitigation, not a fix.
Dismissed findings, with reasons:
args.selectfor a client create atvalidateClientQueryParamsHook, instead of the per-hook rule — declined. It cannot retire the rule:syncFullnessAfterChangeandsyncCommunityFeedbackalso run on update, wheredatais only the patch, so both keepdata.x ?? doc.xwhatever a create'sselectsays. Anddocis theafterReadprojection, not the input — field read access deletes a field from it, asreviewProjectionAccessalready does on this collection for a client — so a wider projection makes the two usually agree where the gate's waiver needs always. The cost is also wider than one response: that hook is collection-generic and documented as touching no write.clientonly when the existing row's is null — declined. The row was already unattributed,loadEmailClienttakes a nullable id and degrades to generic branding, and a conditional write re-opens a fieldsystemFieldAccesscloses on a condition the next reader must re-verify.docs/rules/api-clients.mdsets the precedent for credential rejections: report every one, mute volume Sentry-side, never in-process.reportOverwrittenConfirmationaltogether and keep Q2's option C — declined. C is the ticket's own third option and it did not recommend it, and criterion 6 asks for Q2 decided and applied. What the point did earn: the report now names its reader and what they do with one, in its docblock and in the client contract.findRepeatRegistration's unbounded read — declined, twice flagged. The repo's own feat(api): refuse an unbounded client read, once the Atlas widget paginates #889 convention is to wrap such a read withasTrustedReqand justify its size at the call site, which this code does, comment included.replaced.submissionDatacopies the whole answer blob, up to 50 retained entries — kept. Recording the complete replaced set is the acceptance criterion; the bound needs dozens of repeat signups on one row, which is what the new report surfaces. It is the one cost this branch adds.contactNameandcontactPhone, to a create-only client — chased and dismissed. I probed a narrowed and a plain create: both do, so it is notselect-related.src/plugins/eventImport/csv/columns.ts:46then records that those three fields are published as entered, because a seeker needs a reachable person, and clients hold read on events regardless — so nothing is disclosed thatGET /api/eventswould not give.Detail
Why
syncFullnesskeeps adocfallback. It runs on update as well as create, wheredatais only the patch — so a column that write did not touch is readable only fromdoc. No client holds update on this collection, so the narrowable half is the create, whichdatacovers completely.Why
syncCommunityFeedbackchanged but has no test. It is not reachable:eventFeedbackdeclaresupdate: () => falseandsystemFieldAccess.create, so a client's value is deleted fromdatabefore the hooks run, and the vote's one writer is the feedback page's server action passing noselect. The read followsdatafor consistency withgateEventFeedbackdirectly above it, which already did, and so the unit guard holds for the whole collection. Said so at the line rather than implying a fourth hole.Why the unit guard reads source text. It is the repo's existing idiom (
admin-condition-fields,sanitized-config-rules,custom-cell-drawer-select-coverage). Each of these bypasses was a one-word fix, so a reviewer will not catch the next one. Its limit is stated in its own docblock: a read reachingdocthrough a local alias is invisible to it.Perf figures. The guard is the 242nd unit spec, and
tests/PERF.mdpins that count against the tree — so the lane went red on its own file count, which is what that pin is for. The case count was already 14 behind before this branch. No timing was re-measured.Pipeline note.
/simplify's four lenses ran before the sibling-hook commit;/code-review highand/security-reviewran over the full branch. The review round changed no executable line, so neither was re-run.pr-review-toolkitis not installed in this environment.Ticket checklist drift. The verification checklist names
tests/int/atlas-manager.int.spec.ts, whichmainhas since renamed toevent-registrations.int.spec.ts, and says the repeat-registration spec has 10 cases — it now has 12.Closes #1093
🤖 Generated with Claude Code
https://claude.ai/code/session_01Mg9rjZCvvJ6ufDPXM1YJsE