Repository navigation
feat(auth): admin-triggered resend of a manager's verification email - #691
sydevs-bot wants to merge 5 commits into
Conversation
Closes #680. A manager whose verification email bounced, spam-foldered or was dropped by Resend had exactly one rescue: an admin setting `_verified` by hand in the database, which skips verification rather than performing it. Payload ships no resend operation — its auth surface is forgotPassword / login / logout / me / refresh / resetPassword / unlock / verifyEmail, and `payload.verifyEmail` CONSUMES a token rather than issuing one — and the upstream request has sat unassigned since 2024 (payloadcms/payload#7701), so waiting was not a plan. Shape (a) from the ticket: an admin-only row action, not a public "resend" on the login screen. That choice is the entire security model — no public surface means no account-enumeration oracle and no email-bomb amplifier pointed at an address the caller names, so no Turnstile and no rate limiter to get right. A public variant needs all three and is a different ticket. The email is rendered by the collection's own `auth.verify.generateEmailHTML`, read off the sanitized config rather than re-implemented. Payload's internal `sendVerificationEmail` does this job but is not exported from the package root, and reaching into `dist/` would couple us to its build layout. Rendering from the config is what makes drift impossible — and that drift is exactly what #320 was: a verify link missing its collection slug, which fails SILENTLY because `isPublicAdminRoute` waves any `/verify/` path past the auth gate. The token write is what revokes the old link: the column holds one value, so the previous email stops verifying the moment the new one lands. The admin gate runs BEFORE that write, so a refused caller cannot invalidate the outstanding link of the manager it declined to help. No migration: a `ui` field is not persisted and `_verificationToken` is an existing auth column. `pnpm generate:types` produces no diff, and the integration lane's full-schema push succeeds against the changed config. Tests: six cases in tests/int/manager-verification.int.spec.ts, extending the #320 loop rather than starting a new file. Every one was watched FAILING with the defect reintroduced at the site that would really cause it — token reuse instead of rotation, a hand-written email in place of the template, the already-verified guard dropped, the admin gate dropped, the admin gate moved to AFTER the token write, and the id validation dropped. The non-admin case was itself vacuous first: `undefined` as the caller fell through to the test helper's default parameter and ran as the admin, so it passed for the wrong reason until it was changed to `null`. Fixture pre-mortem: the specs assume the test Payload carries the REAL Managers `auth.verify.generateEmailHTML`, since "the resend renders the same email the create path does" is the property under test and a stub would make it vacuous. Verified in tests/utils/testHelpers.ts:53-65 — `getTestCollections` maps over the real `collections` export and only rewrites `upload` on UPLOAD_COLLECTIONS, which `managers` is not. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014oQ3V1YBH5pnFvprMCbB6A
…nager-verification
Both findings from the security review of this PR's endpoint. **A dropped email reported success, after destroying the old token.** `payload.sendEmail` does not throw here: every failure path in `resendAdapter` returns instead, deliberately, because the same adapter runs inside the manager-create transaction where a throw would roll the account back. So the endpoint's try/catch was dead code for the ordinary delivery failure — a missing RESEND_API_KEY, a Resend outage — and the sequence was: rotate the token (revoking the link the manager may already be holding), drop the message, log "re-sent", return 200. That is the #320/#675 silent email failure, reintroduced on the path built to rescue it. The adapter's three drop paths now return `{ ok: false, reason }` alongside the Sentry capture they already made. It is a return value, not a throw, so the non-fatal contract is unchanged and every existing caller — all of which ignore the result — behaves exactly as before. Only an explicit `ok: false` counts: Payload's console adapter stands in wherever email is unconfigured and resolves undefined, which must keep reading as sent. The endpoint restores the previous token when it sees a drop, rather than merely reporting one. A failed resend now leaves the manager exactly as it found them, with any outstanding link still working, and answers 502 saying so — which is strictly better than telling an admin to retry an account they have just locked out of its own rescue. **The password hash was being handed to the email template renderer.** `showHiddenFields: true` returns `hash`, `salt` and `resetPasswordToken` too, and the whole object was spread into the `user` passed to `generateEmailHTML`, whose output is emailed. Nothing reads them — `VerifyEmail` takes `name` and `email` — so this was never exploitable, but it is live credentials crossing into a renderer one careless template edit from mattering, and it is wider than Payload's own create path, which passes the post-afterRead doc with hidden fields stripped. Now an explicit projection of id / name / email / collection / the new token. The new assertion was watched failing twice, at both sites that would really cause it: ignoring the drop (the behaviour above) leaves the token rotated, and reporting the drop without restoring leaves it rotated too. Both go red; neither half of the assertion is decorative. Also verified since the review, which flagged it as unchecked: the route is genuinely reachable and the gate genuinely fires on a real HTTP request. Against a booted dev server, `POST /api/managers/1/resend-verification` with no credentials answers 403 while `POST /api/managers/1/no-such-endpoint` answers 404 — so the path is registered, `routeParams.id` arrives, and the 403 is this handler rather than a catch-all. The integration specs call the handler directly and cannot see any of that. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014oQ3V1YBH5pnFvprMCbB6A
|
🚅 Deployed to the SahajCloud-pr-691 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
This is the ticket's shape (a), built where the ticket said to build it, and the load-bearing choice — rendering the email from the collection's own auth.verify rather than a second copy — is right, and is what makes the #320 drift class structurally impossible here rather than merely absent. The admin-only gate genuinely is the security model: with no public surface there is no enumeration oracle and no amplifier, and the endpoint reaches for the same isAdminManager predicate the rest of the codebase uses. The specs are unusually strong — eight defects watched failing, one of them proving the gate runs before the token write, which is the assertion most people skip.
My one shape-level doubt is that a single decision generates roughly a third of the diff, and I cannot find what it buys. Rotating the token instead of re-sending the existing one is what creates the drop-detection problem — and the { ok: false } returns in resendAdapter, the new docs/rules/email.md section, the restore branch, the 502 and two of the eight defects all exist to solve it. The same secret goes to the same address, and this endpoint cannot change the address, so rotation's only reliable effect is to kill a link the recipient may still be holding. AC 3 asks for it, but that AC is loop-authored; the human approval was "Let's implement this". Worth settling deliberately rather than inheriting.
Everything else is small and local: three casts that restate what payload-types.ts already declares, one .find() over config.collections where Payload has a typed accessor, a comment that has the wrong field hidden, and a ui field with no admin.condition.
Findings
- should-fix — Token rotation is the source of most of this diff's complexity, and re-sending the existing token removes the failure mode instead of defending against it — plus a gap in the restore guarantee if rotation stays (thread,
resendVerification.ts:112). - should-fix —
req.payload.collections.managers?.config.auth?.verifyreplaces the linear scan, the cast and the extra type import (resendVerification.ts:96-100). - should-fix —
Manageralready declares_verifiedand_verificationToken, andGeneratedTypesis augmented, so& { _verified }and bothas Partial<Manager>casts restate the generated type (resendVerification.ts:81,:124,:170). - consider — The
showHiddenFieldscomment names the wrong field, and the client component depends on the opposite being true; aselectwould also retire the hand-written projection (resendVerification.ts:70-78). - consider — Export the adapter's result type instead of retyping its shape at the call site (
resendVerification.ts:159-161). - consider — The
uifield has noadmin.condition, so non-admin managers are offered a button that can only 403;adminOnlyConditionexists for this (Managers.ts:79-89).
No blockers. Nothing here touches a cross-repo contract: managers is admin-only, in no project, absent from CUSTOM_ENDPOINT_PATHS (checked — set-project is too, so the precedent holds), and pnpm generate:types produces no diff, so no consumer repo's types:cms sync is affected.
What was checked
- Ticket and its thread — #680 including all three comments, to separate what the human approved ("Let's implement this", 2026-09-03) from what the loop's own ticket and follow-up comment assumed. That separation is the basis of the rotation finding.
- The diff — all 8 files,
origin/main...origin/claude/feat-resend-manager-verification(526+/7−), read whole rather than as a diff. - Payload's installed source, since three of this PR's claims are assertions about it:
payload/dist/auth/baseFields/verification.js—_verifiedis a checkbox withdefaultAccessread;hidden: trueis on_verificationTokenonly. This contradicts the endpoint's comment at :70-72 and is what the fourth finding rests on.payload/dist/auth/baseFields/auth.js— confirmshash/salt/resetPasswordTokenare the hidden fields the projection warning is about.payload/dist/index.js:415-416anddist/email/types.d.ts—payload.sendEmailreturns the adapter's value unwrapped, so the drop mechanism does work;EmailAdapter<T>is generic butPayload['sendEmail']is not, so the call-site cast is unavoidable.payload/dist/email/consoleEmailAdapter.js— resolvesundefined, soresult?.ok === false(not!result?.ok) is correct, as both comments claim.payload/dist/collections/config/types.d.ts:690anddist/index.d.ts:251—payload.collections[slug].configis the typed lookup the endpoint hand-rolls.payload/dist/collections/operations/local/update.d.ts:25—dataisDeepPartial<RequiredDataFromCollectionSlug<TSlug>>, so no cast is needed.
- The consumer side of the component's assumption —
@payloadcms/next/dist/views/Document/getDocumentData.js:23-33fetches withoutshowHiddenFields, which is why the_verifiedquestion is a real one and not pedantry.@payloadcms/ui'sDocumentInfotypes confirminitialDataexists and is optional. - This repo's own rules and precedents —
docs/rules/endpoints.md(admin-only endpoints may skiprequireActiveClientif they say why: this one does; OpenAPI registration is required for client-facing endpoints only),docs/rules/access.mdpluspermissions.ts:88andconfig/projects.ts:171-175(which is how I established that a non-admin manager can read another manager),adminOnly.ts(isAdminManageristype === 'admin', so an inactive admin is not a thing and the guard is sound),setProject.tsas the sibling endpoint, andpayload-types.ts:1358-1359/:7157. - Not run: no tests, no typecheck — this checkout is detached at
origin/mainwith the PR branch fetched read-only. The three type findings are argued from the declarations above rather than from a compiler run, so treat them as questions iftscdisagrees.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
| return denied('Verification email is not configured.', 500) | ||
| } | ||
|
|
||
| const token = generateVerificationToken() |
There was a problem hiding this comment.
Is rotating the token actually wanted here? It is the one decision that generates most of this PR. The { ok: false, reason } returns in resendAdapter, the new docs/rules/email.md section, the restore branch at 163–183, the 502, and two of the eight watched-failing defects all exist to stop a dropped send from leaving a manager with a revoked link and nothing in its place.
Re-sending manager._verificationToken unchanged — minting only when it is null — removes that failure mode instead of defending against it: a dropped send would change nothing, so there would be nothing to restore, and the endpoint would be a read plus a send. As far as I can tell rotation buys nothing in exchange: the same secret goes to the same address it was already sent to, and this endpoint cannot change the address, so the only thing rotation reliably does is invalidate a link the recipient may still be holding (spam-foldered, not lost). AC 3 in #680 does ask for rotation, but that AC is loop-authored — the approval on the ticket was "Let's implement this", not a ruling on token lifetime.
Push back if rotation is deliberate — a stale link living forever is a defensible thing to dislike. But it should be a decision someone made, not a line item that quietly costs a third of the diff.
Secondary point, only if rotation stays: the restore payload.update at 167 sits inside the same try, so if it throws, control lands in the catch at 184 and returns the generic 500 — token rotated, not restored, and that copy says nothing about the link that just died. "A failed resend leaves the manager exactly as it found them" holds for a dropped send but not for a failed restore.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
There was a problem hiding this comment.
Splitting this thread: the secondary point is fixed in a141c75; the rotation question is left open for @Ardnived, because it is a decision rather than a defect.
Fixed — the failed-restore hole. You are right that payload.update at 167 sat inside the outer try, so a restore that itself threw landed in the catch and answered the generic 500 ("Could not send the verification email. Please try again.") — describing a no-op, for the one outcome where the manager is genuinely worse off than before the call. It has its own catch now and returns a 502 that says the earlier link has been revoked and another must be sent. This holds whichever way the rotation question goes, which is why it did not wait on it.
Watched failing at the site that causes it, per the repo's rule: with the inner catch removed the new case reports expected 500 to be 502. tests/int/manager-verification.int.spec.ts — "says the link was revoked when the RESTORE itself fails". It also asserts the restore was attempted (updates === 2), so the case cannot pass by the rotation write throwing instead.
Open — should the token rotate at all? I have not changed this, and I do not think a run should decide it. The argument stands as written: the same secret goes to the same address, this endpoint cannot change the address, so rotation's one reliable effect is to kill a link the recipient may still be holding — and it is what generates the { ok: false } return, the restore branch, the 502, the docs/rules/email.md section and two of the eight watched-failing defects. Re-sending manager._verificationToken unchanged (minting only when null) would delete that whole failure mode rather than defending against it.
What stops me acting on my own argument is that AC 3 of #680 asks for rotation, and I wrote AC 3. Your approval on the ticket was "Let's implement this", not a ruling on token lifetime, so the loop treating its own acceptance criterion as authorisation to keep it — or to drop it — is the loop grading its own homework either way.
So:
the two things that would change if you say "don't rotate"
resendVerification.tsloses the rotation write,previousToken, the restore branch (both catches), and the 502 — roughly a third of the file.resendAdapter.ts's{ ok: false, reason }returns andEmailSendResultwould have no consumer left. I would keep them: the adapter reporting a drop is right independent of who reads it, anddocs/rules/email.mddocuments it as the contract. But the endpoint would stop being the reason they exist.
Not affected either way: the admin gate, the template-from-config rendering, the 409/404/400/422 paths, and six of the eight defect cases.
A stale link living forever is a defensible thing to dislike, so "keep rotation" is a fine answer — I only want it to be an answer.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
Five of the six threads on #691, all raised by the loop's own adversarial review. The sixth — whether rotating the token is wanted at all — is a decision rather than a defect and is left open for the reviewer. **A failed restore no longer reports that nothing happened.** The restore write sat inside the outer `try`, so a restore that itself threw landed in the generic 500 ("Could not send … please try again") — for the single outcome where the manager is genuinely worse off than before the call, holding a link that has been revoked and not replaced. It now has its own catch and a 502 whose copy says the link was revoked. Watched failing at that exact site: with the inner catch removed the new case reports `expected 500 to be 502`. **The read is projected by the framework, and its comment was wrong.** `_verified` is not a hidden field — `payload/dist/auth/baseFields/ verification.js` puts `hidden: true` on `_verificationToken` alone and leaves `_verified` an ordinary checkbox with `defaultAccess` read. The old comment claimed the opposite, and `ResendVerification.tsx` depends on the truth: it reads `_verified` off a document the admin view fetches *without* `showHiddenFields`. A `select` now keeps `hash`, `salt` and `resetPasswordToken` out of the document entirely, which is the guarantee the twelve-line warning above the hand-written projection was standing in for. **Three restatements of generated types removed.** `Manager` already declares `_verified` and `_verificationToken` (`payload-types.ts:1358-1359`) and the `GeneratedTypes` augmentation makes `payload.update`'s `data` already `DeepPartial<Manager>`, so the intersection and both `as Partial<Manager>` casts said nothing the compiler did not know. Same in the spec's `tokenOf`. **`req.payload.collections.managers?.config.auth?.verify`** replaces the linear scan over `config.collections` plus its cast and type import — `Collection['config']` is `SanitizedCollectionConfig` already. **`EmailSendResult` is exported** from the adapter instead of retyped structurally at the call site, so a fourth drop path reaches this reader through the compiler. The cast stays: the `EmailAdapter` generic does not reach `payload.sendEmail`. **The `ui` field gains `adminOnlyCondition`.** `managers` is not in `RESTRICTED_COLLECTIONS`, so a non-admin manager can read a colleague's document and was being offered a button that could only ever 403. Gate: lint, typecheck, typecheck:tests, test:unit (120 files / 1564 specs) and the targeted `manager-verification` int spec (8 cases) all green. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KhLvw4PKkZTMqSppPDU3k8
|
Five of the six review threads are closed in The open one: should the verification token rotate at all? (thread). Rotation is what generates the drop-detection machinery — the adapter's One real defect came out of the round. The restore write sat inside the outer The other four were the corrections you'd expect: a comment that named the wrong field ( Gate, and one thing deliberately not doneLint, typecheck, typecheck:tests, Not done: moving the button to the sidebar. It was raised in the same thread as the 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
Closed for now, we want to explore an alternative where users are sent invitations instead of verifications |
) Rewrites every in-scope prose file (67 of 69 flagged by the audit) into strict Simplified Technical English and retires D1/Cloudflare Workers-era debris three months after the Postgres/Railway migration. Tracked *.md (excluding CLAUDE.md symlinks and the vendored .agents/skills/payload/ skill, left untouched pending ownership confirmation) drops from 770,090 to 600,797 chars (22%). The five hot-path files auto-imported every session (AGENTS.md, docs/architecture.md, docs/environment.md, docs/code-style.md, .claude/workflow.json) drop from 84,492 to 36,397 chars (57%). Deleted (dead, zero referrers, grepped clean): seed-issues-report.md, src/migrations/README.md (its one fact folded into src/migrations/AGENTS.md). Merged: DEPLOYMENT.md + RAILWAY_RUNBOOK.md split by lifecycle (how it runs today vs. provision-from-scratch/disaster-recovery), resolving their D1-decommission contradiction — PR #468 (merged 2026-06-08) confirms the Worker is gone, so the stale "Remaining (gated)" TODOs are removed, not reworded. Legacy debris fixed (D1/SQLite/Cloudflare-Workers-as-current retired): migration-reviewer.md's whole persona rewritten for Postgres/Drizzle, seeds/wemeditate/AGENTS.md's Dual-Database table corrected to Postgres, src/globals/AGENTS.md's json_array() rationale corrected to Postgres's real FUNC_MAX_ARGS=100 limit, docs/mcp-setup.md's cloudflare-docs row drops Workers/D1. grep for D1|SQLite|Cloudflare Workers across .claude/agents/, seeds/wemeditate/, src/globals/, docs/mcp-setup.md is clean. README.md's stale `cd sy-devs-cms` corrected to `cd SahajCloud`. Mandatory AGENTS.md fixes applied: dropped the nonexistent `pnpm test:e2e`, replaced the broken dev-server.sh path with the `/workflow:dev-server` skill, fixed the seeds/atlas/MIGRATION_PLAN.md:103 anchor (now resolves to `AGENTS.md#website-selection-rules-584`), collapsed duplicate PR-workflow/test-tier prose into single pointers to testing-reqs.md and the finalize-pr skill. Traps preserved (compressed, never deleted): the conflicted-PR "zero CI" diagnostic with its docs/why.md anchor and #632/#653 numbers; the Cache Rule authorization-header predicate and root-endpoint fix; DB_QUERY_LOGGING and TURNSTILE_SECRET_KEY footguns; storage.md's preview/prod asset-isolation risk; the payload-cli silent-exit/hang ladder; the migration snapshot out-of-order duplicate-re-emission trap; access.md's per-locale-roles gotcha (#665); endpoints.md's root-endpoint hook gap; email.md's two- token-URL-shapes bug; seeds/atlas/AGENTS.md's silent-rollback-on-trashed- relation trap; the never-name-a-global-field-locales rule. The 2026-08-27 dated Admin Access exception is kept (still current). Comment sweep: rewrote comments to STE in every file the audit flagged as touched (route.ts's mandatory dead-comment deletions, r2NativeAdapter.ts, Icon.tsx, scalarPlugin.ts, env/server.ts, localizedRolesAuth.ts, plus the full tests/seeds/scripts/.claude/root-config/.github sweep — 227 files total). Verified comment-only: every changed line in every .ts/.tsx/.mjs/ .cjs/.sh/.py file has an identical code portion before its comment marker; zero functional changes. Deleted a dead `sharp` import and several doc- duplicating/obvious comments (e.g. vitest.setup.ts's two narrate-the- obvious lines). Verification run as finisher: pnpm lint, typecheck, typecheck:tests, and the full unit lane (1564 tests) all pass, plus targeted integration specs for every touched collection/access path (events, regions, role-based- access — 79 tests, live Postgres). ste-lint.py run on all 40 changed .md files: hard violations cut from 169 to 118, concentrated in five already- dense reference docs (admin-ui/api-clients/email/endpoints/openapi/ storage.md) where the prior compression pass already prioritized fidelity over the linter's raw sentence-length cap; remaining flags are verified domain terms (Railway's "Health Check", Zod's "Validate", literal HTTP methods GET/DELETE, SQL "cascade delete", TS "type erasure") or residue in those five files. rule-delta.mjs vs main on AGENTS.md/docs/rules/*.md/ migration-reviewer.md: 3 directives flagged REMOVED, all three verified as de-bolded (not deleted) — "GET /api/events/geojson always excluded, no opt-out" (api-clients.md) and the two CPU parallel-test-run rules (testing-reqs.md) all still present as plain bullets/cells, content identical. 1 flagged ADDED is the same pass-by-reference comment rule gaining full-sentence bold (previously invisible to the tool since only "Do not" was bold). Sequencing: PRs #692 (UNKNOWN), #686 (BLOCKED, not CONFLICTING), #691 (CLEAN) show no current CONFLICTING/DIRTY state, so this PR is not blocked today, though #692/#691 touch overlapping files and should land or be watched. securityReview trigger paths (access/, storage/, api routes, webhook scripts) all confirmed comment-only. Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Five of the six threads on #691, all raised by the loop's own adversarial review. The sixth — whether rotating the token is wanted at all — is a decision rather than a defect and is left open for the reviewer. **A failed restore no longer reports that nothing happened.** The restore write sat inside the outer `try`, so a restore that itself threw landed in the generic 500 ("Could not send … please try again") — for the single outcome where the manager is genuinely worse off than before the call, holding a link that has been revoked and not replaced. It now has its own catch and a 502 whose copy says the link was revoked. Watched failing at that exact site: with the inner catch removed the new case reports `expected 500 to be 502`. **The read is projected by the framework, and its comment was wrong.** `_verified` is not a hidden field — `payload/dist/auth/baseFields/ verification.js` puts `hidden: true` on `_verificationToken` alone and leaves `_verified` an ordinary checkbox with `defaultAccess` read. The old comment claimed the opposite, and `ResendVerification.tsx` depends on the truth: it reads `_verified` off a document the admin view fetches *without* `showHiddenFields`. A `select` now keeps `hash`, `salt` and `resetPasswordToken` out of the document entirely, which is the guarantee the twelve-line warning above the hand-written projection was standing in for. **Three restatements of generated types removed.** `Manager` already declares `_verified` and `_verificationToken` (`payload-types.ts:1358-1359`) and the `GeneratedTypes` augmentation makes `payload.update`'s `data` already `DeepPartial<Manager>`, so the intersection and both `as Partial<Manager>` casts said nothing the compiler did not know. Same in the spec's `tokenOf`. **`req.payload.collections.managers?.config.auth?.verify`** replaces the linear scan over `config.collections` plus its cast and type import — `Collection['config']` is `SanitizedCollectionConfig` already. **`EmailSendResult` is exported** from the adapter instead of retyped structurally at the call site, so a fourth drop path reaches this reader through the compiler. The cast stays: the `EmailAdapter` generic does not reach `payload.sendEmail`. **The `ui` field gains `adminOnlyCondition`.** `managers` is not in `RESTRICTED_COLLECTIONS`, so a non-admin manager can read a colleague's document and was being offered a button that could only ever 403. Gate: lint, typecheck, typecheck:tests, test:unit (120 files / 1564 specs) and the targeted `manager-verification` int spec (8 cases) all green. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KhLvw4PKkZTMqSppPDU3k8
Closes #680.
A manager whose verification email never arrived can now be rescued with a button instead of a database edit. Payload ships no resend operation — its auth surface is
forgotPassword / login / logout / me / refresh / resetPassword / unlock / verifyEmail, andpayload.verifyEmail()consumes a token rather than issuing one — so the only fix was an admin ticking_verifiedby hand, which skips verification rather than performing it. The upstream request (payloadcms/payload#7701) has sat unassigned since 2024.An unverified manager's edit view gains Resend verification email; a verified one gets nothing at all, rather than a disabled control.
⚠ One open question for the reviewer: should the token rotate?
This is the only thing outstanding, and it is a decision rather than a defect — see the thread. Rotating the token is what generates the drop-detection machinery: the
{ ok: false }returns inresendAdapter, the restore branch, the 502, thedocs/rules/email.mdsection, and two of the nine watched-failing defects. Re-sending the existing token unchanged would remove that failure mode rather than defend against it, since the same secret goes to the same address either way and this endpoint cannot change the address.AC 3 of #680 asks for rotation, but that acceptance criterion is loop-authored — the approval on the ticket was "Let's implement this". Either answer is defensible; the loop should not pick it on its own authority. Everything else on the PR is settled.
Shape (a) from the ticket, and that choice is the security model
Admin-only, not a public "resend" on the login screen. No public surface means no account-enumeration oracle and no email-bomb amplifier pointed at an address the caller names — so there is no Turnstile and no rate limiter here to get subtly wrong. A public variant needs all three and is a different ticket.
Two things worth reading the diff for
The email is rendered by the collection's own
auth.verify.generateEmailHTML, read off the sanitized config rather than reimplemented. Payload's internalsendVerificationEmaildoes this job but is not exported from the package root, and reaching intodist/would couple us to its build layout. Rendering from the config is what makes drift impossible — and that drift is exactly what #320 was: a verify link missing its collection slug, which fails silently, becauseisPublicAdminRoutewaves any/verify/path past the auth gate.A dropped send no longer revokes a working link.
payload.sendEmaildoes not throw here — every failure path inresendAdapterreturns instead, deliberately, since the same adapter runs inside the manager-create transaction where a throw would roll the account back. So atry/catchalone would have reported success for a message that was dropped, after rotating the token. The adapter's three drop paths return{ ok: false, reason }beside the Sentry capture they already made, and the endpoint puts the previous token back and answers 502.Only an explicit
ok: falsecounts as a drop: Payload's console adapter stands in wherever email is unconfigured and resolvesundefined, which must keep reading as sent. That union is exported asEmailSendResultrather than retyped at the call site.Review round — six threads, five closed
What the adversarial review found and what changed in
a141c75tryshowHiddenFieldscomment named the wrong field_verifiedis an ordinary checkbox;hidden: trueis on_verificationTokenalone (payload/dist/auth/baseFields/verification.js). The admin edit view depends on that, since it fetches without the flagselect.hash/salt/resetPasswordTokennever enter the document, so the guarantee is structural rather than a warning commentconfig.collectionsreq.payload.collections.managers?.config.auth?.verify— the cast and theSanitizedCollectionConfigimport went with itManageralready declares both fields andpayload.update'sdatais alreadyDeepPartial<Manager>. Both typecheck lanes pass without the castsuifield had noadmin.conditionmanagersis not inRESTRICTED_COLLECTIONS, so a non-admin manager could read a colleague's document and was offered a button that could only 403.adminOnlyConditionis the same predicate the endpoint callsField placement (sidebar vs mid-form) was raised and deliberately not changed: a UX judgement about a screen nobody has looked at, and the one suggestion here with no way to check itself.
Review aids
Preview: Railway builds the per-PR environment on push. The surface is
POST /api/managers/:id/resend-verificationplus the button on/admin/collections/managers/:idfor an unverified manager — a fresh preview may have none, in which case create one to see the control.Test results
pnpm lint, ✓pnpm typecheck, ✓pnpm typecheck:tests, ✓pnpm test:unit— 120 files / 1564 specsmanager-verification— 8 cases, greenuifield is not persisted,_verificationTokenis an existing auth column, andselectis a read option.pnpm generate:typesproduces no difforigin/mainmerged in, so this is tested against feat(atlas): give the unowned remainder a sitemap via a canonical fallback client #676 and refactor(types): derive schedule, region level and verification types from payload-types #681Every assertion was watched FAILING — nine defects, each at the site that would really cause it
try(this round)expected 500 to be 502One assertion was vacuous first, and this is the useful part. The non-admin case passed
undefinedas the caller, which fell through to the test helper's default parameter and ran the case as the admin — a 200 read as a pass. It isnullnow, with a comment saying why.read() ?? fallbackin a spec is the local shape of this.The new case guards against the same trap from the other side: it asserts the restore was attempted (
updates === 2), so it cannot pass by the rotation write throwing instead.Security review — what it found, and the reachability check it could not make
A security review ran (the change touches
src/collections/Managers/andsrc/collections/*/endpoints/, bothsecurityReview.triggerPatternpaths). It found the gate sound — no unauthenticated caller, ordinarymanager,inactivemanager or APIclientcan reach any effect; the 403 is returned beforerouteParamsis read, so there is no enumeration oracle; the token is 160 CSPRNG bits matching Payload's own create path; nothing carries a token into a log, a response or a Sentry capture. Both of its findings were fixed in8582348: the dropped-send defect above, andshowHiddenFields: truehandinghash/salt/resetPasswordTokento the template renderer. That second one is now closed at the framework rather than by hand — see theselectrow above.It flagged one thing as unverifiable from source: the specs call
resendVerification.handler()with a hand-built request, so routing and real auth population are exercised by nothing. Checked against a booted dev server:POST /api/managers/1/resend-verification, no credentialsPOST /api/managers/not-a-number/…POST /api/managers/1/no-such-endpoint(control)Fixture pre-mortem
The specs assume the test Payload carries the real
Managers.auth.verify.generateEmailHTML— "the resend renders the same email the create path does" is the property under test, and a stubbed template would make it vacuous. Verified intests/utils/testHelpers.ts:53-65:getTestCollections()maps over the realcollectionsexport and only rewritesuploadonUPLOAD_COLLECTIONS, whichmanagersis not, so the collection reaches the test config untouched.Manual verification
🤖 Written by the sydevs autonomous loop — see what this is
🤖 Generated with Claude Code
https://claude.ai/code/session_01KhLvw4PKkZTMqSppPDU3k8