2FA back link: review fixes — views guarded by object, client views, a loud stale import map
SB-1: the 2FA package replaces a view that already stands under its keys, so a key that existed before the factory ran was wrongly treated as the project's own and left unguarded (also with a double registration, or ipalKit over its own output). Views are now compared by object, right after the factory. SB-2: SafeTotpView renders through Payload's RenderServerComponent: a client component set as a 2FA view gets only client props plus the checked back. SB-3: a production build with the previous import map shows an empty 2FA screen. twoFactor.importMapCheck (on, production only) reads the committed map at start: an error in the log and a message on the 2FA screens. Docs name the real symptom. SB-4: enabled: false restores admin.dependencies; wrapTotpViews keeps exportName. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
93e75426ab
commit
ad51456eaa
+36
-3
@@ -587,8 +587,8 @@ leading spaces, `data:`, `https://other.example`, `//other.example`, `/\other.ex
|
||||
always a path, never an absolute URL. An absolute `back` on the site's own origin is accepted only when the
|
||||
config has `serverURL`.
|
||||
|
||||
- **On by default** with `twoFactor`. After upgrading run `pnpm payload generate:importmap` and commit
|
||||
`importMap.js`; without it the two screens fail with `[ipal] The admin import map has no "…"`.
|
||||
- **On by default** with `twoFactor`. **After upgrading run `pnpm payload generate:importmap` and commit
|
||||
`importMap.js`** — see "A stale import map" below for what happens otherwise.
|
||||
- **Your own rule:** `twoFactor: { …, safeBack: (back, { adminRoute, origin }) => string }`. It gets the raw value
|
||||
(`undefined` when absent or repeated) and returns where to go. Return a path on your own origin.
|
||||
- **Off:** `twoFactor: { …, safeBack: false }` — the package's views exactly as it registers them. Only when a
|
||||
@@ -598,6 +598,38 @@ config has `serverURL`.
|
||||
the serverProp `ipalTotpView: '<import-map path of the view to render>'` and list that path in
|
||||
`admin.dependencies`).
|
||||
|
||||
**Which views are guarded.** Every view the injected 2FA factory registers on the routes `setup-totp` and
|
||||
`verify-totp`, whatever stood under its keys before. The package replaces a view the project has under the keys
|
||||
`SetupTOTP`, `SetupTOTPBackslash`, `VerifyTOTP` or `VerifyTOTPBackslash`, so such a view is the package's, and
|
||||
guarded. The same holds when the project also lists `payloadTotp(...)` in `plugins` itself.
|
||||
|
||||
**Your own 2FA screen.** Two ways, both keep the check:
|
||||
- Through the wrapped factory (the pattern from "Resetting 2FA"): set `views.VerifyTOTP.Component` (or `SetupTOTP`)
|
||||
on the config the factory returns. ipal-kit puts `SafeTotpView` in front of it. A server component gets every
|
||||
server prop with `searchParams.back` checked. A client component (`'use client'`) gets Payload's client props,
|
||||
your `clientProps`, and `back` plus `searchParams` — both checked; read `back` from the props, not from
|
||||
`useSearchParams()`, which still holds the raw query value.
|
||||
- From a plugin listed after `ipalKit`, or under another key or route: that view is yours and is not wrapped. Use
|
||||
`wrapTotpViews` or `safeAdminBack` in it.
|
||||
|
||||
**A stale import map (read this before upgrading a site with 2FA).** The check needs the import-map entry
|
||||
`@intecion/ipal-kit/admin#SafeTotpView`. A production build made with the import map of the previous version
|
||||
passes, the site starts, and the 2FA setup and verify screens come back **empty** (HTTP 200, no code form), so nobody can sign in to the panel. Payload renders nothing for a path its map lacks; the only trace is
|
||||
`getFromImportMap: PayloadComponent not found in importMap` in the server log. Development is not affected (Payload
|
||||
regenerates the map there). ipal-kit makes this loud in three places:
|
||||
- **Before deploy:** `pnpm exec ipal-doctor` reports `import map lacks @intecion/ipal-kit/admin#SafeTotpView` (error).
|
||||
- **At every start in production:** the log has `[ipal] The admin import map is out of date: … The 2FA setup and
|
||||
verify screens are EMPTY …`.
|
||||
- **On the screen:** instead of nothing, the 2FA screens say "Two-step verification is not available" and what a
|
||||
developer has to run (shown by `TotpRedirectProvider`; with your own `twoFactor.provider` it gets the clientProp
|
||||
`staleImportMap`, with `provider: false` there is only the log line).
|
||||
The check reads `importMap.js` where Payload looks for it (`admin.importMap.importMapFile`, else
|
||||
`app/(payload)<admin route>/` or `src/app/(payload)<admin route>/` under `admin.importMap.baseDir` or the working
|
||||
directory). A file it cannot find is never reported. `twoFactor: { …, importMapCheck: false }` turns the file read,
|
||||
the log line and the message off. **Fix:** `pnpm payload generate:importmap`, commit `importMap.js`, rebuild, redeploy.
|
||||
A second error exists for the opposite case — the wrapper is in the map but the package's view is not:
|
||||
`[ipal] The admin import map has no "@clocklimited/payload-2fa/rsc#TOTPVerify"` (same fix).
|
||||
|
||||
**Check:** log in with the password only, open
|
||||
`/admin/verify-totp?back=https%3A%2F%2Fexample.com%2F`, enter the code: you must land on `/admin`, not on
|
||||
example.com. With `back=%2Fadmin%2Fcollections%2Fpages` you must land on that list.
|
||||
@@ -700,7 +732,8 @@ size while reading, content signature, container and macro checks, an optional `
|
||||
|
||||
- **Verify limit:** `twoFactor.verifyLimit: { max, windowMinutes }`, or `false`.
|
||||
- **`back` link check of the 2FA screens:** `twoFactor.safeBack: false`, or a function as your own rule;
|
||||
`safeAdminBack`, `wrapTotpViews`, `SafeTotpView` are exported.
|
||||
`safeAdminBack`, `wrapTotpViews`, `SafeTotpView` are exported. The stale import-map warning that comes with it:
|
||||
`twoFactor.importMapCheck: false`.
|
||||
- **2FA check:** per entity `custom.ipal.secondFactor` / `custom.totp.disableAccessWrapper` (one operation or
|
||||
all); `twoFactor.guard: false` turns ipal-kit's own second-factor check off everywhere (not recommended);
|
||||
`requireSecondFactor` / `secondFactorPassed` are exported for your own access functions and endpoints.
|
||||
|
||||
Reference in New Issue
Block a user