Repository navigation
feat(managers): let the support account sign in as a manager - #1271
Conversation
The admin whose email is CONTACT_EMAIL can act as any active, non-admin manager in the real admin, to reproduce a permission problem as that manager sees it. A support-impersonation auth strategy, ahead of localized-roles, swaps in the target named by a signed cookie bound to support's own session, re-checking both accounts on every request. Saves go through as the manager. Their own row, saved preferences and project switcher are left untouched, the refresh re-signs support's own token, and a banner with Exit sits across every admin page. One log line at start and exit; nothing stored and no notice to the manager. Local auto-login now reads CONTACT_EMAIL instead of a second spelling. Co-Authored-By: Claude Opus 5.5 <[email protected]>
From the /simplify and /code-review passes over the branch: - Sign-out while impersonating now ends support's own session. Payload's logout removed the target's session instead, so support's outlived it. - A bulk managers write is refused while impersonating; it names no row, so its where could reach the manager's own. - A refused cookie answers with support themself and clears itself, instead of authenticating the same JWT twice on every request. - One afterRead hook carries the cookie's project and impersonatedBy onto every read of the impersonated row, replacing the /me and refresh copies. - The refresh re-signs through signSessionToken, extracted from createSession; the strategy reuses authenticateJWT, the JWT half of the localized-roles strategy, so support's roles are no longer loaded. - The start button moves into the plugin, the preferences guard into its own module wired from the payload-preferences policy, and the logout cookie clear out of middleware. - Start and Exit handle a failed request; startImpersonation lets a database error reach the error handler instead of answering 404. - The cookie keeps for the browser maximum, so it never ends an impersonation on its own; the gate's docblock states the accepted admin-email gap; the false plugin-order constraint is gone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cumented Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🚅 Deployed to the SahajCloud-pr-1271 environment in sahajcloud
1 service not affected by this PR
|
Giving a manager CONTACT_EMAIL through the admin or the API is refused, so another admin cannot take the support role by moving the address onto their own account. The row that holds it keeps it, and a seed or script with no user is not judged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The feature earns its place and works through Payload's own seams. But it is the largest shape the problem allows: AGENTS.md tables six Payload defaults this plugin overrides, and one choice forces all six — support's own session stays underneath. The repo already signs in as an arbitrary manager (createSession), and nothing says why that was rejected. Second total: a per-collection plugin wrapper beside loginPlugin, which already wires the same collection and keys generically.
Findings
should-fix— an unverified manager passes the start gate, then is refused every request (gate.ts)should-fix— the session-underneath choice, unweighed against minting the target's (cookie.ts)should-fix— "see the docblock" heads nothing since the split (localizedRolesAuth.ts)should-fix— Streamline ×8 — threads onplugin.ts,gate.ts,strategy.ts,ImpersonateButton.tsx,AGENTS.mdconsider—mayImpersonatenames the target as the actor (gate.ts)consider—accessPlugindeep-imports impersonation for a one-callerextend(systemEntities.ts)consider—signSessionToken's exported path skips the guard its comment cites (session.ts)
What was checked
Read whole: the 8 plugin modules, both components, localizedRolesAuth.ts, session.ts, systemEntities.ts, setProject.ts, loginPlugin.ts, both specs and the doc edits. Streamliner: 33 pieces covered, 19 kept, 8 of 10 sketches held — the two dropped remove behaviour this PR's int spec pins. It ran before 5d6cbfd, so supportAddress.ts was walked by hand: it holds, on Payload's own EmailFieldValidation. Previews: both ON_HOST, ids 1001001/1001002 in src/fixture/managers.ts. All 16 paths the body names exist on it. No payload-types.ts or atlas file in the diff: no consumer side.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
Splitting `localizedRolesAuth`'s strategy into `authenticateJWT` and `hydrateAuthUser` left the block documenting both heading neither: it sat above `withLocalStrategyView`, which carries its own docblock underneath it, so `authenticateJWT`'s "see the docblock" pointed at an orphan. Its two numbered failure modes had parted too. The wrong-collection guard is `authenticateJWT`'s and the swallowed-hydration catch is `hydrateAuthUser`'s, so each now sits on the function that owns it, as do the two ⚠ notes about Payload's JWT verifier. Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWXoV8n2EP7jtbJs6
`signSessionToken` reads `user.email!` on the guarantee that Payload adds `sessions` and `email` in the same branch of `getAuthFields`. That held while `createSession` was its only caller and ran the `sessions` check first; `refreshImpersonatorToken` now calls it directly, so the invariant the file opens with — that a token minted for a collection without `sessions` authenticates nobody — went unenforced on the exported path. The check moves into one `sessionCapableConfig`, which both call. `createSession` still runs it first so a refused collection costs neither its read nor its session write. Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWXoV8n2EP7jtbJs6
`mayImpersonate` read `type` alone, and `startImpersonation`'s `select` omitted `_verified`, so an invited manager who never confirmed their email passed the start: support got a 200 and a cookie, reloaded, and was still support with nothing said. Payload's JWT strategy yields no user while that flag is false, and `readTarget` refused on it one layer later. The gate now asks for both, so the start refuses what every request would, and the endpoint selects the column. `readTarget`'s own `auth.verify` clause goes with it — one place decides, and the gate asks unconditionally rather than only where the collection configures verification. The button reads `_verified` from form state beside `type`; the column is a real checkbox field on `Managers`, so it is there. Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWXoV8n2EP7jtbJs6
`impersonationPlugin` was a second per-collection wrapper over the one collection `loginPlugin` already wires, hard-coded to `'managers'` where the login plugin keys generically on its `collections` option and spreads `auth`, `fields`, `beforeOperation`, `endpoints` and `admin.components` per entry. Both features are ways into the admin panel, so one plugin now owns the collection. The modules move to `src/plugins/login/impersonation/`, wired on the `managers` entry beside invitations, which is gated the same way and for the same reason: both read columns only `Managers` has. `plugin.ts`, the barrel and the two config entries go; `setImpersonatedProject` is exported from the login barrel instead, and `hooks.ts` reaches `signSessionToken` relatively rather than through that barrel. The strategy is still prepended, so it still runs ahead of the `localized-roles` strategy `accessPlugin` appends — stated now in `loginPlugin`'s own register-before-accessPlugin note. The sidebar button is declared inline in the field list, its only use. `login-plugin.spec.ts` grows `MANAGER_ROUTES`: the impersonation routes now sit in the literal allowlist of auth routes this plugin wires, and the admin-components assertion names the header slot the banner is appended to. Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWXoV8n2EP7jtbJs6
A preview's own admin is now [email protected], CONTACT_EMAIL's default and the address production uses, so a reviewer signed in as it can try support impersonation on the fixture managers. Previews send mail through Mailpit, so the address receives nothing from them. A unit case pins the constant to CONTACT_EMAIL. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`GateUser` and `Impersonator` re-declared five stored columns by hand, and loosely: `type?: string | null` where `Manager['type']` is a three-value union, so `mayImpersonate`'s `'manager'` literal was unchecked and so was every fixture and call site that spelled one. Both now derive from `Manager`. `id` stays `number | string` on purpose — Payload types an authenticated user's id that way whatever the collection's own column is — and `collection`, `_sid` and `impersonatedBy` stay their own, since no manager row carries them. The button's `useFormFields` read casts to `Manager['type']` rather than `string`, which is the one place the looseness was load-bearing. Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWXoV8n2EP7jtbJs6
`IMPERSONATION_COOKIE` sat in the client-safe module, but no client reads it: `cookie.ts` and the integration spec are its only callers. It moves there, leaving `gate.ts` holding the two predicates, the accessor and the types that genuinely cross the server/browser line. Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWXoV8n2EP7jtbJs6
`mayImpersonate(target)` read as "target may impersonate", where the subject is the target: it answers whether the target may be impersonated. `mayBeImpersonated` says that, and reads right at both call sites. Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWXoV8n2EP7jtbJs6
`createImpersonationStrategy()` took no argument and returned a constant. Its sibling `createLocalizedRolesStrategy(slug)` is a factory because it closes over a slug; this one closes over nothing, so it is now the constant it always was. `isBoundTo` had one caller and folded into the `const target =` condition it guarded, where the checks read in the same order. Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWXoV8n2EP7jtbJs6
… controls `ImpersonateButton` and `ImpersonationBanner` carried the same four lines each — a credentialed POST, a failure state, and a full page load — with the ⚠ note explaining the load duplicated verbatim. `postAndReload` is that shape once, beside `payloadListFetcher`; each caller keeps its own busy state and its own failure copy. `SignIn/SignInAsForm.tsx` is not a third caller: it sends a JSON body and decides success on a `token` in the response, not on `response.ok`, so a shared `ok`-based helper would navigate on a 200 that signed nobody in. Neither caller needs the `no-location-assign-relative-destination` disable any more — the rule reads a literal destination, and the helper takes the path as a parameter, which is why `SignInAsForm` never carried one either. Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWXoV8n2EP7jtbJs6
"How a request becomes the manager" and five of the six table rows restated docblocks in `strategy.ts`, `hooks.ts`, `endpoints.ts` and `preferences.ts`, mostly verbatim — so a behaviour-preserving move would have left the prose wrong with nothing failing. Both now name the files that hold the detail. The Tests section named the integration spec's cases one by one, which an added or renamed case makes false; it names the two spec files instead. Kept whole: the owner decisions, the token-claims ⚠, the first-time preference create, and the document-lock and Sentry caveats. Added one owner decision, which was the gap behind the shape: support's own session stays underneath, and why minting the target's own was rejected. Nothing said so, so the six stops below read as unforced. Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWXoV8n2EP7jtbJs6
`@/plugins/login`'s barrel reaches `@/plugins/access`'s through `loginPlugin` and the impersonation strategy, so importing it from `systemEntities` would close a cycle between the two plugin barrels. The deep import is the answer, and nothing said so. Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWXoV8n2EP7jtbJs6
…tion Brings in 5a7736c, which provisions the support account as the preview admin. Its one AGENTS.md addition — how to try the feature on a preview — lands in that file's new home under `src/plugins/login/impersonation/`, and the stale `src/plugins/impersonation` paths in `proxy.ts` and `.env.example` follow the move. Two docblocks still named the deleted `impersonationPlugin`; both now name `loginPlugin`. Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjYWXoV8n2EP7jtbJs6
|
All 14 critic threads answered: 12 adopted, 2 refused on facts. Base merged clean, plus 5a7736c. Adopted
Refused
Gate ✓, int specs ✓, security clean. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
|
The newest commit, 7b90f14, is sydevs-bot's own, so it is not approved on your behalf. Read it, then say 🤖 sydevs dispatcher |
InfoBanner gains `inline`: icon, title, description and action on one line, the action at the end. The impersonation banner sits above every admin page, so a two-line block cost height on each of them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Approved for Ardnived, who wrote it: GitHub refuses an author's own approval. CI is green and the automated review has run. Enable auto-merge when you want it merged: the queue tests it against its base. 🤖 Written by the sydevs autonomous loop — see what this is
Summary
CONTACT_EMAIL) can act as any active, non-admin manager in production.CONTACT_EMAILaddress through the admin or the API, so no other admin can take the support role.Change outline
Flow — every authenticated
managersrequestA new strategy runs ahead of
localized-roles. With no impersonation cookie it returns at once, so ordinary requests are unchanged.Contract — what changes for the support account and for an impersonated request
Files — where the pieces live
Preview
The preview's admin is now the support account (
PREVIEW_ADMIN_ADDRESSis[email protected], which isCONTACT_EMAIL). Pick it on the preview's sign-in page, then:[email protected]into his email shows the refusal.Test results
support-impersonation10 passed,login-plugin17. These also ran unchanged:preview-auto-signin11,role-based-access97,managers-access20,payload-system-access16,manager-passwordless11,manager-magic-link,manager-invite,impersonation-gate10,login-token,e2e-preview-constants.Manual verification
Done in a real browser (Playwright, local dev server, signed in as the support account). Every check passed:
currentProjectalone. A PATCH to the manager's own row answers 403.[email protected]into a manager's email shows the refusal.Notes for reviewer
CONTACT_EMAILwhile a user is signed in. Seeds and scripts with no user are not checked, which is how the support account is created.capture, which namesreq.user, so errors raised while impersonating report under the manager. Changing that is outside this PR.impersonation/AGENTS.md.keepImpersonatedPreferencesthrough the@/plugins/loginbarrel: that closes a cycle with@/plugins/access's.postAndReload), for the two callers whose shape matches.SignInAsFormis not a third: it succeeds on atokenin the response, not onresponse.ok.Detail
/simplify(four lenses) and/code-review highran over the branch. Thepr-review-toolkitplugin isn't installed./security-reviewfound no HIGH or MEDIUM issue.req.user's session. While impersonating, that is the target's session, so support's own session outlived sign-out. The test fails with the hook removed.refuseOwnRowWriteskeyed onargs.id, so a bulkwherewrite could reach the manager's own row.id,collectionorsidclaim and has its own audience, so it never reads as a session JWT. A session JWT never reads as the cookie either.🤖 Generated with Claude Code