diff --git a/reference/.agents/skills/iapl-debug/SKILL.md b/reference/.agents/skills/iapl-debug/SKILL.md index 064c5f3..0ae5243 100644 --- a/reference/.agents/skills/iapl-debug/SKILL.md +++ b/reference/.agents/skills/iapl-debug/SKILL.md @@ -34,7 +34,7 @@ through this procedure. Ask only when you are missing something you cannot get y ### Build / TypeScript | Symptom | Cause | Fix | |---|---|---| -| the 2FA code screen answers "Too many codes were tried…" (`429` from `/api/verify-totp`) | more than 5 verify attempts for that account in 10 minutes (`twoFactor.verifyLimit`); repeated lines `[iapl] 2FA: too many verify attempts` in the log without the owner trying = someone has the password | wait for the window, enter the current code once; unexplained attempts: change that account's password. Tests that log in often: `verifyLimit: { max: … }` for that environment | +| the 2FA code screen answers "Too many codes were tried…" (`429` from `/api/verify-totp`) | more than 5 wrong codes for that account in 10 minutes (`twoFactor.verifyLimit`; right codes do not count since 1.17.1). "…being checked right now. Try again in a moment." (`Retry-After: 2`) = several attempts of one account at the same moment, nothing is locked; repeated lines `[iapl] 2FA: too many verify attempts` in the log without the owner trying = someone has the password | wait for the window, enter the current code once; unexplained attempts: change that account's password. Tests that log in often: `verifyLimit: { max: … }` for that environment | | `isAdmin(req.user)` says `false` for a real administrator on the server, in a process that loads two Payload configs (tests, a multi-site script) | a call without a source counts only collections that are staff in **every** config of the process | pass the source: `isAdmin(req.user, req.payload)` — with it each config gets its own answer | | `isAdmin(user)` / `isEditor(user)` is always `false` in a client component or in `proxy.ts` | the staff collections are not known there (no config in the browser bundle / middleware), and the predicates fail closed | `isAdmin(user, config)` with `useConfig()`, imported from `@intecion/ipal-kit/client`; in middleware `isAdmin(user, { staffCollections: ['users'] })` | | `next build --webpack`: `'server-only' cannot be imported from a Client Component module … caused by importing '@intecion/ipal-kit/dist/index.js'` | a `'use client'` file imports the main entry (Turbopack lets it pass) | import from `@intecion/ipal-kit/client` (role predicates are there since 1.16.7; types: `import type` from the main entry is fine); data the browser needs → a prop from a server component | diff --git a/reference/.agents/skills/iapl-reference/SKILL.md b/reference/.agents/skills/iapl-reference/SKILL.md index 6351c4b..e31bb2f 100644 --- a/reference/.agents/skills/iapl-reference/SKILL.md +++ b/reference/.agents/skills/iapl-reference/SKILL.md @@ -51,8 +51,8 @@ description: Complete map of everything @intecion/ipal-kit provides — every ia | `twoFactor.importMapCheck` | on | production only: at start searches the `importMap.js` on disk (where Payload looks for it) for `@intecion/ipal-kit/admin#SafeTotpView`; when not found, logs `[iapl] The admin import map may be out of date …` and IAPL's `TotpRedirectProvider` puts the notice "Two-step verification may not be available" above the 2FA screens (never instead of them). A hint only — the map in the build can differ from the file on disk (Dockerfile runner stage, re-exporting map); a file that is not found is not reported | `false` = no file read, log line or notice | | `twoFactor.texts` | IAPL's en/pl texts (`TOTP_TEXTS`) over the package's; 2FA screens titled "Two-step verification" / "Weryfikacja dwuetapowa" (site's language) | `false` = the package's texts; one text: `i18n.translations..totpPlugin.` (security.md) | | `twoFactor.guard` | on | IAPL's own second-factor check on every collection and global (also the plugin's own and those of plugins listed after iapl) and in `userMeetsRole`; startup fails with `[iapl] twoFactor: the injected 2FA plugin did not add …` when the 2FA package lacks the `totp` strategy / `hasTotp` / `totpSecret` | per entity: `custom.ipal.secondFactor: false` / `{ read: false }` or the package's `custom.totp.disableAccessWrapper.`; `false` = the package's wrapper only (the plugin's own data then opens to a password without the code; not recommended). The package's endpoints stay limited to accounts of the 2FA collection either way | -| `twoFactor.verifyLimit` | `{ max: 5, windowMinutes: 10, store: 'database' }` | attempts per account on `POST /api/verify-totp` (the 2FA package counts none): the sixth in the window, right or wrong, gets `429` + `Retry-After`. Counted in memory and in the database (`payload.kv`, the `payload-kv` collection Payload adds), so a restart or a second instance does not reset it; a failing store never opens the gate | `{ max, windowMinutes }`; `{ store: 'memory' }` = this instance only; `false` = no limit | -| `twoFactor.sameOrigin` | on | `POST /api/verify-totp` and `/api/setup-totp` refuse (`403`, not counted) a request a browser marks as coming from another origin (`Origin`, else `Sec-Fetch-Site`). Own origins: the request's host (`Host`, `X-Forwarded-Host`, a default port written out is ignored), `serverURL`, Payload's `csrf` / `cors`. Requests without those headers pass. A refusal is logged once per origin with how to allow it — behind a proxy that hides the address set `serverURL` | `{ origins: ['https://app.example.com'] }` adds origins; `false` = off | +| `twoFactor.verifyLimit` | `{ max: 5, windowMinutes: 10, store: 'database' }` | wrong codes per account on `POST /api/verify-totp` (the 2FA package counts none): after five wrong ones in the window the next attempt, right or wrong, gets `429` + `Retry-After`; a right code gives its place back (1.17.1); an attempt held out only by others still being checked gets `429` + `Retry-After: 2`. Counted in memory and in the database (`payload.kv`, the `payload-kv` collection Payload adds), so a restart or a second instance does not reset it; a failing store never opens the gate | `{ max, windowMinutes }`; `{ store: 'memory' }` = this instance only; `false` = no limit | +| `twoFactor.sameOrigin` | on | `POST /api/verify-totp`, `/api/setup-totp` and (1.17.1) the admin's `/api/ipal/two-factor/reset` refuse (`403`, not counted) a request a browser marks as coming from another origin (`Origin`, else `Sec-Fetch-Site`). Own origins: the request's host (`Host`, `X-Forwarded-Host`, a default port written out is ignored), `serverURL`, Payload's `csrf` / `cors`. Requests without those headers pass. A refusal is logged once per origin with how to allow it — behind a proxy that hides the address set `serverURL` | `{ origins: ['https://app.example.com'] }` adds origins; `false` = off | | `twoFactor.requireSetup` | on, `{ windowHours: 72 }` | an account without TOTP reaches nothing but the setup screen and `/api/setup-totp` (REST, GraphQL and the panel's data answer 403); it has `windowHours` from its creation or from an admin's reset, then it is blocked until an admin reopens setup. Adds the field `totpSetupStatus` (panel) to the 2FA collection, a dashboard notice and `POST /api/ipal/two-factor/reset`; the date field `totpSetupFrom` is there whenever 2FA is on (also with `requireSetup: false` / `guard: false`). Existing accounts get their window at the first start after the upgrade, written once. **Postgres/SQLite: the migration must be applied when the new container starts — `prodMigrations` or `pnpm payload migrate && pnpm start`, not a pre-deployment command (deployment.md §4.3) — or every login answers 500**; `generate:importmap`. `exempt` must return exactly `true` at once (an `async` one, or a `windowHours` that is not a number / `false`, stops the start) | `false` = the package's rule (API open until setup); `{ windowHours: 24 }`, `{ windowHours: false }` (no limit), `{ exempt: ({ user }) => … }` (a service account) | | `twoFactor.requireSetup.dashboardNotice` / `.statusField` / `.setupNotice` | on | the administrators' notice on the dashboard; the status and reset control on the account page; the notice on the setup screen | `false` each (the lock and the reset endpoint stay) | | `twoFactor.resetAccess` (the endpoint exists with `twoFactor.guard` on; `guard: false` = no endpoint, 404) | a staff admin whose session entered its own TOTP code (not an API key, not an `exempt` account) | who may reset another account's TOTP / reopen its setup (the button on the account page, `POST /api/ipal/two-factor/reset`). The reset clears the secret and the account's sessions. A session that still owes its code is always refused | `({ req }) => boolean` — replaces the rule, so keep `req.user?._strategy === 'totp' &&` in it unless API-key / exempt admins should reset; only `true` allows; `req.user._strategy` tells `'totp'`, `'api-key'`, `'local-jwt'` apart | diff --git a/reference/.agents/skills/iapl-reference/resources/api.md b/reference/.agents/skills/iapl-reference/resources/api.md index 182ce98..500b89e 100644 --- a/reference/.agents/skills/iapl-reference/resources/api.md +++ b/reference/.agents/skills/iapl-reference/resources/api.md @@ -75,7 +75,7 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `writeOnlySecret(field, options?)`, `writeOnlySecrets(fields, names, optionsByName?)`, `maskSecretAfterRead`, `keepSecretBeforeValidate`, `buildKeepSecret(options?)`, `SECRET_MASK`, `SECRET_CLEAR`, `isSecretMask(value)`, `INTEGRATION_SECRET_FIELDS`, `SMTP_PASSWORD_BOUND_TO` | `@intecion/ipal-kit` | Write-only secret fields (`secrets.writeOnly`): the wrapper for one field and for named fields anywhere in a tree (tabs, rows, groups); the two field hooks (reads through access control get `'********'`, the Local API with access control off gets the value; a save with nothing / empty / the mask keeps the stored value, `'[[clear]]'` removes it); the hook builder with options — `{ boundTo: ['siblingField'], appliesWhen?: (siblingData) => boolean }`: a save through access control that changes a bound sibling field without sending the secret throws a `ValidationError` on the secret (`secrets.reenterOnChange`); the two constants; the plugin's own secret field names (`smtpPassword`, `turnstileSecretKey`); the fields the SMTP password is bound to (`smtpHost`, `smtpPort`, `smtpUser` — not the transport: the mail adapter may fall back to SMTP). | | `maskSecretsOnRestore`, `maskWriteOnlySecrets(data, fields)` | `@intecion/ipal-kit` | Versions and write-only secrets: the `afterRead` hook for a global or a collection (a restore answers with the version document, fields under `version`, where field hooks do not run — it masks them there for reads through access control); the walker it uses (masks every write-only field in `data`, following tabs, rows, groups, arrays and blocks). On Site integrations by default; add the hook to your own entity that has both. | | `requestFromOwnOrigin(req, extraOrigins?)`, `ownOrigins(req, extraOrigins?)`, `reportRefusedOrigin(req, extraOrigins?)` | `@intecion/ipal-kit` | `twoFactor.sameOrigin`: `false` when a browser marks the request as coming from another origin (`Origin` not among the request's host, `serverURL`, `csrf`, `cors`, the extras; a default port written out on the host is ignored; else `Sec-Fetch-Site` not `same-origin` / `none`); `true` without those headers. `ownOrigins` → `{ hosts, origins }`. `reportRefusedOrigin` writes one log line per refused origin and process (at most 50) with the ways to allow it, and returns whether it wrote. For your own state-changing endpoint. | -| `buildVerifyLimit(collection, { max?, windowMinutes?, store?, keyPrefix? })`, `verifyLimitKey(collection, id, keyPrefix?)`, `clearVerifyLimits()` | `@intecion/ipal-kit` | `twoFactor.verifyLimit`: `async (req) => Response \| null` — counts an attempt of `req.user` in memory and, unless `store: 'memory'`, in `payload.kv`; a `429` with `Retry-After` past `max`. The kv key of an account's count; emptying the in-memory counts (tests). | +| `buildVerifyLimit(collection, { max?, windowMinutes?, store?, keyPrefix? })`, `verifyLimitKey(collection, id, keyPrefix?)`, `clearVerifyLimits()` | `@intecion/ipal-kit` | `twoFactor.verifyLimit`: `async (req) => Response \| null` — takes a place for an attempt of `req.user` in memory and, unless `store: 'memory'`, in `payload.kv`; a `429` with `Retry-After` past `max` (`Retry-After: 2` when only attempts still being checked hold it). `limit.settle(req, correct)` after the check: a right code gives its place back (unsettled = wrong). The kv key of an account's count; emptying the in-memory counts (tests). | | `turnstileSecretFromEnv(integrations)`, `TURNSTILE_SECRET_ENV` | `@intecion/ipal-kit` | `true` when the Turnstile secret in use comes from the environment because the panel field is empty (**deprecated** path; the doctor's `turnstile-env-key`); the variable's name, `'TURNSTILE_SECRET_KEY'`. | | `userMeetsRole(req, minimum)` | `@intecion/ipal-kit` | Predicate → `boolean` with `req` (`{ payload, user }`), in this order: the account belongs to a **staff collection** (`admin.user`, `access.authCollection`, `access.staffCollections`); with 2FA on it has passed the second factor (`secondFactorPassed`); it has a role ≥ `minimum`, **or** its collection has no `roles` field (the project omitted `access`). An account of any other auth collection never passes, whatever fields it has. The plugin's staff features (Site integrations, settings globals, form submissions, consent records, stats, cookie scanner, the e-mail test) use it; use it in your own endpoints. | | `staffCollectionSlugs(source?)` | `@intecion/ipal-kit` | `string[]`: the staff collections — `admin.user`, `access.authCollection` and `access.staffCollections` — from `req.payload`, a config or `{ staffCollections }`; without an argument what the configs built in this process agree on (`[]` when there is none). Roles and staff checks count only for accounts of these. | @@ -619,7 +619,7 @@ Server only (`pnpm payload run`); never import it from client code, the Payload | `SAFE_TOTP_VIEW` / `totpViewImportKey(component)` | `@intecion/ipal-kit` | `'@intecion/ipal-kit/admin#SafeTotpView'`, the wrapper's import-map path (the default `wrapper` of `wrapTotpViews`); and the import-map key (`path#export`) of a component given as a string or `{ path, exportName }`. | | `findImportMapFile(config, cwd?)` / `missingImportMapEntries(config, entries, cwd?)` | `@intecion/ipal-kit` | Where the project's `importMap.js` is on disk (`admin.importMap.importMapFile`, else `app/(payload)/` or `src/app/…` under `admin.importMap.baseDir` / the working directory; `null` when not found), and which of `entries` its text does not contain (`{ file, missing }`). A hint from the file on disk, not the map in the build: warn on it, never block on it. Behind `twoFactor.importMapCheck`. | | `buildSetupFields({ statusField? })`, `stampSetupFrom`, `backfillSetupFrom(payload, collection)` | `@intecion/ipal-kit` | The parts of "2FA setup required" for a project that wires them itself: the fields for the 2FA collection (`totpSetupFrom`, and the panel's `totpSetupStatus` unless `statusField: false`), the `beforeChange` hook that stamps the window start (on create, and when an account loses its TOTP secret), and the start-up step that gives accounts without TOTP and without a start their window (returns how many; once per account). | -| `buildTwoFactorResetEndpoint(collection, { access? })`, `TWO_FACTOR_RESET_PATH` | `@intecion/ipal-kit` | `POST /api/ipal/two-factor/reset` `{ userId }`: clears the account's TOTP secret and sessions and starts a new window. Default: a staff admin whose session entered its own TOTP code; `access` replaces that (only `true` allows; a session that owes its code is always refused). `iapl` registers it only with `twoFactor.guard` on. | +| `buildTwoFactorResetEndpoint(collection, { access?, ownOrigin? })`, `TWO_FACTOR_RESET_PATH` | `@intecion/ipal-kit` | `POST /api/ipal/two-factor/reset` `{ userId }`: clears the account's TOTP secret and sessions and starts a new window. `ownOrigin(req)` false → `403` before anything changes (the plugin passes the `twoFactor.sameOrigin` rule; wire `requestFromOwnOrigin` when you build it yourself). Default: a staff admin whose session entered its own TOTP code; `access` replaces that (only `true` allows; a session that owes its code is always refused). `iapl` registers it only with `twoFactor.guard` on. | | `countAccountsWithoutTotp(payload, collection, setupWindowMs?)` | `@intecion/ipal-kit` | `{ without, blocked }` — accounts of the 2FA collection without TOTP, and how many are past their window. | | `resolveRequireSetup(option)`, `strictExempt(fn)`, `SETUP_FROM_FIELD`, `DEFAULT_SETUP_WINDOW_HOURS` | `@intecion/ipal-kit` | `twoFactor.requireSetup` → `{ requireSetup, setupWindowMs, exempt? }` as the guard reads it (throws on a `windowHours` that is not a number ≥ 0 or `false`, and on an `async` `exempt`); the wrapper that makes an `exempt` function answer `true` only for exactly `true`; the field name `'totpSetupFrom'`; `72`. | | `fetchPublicImage(url, base)`, `publicImageDataUri(url, base)`, `rasterImageType(bytes)`, `siteOrigin(serverURL)`, `PUBLIC_IMAGE_MAX_BYTES` | `@intecion/ipal-kit` | An image fetched the way an anonymous visitor gets it (no cookies; http(s) only; `image/*`; at most 512 KB, reading stops at the limit) as `{ bytes, type }` or a `data:` address, else `null`. Used for the logo and icon on the 2FA screens. `rasterImageType(bytes)` → the media type of a bitmap by its first bytes (PNG, JPEG, GIF, WebP, ICO, AVIF) or `null` — never trust a claimed type before answering a file's bytes from the site's origin; an SVG gives `null`. | diff --git a/reference/.agents/skills/iapl-setup/SKILL.md b/reference/.agents/skills/iapl-setup/SKILL.md index 8857e7c..78453e9 100644 --- a/reference/.agents/skills/iapl-setup/SKILL.md +++ b/reference/.agents/skills/iapl-setup/SKILL.md @@ -228,7 +228,7 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo `[iapl] twoFactor…` unless `allowCollectionMismatch: true`. The second factor covers every collection and global (the plugin's own, and those of plugins listed after `iapl`) and the plugin's endpoints; guard your own endpoints with `secondFactorPassed(req)` or `userMeetsRole(req, role)` (security.md "What the second factor covers"). - Verify attempts: 5 per account in 10 minutes (`twoFactor.verifyLimit`). + Verify attempts: 5 wrong codes per account in 10 minutes (`twoFactor.verifyLimit`); right codes do not count. The `back` link of the setup and verify screens is checked on the server (`twoFactor.safeBack`, on by default: only a path inside the admin route is kept; `false` turns it off, a function replaces the rule). It needs the import map entry `@intecion/ipal-kit/admin#SafeTotpView` — run `pnpm payload generate:importmap` and commit @@ -246,7 +246,9 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo (column `totp_setup_from`, there whenever 2FA is on) — without it every login answers 500; `pnpm payload generate:importmap` (`TwoFactorStatusField`, `TwoFactorAlert`). A service account that logs in with a password: `requireSetup: { exempt }` (a plain function - returning exactly `true`; never `async`); an API key needs nothing. Parts to switch off: `requireSetup: + returning exactly `true`; never `async`), deciding from a field only an admin can write (`serviceAccount` + checkbox with `adminOnlyField`; security.md "Decide `exempt` from a field only an administrator can write"), + never from the e-mail — every account may change its own e-mail; an API key needs nothing. Parts to switch off: `requireSetup: { dashboardNotice: false, statusField: false, setupNotice: false }`. An admin's reset ends the account's sessions and needs the admin's own TOTP code (`twoFactor.resetAccess` changes who). Have two administrators with 2FA: when all are blocked, only a script or a redeploy helps (security.md "Every administrator is diff --git a/reference/.agents/skills/iapl-upgrade/SKILL.md b/reference/.agents/skills/iapl-upgrade/SKILL.md index 53fe0a2..4bd9e93 100644 --- a/reference/.agents/skills/iapl-upgrade/SKILL.md +++ b/reference/.agents/skills/iapl-upgrade/SKILL.md @@ -413,7 +413,10 @@ site without steps 1–3 and a deploy day agreed with the owner. Steps 2, 3 and `[iapl] 2FA: the column for "totpSetupFrom" is missing … NOBODY CAN LOG IN`. `pnpm exec iapl-doctor` reports it before the deploy. MongoDB: nothing. 4. An integration that logs in with a password and has no TOTP: give it an API key, or - `twoFactor.requireSetup: { exempt: ({ user }) => user.email === '…' }`. `grep -rn "overrideAccess: false" src`: + `twoFactor.requireSetup: { exempt: ({ user }) => user.serviceAccount === true }` with a checkbox only admins can + write (`access: { create: adminOnlyField, update: adminOnlyField }`) — not by e-mail: every account may change its + own e-mail (security.md "Decide `exempt` from a field only an administrator can write"). A project already on an + e-mail list (1.17.1): move to the field, or make `email` admin-only. `grep -rn "overrideAccess: false" src`: a `user` fetched by id is refused for every account now — take it from `payload.auth({ headers })`. 5. `rm -rf .next`, build, redeploy on Coolify. Read the first lines of the log: `[iapl] 2FA: N existing account(s) without two-step verification…` — pass that number to the owner. The line appears on that first start only.