diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 533e103..89e3da1 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,14 +10,19 @@ once there are more than 20. ## Unreleased — security follow-ups to 1.16.7 (version to be set at release) -> **Read before upgrading.** No option, schema, migration or import-map change. Two points: +> **Read before upgrading.** No option, schema, migration or import-map change. Three points: +> **A site built with Turbopack** (`next build` without `--webpack`) published the plugin's `package.json`: +> update and rebuild (see Security). > **What can stop people:** on a project's own staff collection **without access rules of its own** whose > accounts can hold `editor` or `admin` although its roles are not just the plugin's — a `roles` select such as > `user, editor, admin, boss` or `viewer, editor`, or a `roles` field that is text, json or a relationship (all > with `hasMany`, i.e. holding a list; a single-valued field is not affected) — an account that is > not an admin can no longer create, delete or unlock accounts there, change another account, or change > anybody's roles. If **no** staff account holds `admin`, nobody can (the start log says so; the way out is -> below). And a site **built with Turbopack** (`next build` without `--webpack`): see Security. +> below). +> **Only where a plugin listed after ipalKit copies a staff collection, or makes a collection of your config the +> panel's** (`admin.user`): some answers get narrower there — see "Requires project changes". No known site does +> either. ### Security - **A staff collection whose accounts can hold `editor` or `admin` gets the admin rules.** The plugin's checks go @@ -33,6 +38,21 @@ once there are more than 20. an admin; update — an admin or the account itself; roles — only an admin. Not affected: `access.authCollection`, collections with rules of their own, a `roles` select whose values hold neither `editor` nor `admin`. No known site has such a collection ([access.md](./access.md) "Account rules"). +- **A copy of a staff collection kept rules written for the original.** A plugin listed after ipalKit that + spreads a staff collection into another slug (`{ ...staff, slug: 'copy' }`) carried the "already handled" marker + and the plugin's rules along. "An admin, or the account itself" then meant the ORIGINAL's accounts: with + numeric ids (Postgres, SQLite) an account of the original could change the password of the account with the + same id in the copy. Now the plugin puts its rule for the copy's own slug **in front of** every rule it wrote + for the original, and both must allow; on a copy named as staff, in front of every rule. Nothing is replaced + or rewritten, so a copy is never opened wider than it was and never wider than the plugin's rule — whatever + role values it has and however it uses or wraps the copied rules. Its `roles` field is guarded on every copy. + The marker `custom.ipalAccounts` names the slug and the staff status (`{ slug, staff, own? }`). +- **A collection of the config that a later plugin makes the panel's had no account rules.** A collection that is + in your config, is not named as staff, and becomes the login collection because a plugin listed after ipalKit + sets `admin.user` to it counted as "already handled": where it had no rules of its own, Payload's defaults + stood — an account of any auth collection (a customer) could create, change and delete panel accounts there. + Now it gets the plugin's rules when the config goes live, for every operation that had **no** rule in your + config; an operation you wrote a rule for keeps it exactly as written (`AccountsMarker.own`). - **A Turbopack build of a site published the plugin's `package.json`.** The plugin read its own version from that file by a path relative to its module, and a bundler takes such a file for an asset: Turbopack copied it to `/_next/static/media/package..json`, where anyone could fetch it. It is the **plugin's** manifest, not @@ -43,14 +63,24 @@ once there are more than 20. server side: not served. The version is now a constant in the code (`src/version.ts`); nothing is read from disk at run time. + +### Fixed +- `next dev`: a collection that becomes a staff collection in an edit (named in `access.staffCollections` for + the first time) gets its rules on the reload; it needed a restart when its config object outlived the reload. +- A plain 2FA config guards nothing twice at start (the plugin's rules are marked before its 2FA guard). + ### Added - A start-log warning when staff collections run on the admin rules and no staff account holds `admin` (checked collection by collection; "could not check" where it cannot tell). - `pnpm e2e:built` (plugin repository): builds the reference site with webpack and with Turbopack and checks, - on each, the account rules on a built site and that no package manifest is among the public files. Part of - the release gate (PROGRAMISTA §8.1). The reference site's Playwright runs reset the test admins first - (`e2e/global-setup.ts`), so a spec no longer fails because of what ran before it. -- Exports: `canHoldStaffRole`, `rolesAreAList`, `staffCollectionsNobodyManages`. + on each, the account rules on a built site (copied staff collections included) and that no package manifest is + among the public files. Part of the release gate (PROGRAMISTA §8.1). The reference site's Playwright runs + reset the test admins first (`e2e/global-setup.ts`), so a spec no longer fails because of what ran before it. +- Exports: `canHoldStaffRole`, `rolesAreAList`, `staffCollectionsNobodyManages`, `staffRuleOf`, + `isPasswordRuleHook`; types `StaffRuleMark`, `AccountsMarker`. `markSeenAuthCollections(config, staffSlugs)` + takes the staff slugs; `LateAdoption` has `kept` and `known`. +- The start log tells a collection that became staff after ipalKit ran from one a later plugin added, and names + the rules of its own that were kept. ### Requires project changes - **A staff collection of your own, without access rules, whose accounts can hold `editor` or `admin`** (a @@ -69,6 +99,25 @@ once there are more than 20. - **A site built with Turbopack:** update and rebuild — the new build has no `package..json` under `/_next/static/media/`. Check: `find .next/static -name 'package*.json'` prints nothing. Nothing to do for a webpack build. +- **Only if a plugin of yours copies a staff collection** (`{ ...staff, slug: 'copy' }`, or a new collection that + reuses a staff collection's `access` object) — three answers get narrower: + - **The copy's own accounts and "the account itself".** In the copy, the copied rule "an admin, or the account + itself" lets only an admin through (it still speaks of the original's accounts). If the copy's own accounts + should edit themselves, give the copy its own rule — one line: + `access: { ...staff.access, update: adminOrSelfIn('copy') }` ([access.md](./access.md) "Account rules"). + Before this change those accounts could not edit themselves either. + - **A copy named as staff whose own rules were wider than the plugin's** — a public `read`, an open `create`, + a rule that returns a query, Payload's defaults where it dropped a rule: in 1.16.7 a copy counted as handled + and kept them; now the plugin's rule goes in front, so a customer or an anonymous request no longer passes. + To keep the copy's rules exactly as they are: `custom: { ipal: { accountRules: false } }` on the copy. + - **Where the original has roles of its own** (`lead, member`): its accounts could manage the copy's accounts + (create, change, delete) through the copied rule "an account of the original". They no longer can: only a + plugin admin manages the copy's accounts (the copy's own accounts could not before and cannot now), until + the copy writes rules of its own (`access.create` / `update` / `delete`). +- **Only if a plugin listed after ipalKit sets `admin.user` to a collection of your config that you did not name + as staff:** the operations that collection has no rule for get the plugin's (an admin; update — an admin or + the account itself; read — staff). Rules you wrote on it stay. Better: name it in `access.staffCollections` + (or list that plugin before ipalKit) — then it is handled at config time like any staff collection. - `pnpm ipal:skills`. ### Changed @@ -81,10 +130,6 @@ once there are more than 20. the value still grants nothing. ### Known limitations -- **Copied staff collections behave as in 1.16.7**: a plugin listed after ipalKit that spreads a staff collection - into a new slug (`{ ...staff, slug: 'copy' }`) keeps the rules written for the original, so with numeric ids - (Postgres, SQLite) the original's account with the same id can change the copy's account. Not changed in this - release; no known site copies a staff collection. - A staff collection **without a `roles` field** is unchanged: every account of it is an admin to the plugin. - A `roles` select of your own whose values hold neither `editor` nor `admin` is unchanged: inside it every account may create, change and delete accounts (`ipal-doctor --url` → `staff-own-roles`). @@ -96,6 +141,10 @@ once there are more than 20. they do. The admin rules apply to the collection either way. - The start-log check reads up to 1000 accounts of a collection whose `roles` field the database cannot be asked about; with more it says "could not check" for that collection. +- `next dev`: a collection that STOPS being a staff collection in an edit keeps the rules until a restart; after + a reload the adoption still runs with the options the site started with. +- A marker or a function mark written by hand in the project's own config is taken at its word ("handled" for a + marker of the collection's own slug); a hand-made function mark only ever adds the plugin's rule in front. ## 1.16.7 — hardening diff --git a/docs/access.md b/docs/access.md index d666d25..1e2c26c 100644 --- a/docs/access.md +++ b/docs/access.md @@ -355,6 +355,56 @@ is kept and can only narrow it. To keep a late collection's rules exactly as the wider `read` — say so on the collection: `custom: { ipal: { accountRules: false } }` (the password rule and the first-user endpoint still apply), or list that plugin before ipalKit. +**A collection of your own config that becomes staff later** — it is in the config, you did not name it as staff, +and a plugin listed after ipalKit sets `admin.user` to it — is handled at the same moment, with one difference: +the plugin saw it at config time and wrote down which operations had a rule of yours (the marker's `own`). **Those +rules stay exactly as written; an operation that had no rule gets the plugin's** — the same result as for a +collection named in `access.staffCollections`, and its `roles` field is guarded where the plugin's `update` rule +is the one in force. The log: `[ipal] "people" became a staff collection after ipalKit ran: put on it — access +rules for update, delete, unlock, read, readVersions, roles; the password rule. Its own rules for create are kept +as written.` Without rules of its own such a collection ran on Payload's defaults before (any signed-in account, +a customer included, created and changed panel accounts). Simpler and clearer: name the collection in +`access.staffCollections`, or list that plugin before ipalKit. Verify: sign in as an account of a non-staff +collection and `POST /api/` — 403 unless your own `create` rule lets it through. + +**A copy of a staff collection** — a later plugin that spreads one into a new slug (`{ ...staff, slug: 'copy' }`), +or a new collection that reuses a staff collection's `access` object — brings along rules the plugin wrote for +the ORIGINAL: "an account of `staff`", "the account itself" = one of the original's. The plugin sees them by a +mark it puts on its own functions (`staffRuleOf(rule)` → `{ slug, self }`; the mark counts only on the very +function it was made for, so a wrapper of yours around a plugin rule is your rule). What it does is one thing, +in every case: + +> **The plugin's rule for THIS collection goes in front of the rule that is there, and both must allow.** +> Nothing is replaced and nothing is rewritten. + +| The copy | Where the plugin's rule goes in front | +|---|---| +| named in `access.staffCollections` | of every rule — as on any late staff collection | +| not named as staff, or with `custom: { ipal: { accountRules: false } }` | only of the rules the plugin wrote for the original; your own rules there stay as they are | +| its `roles` field | guarded on every copy (the plugin's roles: only an admin changes them; others: never one's own) unless the field has an `access.update` of its own — then the guard goes in front only of a rule the plugin wrote for the original | + +So a copy is never opened wider than its rules were before, and never wider than the plugin's rule — whatever +role values it has, whichever operation it uses a copied rule for, however it wraps it. The original's account +with the same id is not "the account itself" in the copy. + +**The cost, and the one line that pays it:** a copied rule that says "an admin, or the account itself" still +means the ORIGINAL's accounts, so in the copy only an admin passes it — the copy's own accounts cannot edit +themselves until the copy says who may: + +```ts +import { adminOrSelfIn } from '@intecion/ipal-kit' +// in the plugin that makes the copy: +{ ...staff, slug: 'copy', access: { ...staff.access, update: adminOrSelfIn('copy') } } +``` + +A rule you write there is not marked, so on a staff copy it is combined with the plugin's rule for `copy` +("an admin, or the account itself" of the copy) and works. The password rule is on a copy once +(`isPasswordRuleHook`). The marker `custom.ipalAccounts` (`{ slug, staff, own? }`, type `AccountsMarker`) records which +collection the plugin has handled, whether as staff, and — for a collection that was not staff at config time — +which operations had a rule of the project's then (`own`): a copy carries the original's marker and is handled under +its own slug; in `next dev` a collection named as staff in an edit is handled on the reload. A marker for the +collection's own slug means "handled" — only your own config can write one, like `accountRules: false`. + **A slug in `access.staffCollections` or `access.authCollection` that is not an auth collection of the config:** Payload does not start. The log names the slug and the auth collections it knows. The process stays up, but every Payload call fails — `/api/health` answers 503, `/api/*` and the panel 500; a page that needs no Payload diff --git a/docs/agent/reference-site/INDEX.md b/docs/agent/reference-site/INDEX.md index d81e54a..aabe8e7 100644 --- a/docs/agent/reference-site/INDEX.md +++ b/docs/agent/reference-site/INDEX.md @@ -1164,8 +1164,8 @@ Rules: AGENT.md §8a. |---|---| | `e2e/create-test-admin.ts` | two test admins with a known TOTP secret (the specs share out the five 2FA verify attempts per account), their stored verify counts cleared, and e-mail sending pointed at the tests' mail sink (local / CI database only) | | `e2e/global-setup.ts` | Playwright global setup: resets the test admins and clears their stored 2FA attempt counts before every run, so specs do not depend on run order (below) | -| `e2e/late-staff-fixture.ts` | test fixture, on only with E2E_LATE_STAFF=1: one plugin before ipalKit (a staff collection of the config whose roles are the plugin's values plus one more) and one after it (a staff collection without rules, one whose roles field is text, a visitor collection with open sign-up) (below) | -| `e2e/late-staff.spec.ts` | the account rules on a BUILT site (run by `pnpm e2e:built` after a webpack and a Turbopack build): a staff collection a later plugin adds, and staff collections whose accounts can hold `admin` — a visitor account gets nothing, nobody raises its own role or makes an admin | +| `e2e/late-staff-fixture.ts` | test fixture, on only with E2E_LATE_STAFF=1: one plugin before ipalKit (staff collections of the config: roles with one more value, the plugin's roles, roles of the project's own) and one after it (a staff collection without rules, one whose roles field is text, copies of staff collections under new slugs — plain, with rules of their own, one rule used for another operation, other role values, the opt-out, not staff — and a visitor collection with open sign-up) | +| `e2e/late-staff.spec.ts` | the account rules on a BUILT site (run by `pnpm e2e:built` after a webpack and a Turbopack build): a staff collection a later plugin adds, staff collections whose accounts can hold `admin`, and copies of staff collections — a visitor account gets nothing, nobody raises its own role or makes an admin, a copy is never wider than the plugin's rule | | `e2e/smoke.spec.ts` | the smoke tests every release must pass: pages, showcase, forms (also a file sent by e-mail), sitemap, SEO/GEO, headers, consent, 2FA | | `e2e/smtp-sink.ts` | a local mail sink for the smoke tests: reads what the site really sent (recipients, attachments) | | `e2e/totp.ts` | RFC 6238 code generator for the 2FA sign-in in the smoke test, and the address of the second test admin (below) | @@ -1191,48 +1191,6 @@ export default function globalSetup(): void { } ``` -### `e2e/late-staff-fixture.ts` - -```ts -import type { Config, Plugin } from 'payload' - -/** - * Test fixture, on only with E2E_LATE_STAFF=1 (e2e/late-staff.spec.ts): a plugin listed AFTER ipalKit that adds - * a staff collection (`late-staff`, named in `access.staffCollections`) and a visitor collection with open - * sign-up. ipalKit has already run when these collections appear, so it must give them its account rules when - * the config goes live — and it must do so in a BUILT site too, where bundlers rename every function. - * Never part of a real site: the starter drops `e2e/` and the lines that use this file. - */ -export const E2E_LATE_STAFF = process.env.E2E_LATE_STAFF === '1' - -/** Slugs the fixture names as staff (payload.config.ts → `access.staffCollections`). */ -export const E2E_STAFF_SLUGS = ['late-staff', 'e2e-crew', 'e2e-late-text'] - -/** - * Listed BEFORE ipalKit: a staff collection of the project's own, without rules, whose roles are the plugin's values - * PLUS one more. `admin` on an account of it makes a plugin admin, so its accounts must not hand that value out. - */ -export const e2eEarlyStaff: Plugin = (config: Config) => - E2E_LATE_STAFF - ? { ...config, collections: [...(config.collections ?? []), { slug: 'e2e-crew', auth: true, fields: [{ name: 'roles', type: 'select', hasMany: true, options: ['user', 'editor', 'admin', 'boss'], saveToJWT: true }] }] } - : config - -export const e2eLateStaff: Plugin = (config: Config) => - E2E_LATE_STAFF - ? { - ...config, - collections: [ - ...(config.collections ?? []), - // no access rules at all: Payload's defaults ("any logged-in user") are what ipalKit must replace - { slug: 'late-staff', auth: true, fields: [{ name: 'roles', type: 'select', hasMany: true, options: ['user', 'editor', 'admin'], saveToJWT: true }], versions: true }, - // a late staff collection whose `roles` is a text field: any value can be written there, `admin` included - { slug: 'e2e-late-text', auth: true, fields: [{ name: 'roles', type: 'text', hasMany: true }] }, - { slug: 'e2e-visitors', access: { create: () => true }, auth: true, fields: [] }, - ], - } - : config -``` - ### `e2e/totp.ts` ```ts diff --git a/docs/agent/skills/ipal-debug/SKILL.md b/docs/agent/skills/ipal-debug/SKILL.md index c0268f2..a205f46 100644 --- a/docs/agent/skills/ipal-debug/SKILL.md +++ b/docs/agent/skills/ipal-debug/SKILL.md @@ -110,6 +110,7 @@ through this procedure. Ask only when you are missing something you cannot get y | an account saves its own profile and its `roles` do not change (no error) | `accounts.adminOnlyWrite`: nobody changes its own roles; with the plugin's roles only an admin changes roles | an admin changes the role; or give the `roles` field its own `access.update` | | a logged-in visitor (customer) gets `403` reading a staff collection — an author box went empty | `accounts.staffOnlyRead`: only staff accounts read a staff collection without a `read` rule | write that collection's `read` rule; or `staffOnlyRead: false` | | `/api/health` answers 503, the panel and `/api/*` 500 after a deploy; log: `[ipal] access names "…" as a staff collection, but this config has no auth collection with that slug` | a slug in `access.staffCollections` / `access.authCollection` is not an auth collection (a typo, a removed collection): Payload does not start, the process stays up (with a health check Coolify keeps the old container) | fix the slug or add the collection | +| the log says `"" became a staff collection after ipalKit ran` | a plugin listed after ipalKit set `admin.user` to a collection of your config that is not named as staff: the operations without a rule of yours got the plugin's, yours are kept (named in the same line) | name the collection in `access.staffCollections` (or `access.authCollection`), or list that plugin before ipalKit | | a collection added by a plugin listed after ipalKit refuses what its own access rule allows | it is in `access.staffCollections`: the plugin's account rules are put in front of its rules and both must allow (the log at start lists what was put) | `custom: { ipal: { accountRules: false } }` on that collection, or list that plugin before ipalKit | | a fresh site with `access.firstUserAdmin: false`: the first account sees "Unauthorized", or the start fails with `leaves a fresh site with nobody who can open the panel` | the first account gets the default role, below the panel role | `access.defaultRole: 'editor'`, or `accounts: { panelRole: false }`, or drop `firstUserAdmin: false` | | saving Site integrations fails on the password field: "Enter the password again…" | the server, port or user name changed and the stored SMTP password is kept only for the settings it was saved with — also when the transport says Microsoft Graph | type the password again; or "Remove the stored value" for a server without one; a seed with the Local API is not asked; `secrets: { reenterOnChange: false }` | diff --git a/docs/agent/skills/ipal-reference/resources/api.md b/docs/agent/skills/ipal-reference/resources/api.md index ada3950..57afbeb 100644 --- a/docs/agent/skills/ipal-reference/resources/api.md +++ b/docs/agent/skills/ipal-reference/resources/api.md @@ -68,7 +68,8 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `isEditor(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with `editor` or higher. | | `panelAccess(minimum?)`, `applyPanelRole(config, slug, role)`, `resolvePanelRole(option)`, `countBelowPanelRole(payload, slug, role)`, `DEFAULT_PANEL_ROLE` | `@intecion/ipal-kit` | `accounts.panelRole`: an `access.admin` function ("holds at least `minimum`", default `'editor'`; role only, not the second factor); the applier (skips a collection that has its own `access.admin`); the option → role or `null` when off; `{ all, below }` counts for the start-up line; `'editor'`. | | `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles(collection)`, `canHoldStaffRole(collection)`, `rolesAreAList(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, read?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead`: the access functions — "an admin, fully signed in" (create, delete, unlock); "an admin, or the account itself" (update; self = an account of THAT collection); "a fully signed-in account of a staff collection" (read); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); the two field-access functions for a `roles` field (`update`: only an admin / never the account itself); whether a collection carries the plugin's roles (a `roles` select with `hasMany` at the top level of the data with only `user` / `editor` / `admin`); whether an account of it can hold `editor` or `admin` whatever else the field offers (a select with one of them among its values, or a `roles` field whose values cannot be listed — text, json, a relationship) — then the admin rules apply too; whether the `roles` field can put an ARRAY on the account at all (select / text / relationship need `hasMany`; radio, number, date, checkbox never do) — the plugin counts roles only from an array, so a single-valued field brings no admin rules; the applier — puts the rules on the named staff collections for the operations that have none and closes the `roles` field where the plugin's `update` rule is in force, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | -| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)`, `staffCollectionsNobodyManages(payload, staffSlugs, except?)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | `staffCollectionsNobodyManages` (async) → `{ stuck, unchecked }`: `stuck` — staff collections on the admin rules while no staff account is a plugin admin (nobody can create, delete or unlock accounts there; the plugin warns at start); `unchecked` — staff collections whose accounts could not be checked, in which case nothing is claimed. Each collection is asked in the way its field allows. +| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)`, `staffCollectionsNobodyManages(payload, staffSlugs, except?)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. A collection is "handled" when its marker `custom.ipalAccounts` (`AccountsMarker`: `{ slug, staff }`) names its own slug and its staff status; a copy under a new slug, or a collection that became staff since, is handled again (`markSeenAuthCollections(config, staffSlugs)` writes the marker at config time). On a COPY the plugin never replaces or rewrites a rule: its rule for the copy's slug goes in front of every rule on a staff copy, and in front of the rules marked as the plugin's for another collection (`staffRuleOf`) on a copy that is not staff or keeps its own rules; the `roles` field of every copy is guarded. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | `staffCollectionsNobodyManages` (async) → `{ stuck, unchecked }`: `stuck` — staff collections on the admin rules while no staff account is a plugin admin (nobody can create, delete or unlock accounts there; the plugin warns at start); `unchecked` — staff collections whose accounts could not be checked, in which case nothing is claimed. Each collection is asked in the way its field allows. +| `staffRuleOf(rule)`, `isPasswordRuleHook(hook)` | `@intecion/ipal-kit` | The plugin's mark on its own functions, read-only (a `Symbol.for` property on the function, so it travels with a copied collection and is the same for every instance of the module): `{ slug, self }` — the collection the rule was written for and the function the mark was made for — or `undefined` for a rule the plugin did not put there. It counts only on that very function: a closure, a `Proxy` or a copied function around the plugin's rule is your own rule. `isPasswordRuleHook`: whether a `beforeOperation` hook is the plugin's password rule. The mark is used for one thing: to put the plugin's rule for a copy's own slug in front of a rule written for the original. | | `checkPassword(password, { email?, minLength? })`, `buildPasswordRuleHook({ minLength? })`, `applyPasswordRule(config, slugs, rule)`, `resolvePasswordRule(option)`, `DEFAULT_PASSWORD_MIN_LENGTH` | `@intecion/ipal-kit` | `accounts.password`: `'short' \| 'email' \| null` for a new password (length in characters); the `beforeOperation` hook for `create` / `update` / `resetPassword` (throws Payload's `ValidationError` on `password`, text in the panel's language; the account's address is looked up by id, reset token or bulk query when the request carries none; a password that is not text is refused; login is never checked); the applier; the option → `{ minLength }` or `null`; `12`. | | `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. | @@ -81,7 +82,7 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `buildRolesField(defaultRole?, { firstUserAdmin? })` | `@intecion/ipal-kit` | The `roles` select field the plugin injects (only admins set roles; `firstUserAdmin` default `true` = the account made on "Create first user" gets `admin`). The plugin wires it itself — use it only for an auth collection the plugin does not manage. | | `injectRoles(config, accessOption)` | `@intecion/ipal-kit` | Adds `roles` to `accessOption.authCollection` in a config. The plugin calls it itself with `access` — do not call. | -**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`, `firstUserRoute`, `password`), `StaffAccountAccessOptions` (`{ create?, write?, read?, pluginRoles? }`), `LateAdoption` (`{ slug, applied, password, firstUser }`), `StaffAccountRules` (what the plugin put on a staff collection, in `custom.ipalAccountRules`: `{ applied, ownRoles }`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). +**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`, `firstUserRoute`, `password`), `StaffAccountAccessOptions` (`{ create?, write?, read?, pluginRoles? }`), `StaffRuleMark` (`{ slug, self }`), `AccountsMarker` (`{ slug, staff, own? }`, in `custom.ipalAccounts`; `own`: the operations that had a rule of the project's at config time, kept when the collection becomes staff later), `LateAdoption` (`{ slug, applied, kept, known, password, firstUser }`; `known`: in the config when ipalKit ran and staff only afterwards, `kept`: its operations whose own rule was left as written), `StaffAccountRules` (what the plugin put on a staff collection, in `custom.ipalAccountRules`: `{ applied, ownRoles }`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). ## Accessibility — widget (`accessibility`) — details: `node_modules/@intecion/ipal-kit/docs/accessibility.md` diff --git a/docs/agent/skills/ipal-setup/SKILL.md b/docs/agent/skills/ipal-setup/SKILL.md index 858bc1f..3ca0a81 100644 --- a/docs/agent/skills/ipal-setup/SKILL.md +++ b/docs/agent/skills/ipal-setup/SKILL.md @@ -259,7 +259,9 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo one each of its accounts is an admin to the plugin. Every slug in `access.staffCollections` must be an auth collection of the config, or Payload does not start (`/api/health` 503, the slug in the log); a staff collection from a plugin listed after ipalKit gets the rules in front of its own (`custom: { ipal: { accountRules: false } }` - on it keeps its own as they are); Payload's first-user route answers only for the + on it keeps its own as they are); a collection of the config that a later plugin makes the panel's (`admin.user`) + keeps the rules you wrote and gets the plugin's for the rest — name the login collection in + `access.staffCollections` so it is handled at config time; Payload's first-user route answers only for the panel's login collection (`firstUserRoute`) — so **create the first account right after the first deploy**, it becomes the admin; a new password has at least 12 characters (`password`). A customer collection with sign-up: write its own `create: () => true`; the rules do not touch it. Do not combine diff --git a/docs/agent/skills/ipal-upgrade/SKILL.md b/docs/agent/skills/ipal-upgrade/SKILL.md index 3966a74..724605e 100644 --- a/docs/agent/skills/ipal-upgrade/SKILL.md +++ b/docs/agent/skills/ipal-upgrade/SKILL.md @@ -477,6 +477,12 @@ account → "Two-step verification: Set up." and the reset button; delete the ac A staff collection added by a plugin listed after ipalKit gets the same rules at start, put in FRONT of the rules it has (both must allow). If that plugin's collection needs a rule wider than the plugin's default, set `custom: { ipal: { accountRules: false } }` on it. + From the release after 1.16.7: a **copy** of a staff collection made by such a plugin (`{ ...staff, slug: 'copy' }`) + gets the plugin's rule for its own slug in front of the copied rules — the copy's accounts edit themselves only + after `access: { ...staff.access, update: adminOrSelfIn('copy') }`, and the original's accounts no longer manage + the copy's. A collection of your config that such a plugin makes the panel's (`admin.user`) keeps the rules you + wrote and gets the plugin's for the operations without one — name it in `access.staffCollections` instead + (docs/access.md "Account rules"; the start log says what was put and what was kept). `first-register` on any auth collection other than the panel's login collection answers `403` unless that collection allows sign-up. `access.firstUserAdmin: false` with a default role below `editor`: the panel role is not applied (a warning at start), or — with `accounts.panelRole` set — the start fails with the fix in the diff --git a/reference/.agents/skills/ipal-debug/SKILL.md b/reference/.agents/skills/ipal-debug/SKILL.md index c0268f2..a205f46 100644 --- a/reference/.agents/skills/ipal-debug/SKILL.md +++ b/reference/.agents/skills/ipal-debug/SKILL.md @@ -110,6 +110,7 @@ through this procedure. Ask only when you are missing something you cannot get y | an account saves its own profile and its `roles` do not change (no error) | `accounts.adminOnlyWrite`: nobody changes its own roles; with the plugin's roles only an admin changes roles | an admin changes the role; or give the `roles` field its own `access.update` | | a logged-in visitor (customer) gets `403` reading a staff collection — an author box went empty | `accounts.staffOnlyRead`: only staff accounts read a staff collection without a `read` rule | write that collection's `read` rule; or `staffOnlyRead: false` | | `/api/health` answers 503, the panel and `/api/*` 500 after a deploy; log: `[ipal] access names "…" as a staff collection, but this config has no auth collection with that slug` | a slug in `access.staffCollections` / `access.authCollection` is not an auth collection (a typo, a removed collection): Payload does not start, the process stays up (with a health check Coolify keeps the old container) | fix the slug or add the collection | +| the log says `"" became a staff collection after ipalKit ran` | a plugin listed after ipalKit set `admin.user` to a collection of your config that is not named as staff: the operations without a rule of yours got the plugin's, yours are kept (named in the same line) | name the collection in `access.staffCollections` (or `access.authCollection`), or list that plugin before ipalKit | | a collection added by a plugin listed after ipalKit refuses what its own access rule allows | it is in `access.staffCollections`: the plugin's account rules are put in front of its rules and both must allow (the log at start lists what was put) | `custom: { ipal: { accountRules: false } }` on that collection, or list that plugin before ipalKit | | a fresh site with `access.firstUserAdmin: false`: the first account sees "Unauthorized", or the start fails with `leaves a fresh site with nobody who can open the panel` | the first account gets the default role, below the panel role | `access.defaultRole: 'editor'`, or `accounts: { panelRole: false }`, or drop `firstUserAdmin: false` | | saving Site integrations fails on the password field: "Enter the password again…" | the server, port or user name changed and the stored SMTP password is kept only for the settings it was saved with — also when the transport says Microsoft Graph | type the password again; or "Remove the stored value" for a server without one; a seed with the Local API is not asked; `secrets: { reenterOnChange: false }` | diff --git a/reference/.agents/skills/ipal-reference/resources/api.md b/reference/.agents/skills/ipal-reference/resources/api.md index ada3950..57afbeb 100644 --- a/reference/.agents/skills/ipal-reference/resources/api.md +++ b/reference/.agents/skills/ipal-reference/resources/api.md @@ -68,7 +68,8 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `isEditor(user, source?)` | `@intecion/ipal-kit`; in client components `@intecion/ipal-kit/client` | Predicate → `boolean`: staff account with `editor` or higher. | | `panelAccess(minimum?)`, `applyPanelRole(config, slug, role)`, `resolvePanelRole(option)`, `countBelowPanelRole(payload, slug, role)`, `DEFAULT_PANEL_ROLE` | `@intecion/ipal-kit` | `accounts.panelRole`: an `access.admin` function ("holds at least `minimum`", default `'editor'`; role only, not the second factor); the applier (skips a collection that has its own `access.admin`); the option → role or `null` when off; `{ all, below }` counts for the start-up line; `'editor'`. | | `staffCreateAccess`, `staffUpdateAccess(slug)`, `staffReadAccess`, `sameStaffCollectionAccess(slug)`, `rolesByAdminOnly`, `rolesNotOwn(slug)`, `hasPluginRoles(collection)`, `canHoldStaffRole(collection)`, `rolesAreAList(collection)`, `applyStaffAccountAccess(config, staffSlugs, { create?, write?, read?, pluginRoles? })` | `@intecion/ipal-kit` | `accounts.adminOnlyCreate` / `adminOnlyWrite` / `staffOnlyRead`: the access functions — "an admin, fully signed in" (create, delete, unlock); "an admin, or the account itself" (update; self = an account of THAT collection); "a fully signed-in account of a staff collection" (read); "an account of this staff collection, or a plugin admin of another" (a collection whose roles are not the plugin's); the two field-access functions for a `roles` field (`update`: only an admin / never the account itself); whether a collection carries the plugin's roles (a `roles` select with `hasMany` at the top level of the data with only `user` / `editor` / `admin`); whether an account of it can hold `editor` or `admin` whatever else the field offers (a select with one of them among its values, or a `roles` field whose values cannot be listed — text, json, a relationship) — then the admin rules apply too; whether the `roles` field can put an ARRAY on the account at all (select / text / relationship need `hasMany`; radio, number, date, checkbox never do) — the plugin counts roles only from an array, so a single-valued field brings no admin rules; the applier — puts the rules on the named staff collections for the operations that have none and closes the `roles` field where the plugin's `update` rule is in force, `pluginRoles` = slugs whose roles field is injected later. Run it before any plugin that wraps access (the 2FA package). | -| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)`, `staffCollectionsNobodyManages(payload, staffSlugs, except?)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | `staffCollectionsNobodyManages` (async) → `{ stuck, unchecked }`: `stuck` — staff collections on the admin rules while no staff account is a plugin admin (nobody can create, delete or unlock accounts there; the plugin warns at start); `unchecked` — staff collections whose accounts could not be checked, in which case nothing is claimed. Each collection is asked in the way its field allows. +| `buildFirstUserEndpoint(option?)`, `applyFirstUserRoute(config, option?)`, `adoptLateAuthCollections(config, staffSlugs, { access?, beforeOperation?, firstUserRoute? })`, `bothAllow(first, second)`, `unknownStaffCollections(config, staffSlugs)`, `openSignUpCollections(payload)`, `staffCollectionsOpenToOthers(payload)`, `staffCollectionsOnOwnRoles(payload)`, `staffCollectionsNobodyManages(payload, staffSlugs, except?)` | `@intecion/ipal-kit` | `accounts.firstUserRoute`: the plugin's own `POST /first-register` collection endpoint, matched before Payload's — `403` unless the collection is the panel's login collection (`'panel'`), is in the list, or its own `create` lets an anonymous request through; otherwise it calls Payload's handler (and sets `req.context.ipalFirstRegister`); the applier (every auth collection; `'all'` adds nothing; `endpoints: false` is left alone). For the doctor: slugs of auth collections with open sign-up; `':'` for every staff collection an account of a non-staff collection may create in, read, update, delete from or unlock; slugs of staff collections with role values of their own on the default rules. `adoptLateAuthCollections` takes the LIVE config (`payload.config`) and gives auth collections that a plugin listed after ipalKit added the same rules, in place (called by the plugin at start and on every dev reload; returns `LateAdoption[]` — per collection what was put). There the rules are combined with the collection's own by `bothAllow` (an access function that allows only when both do; two query constraints are joined with `and`), because in a sanitized config Payload's default cannot be told from a written rule — never by a function's name, which a production build changes. `custom.ipal.accountRules: false` on a late collection keeps its rules as they are. A collection is "handled" when its marker `custom.ipalAccounts` (`AccountsMarker`: `{ slug, staff }`) names its own slug and its staff status; a copy under a new slug, or a collection that became staff since, is handled again (`markSeenAuthCollections(config, staffSlugs)` writes the marker at config time). On a COPY the plugin never replaces or rewrites a rule: its rule for the copy's slug goes in front of every rule on a staff copy, and in front of the rules marked as the plugin's for another collection (`staffRuleOf`) on a copy that is not staff or keeps its own rules; the `roles` field of every copy is guarded. `unknownStaffCollections` lists staff slugs that are not auth collections (Payload does not start on any). | `staffCollectionsNobodyManages` (async) → `{ stuck, unchecked }`: `stuck` — staff collections on the admin rules while no staff account is a plugin admin (nobody can create, delete or unlock accounts there; the plugin warns at start); `unchecked` — staff collections whose accounts could not be checked, in which case nothing is claimed. Each collection is asked in the way its field allows. +| `staffRuleOf(rule)`, `isPasswordRuleHook(hook)` | `@intecion/ipal-kit` | The plugin's mark on its own functions, read-only (a `Symbol.for` property on the function, so it travels with a copied collection and is the same for every instance of the module): `{ slug, self }` — the collection the rule was written for and the function the mark was made for — or `undefined` for a rule the plugin did not put there. It counts only on that very function: a closure, a `Proxy` or a copied function around the plugin's rule is your own rule. `isPasswordRuleHook`: whether a `beforeOperation` hook is the plugin's password rule. The mark is used for one thing: to put the plugin's rule for a copy's own slug in front of a rule written for the original. | | `checkPassword(password, { email?, minLength? })`, `buildPasswordRuleHook({ minLength? })`, `applyPasswordRule(config, slugs, rule)`, `resolvePasswordRule(option)`, `DEFAULT_PASSWORD_MIN_LENGTH` | `@intecion/ipal-kit` | `accounts.password`: `'short' \| 'email' \| null` for a new password (length in characters); the `beforeOperation` hook for `create` / `update` / `resetPassword` (throws Payload's `ValidationError` on `password`, text in the panel's language; the account's address is looked up by id, reset token or bulk query when the request carries none; a password that is not text is refused; login is never checked); the applier; the option → `{ minLength }` or `null`; `12`. | | `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. | @@ -81,7 +82,7 @@ Admin panel components from `@intecion/ipal-kit/admin` — the project does NOT | `buildRolesField(defaultRole?, { firstUserAdmin? })` | `@intecion/ipal-kit` | The `roles` select field the plugin injects (only admins set roles; `firstUserAdmin` default `true` = the account made on "Create first user" gets `admin`). The plugin wires it itself — use it only for an auth collection the plugin does not manage. | | `injectRoles(config, accessOption)` | `@intecion/ipal-kit` | Adds `roles` to `accessOption.authCollection` in a config. The plugin calls it itself with `access` — do not call. | -**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`, `firstUserRoute`, `password`), `StaffAccountAccessOptions` (`{ create?, write?, read?, pluginRoles? }`), `LateAdoption` (`{ slug, applied, password, firstUser }`), `StaffAccountRules` (what the plugin put on a staff collection, in `custom.ipalAccountRules`: `{ applied, ownRoles }`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). +**Types:** `AccountsOptions` (`accounts`: `panelRole`, `adminOnlyCreate`, `adminOnlyWrite`, `staffOnlyRead`, `firstUserRoute`, `password`), `StaffAccountAccessOptions` (`{ create?, write?, read?, pluginRoles? }`), `StaffRuleMark` (`{ slug, self }`), `AccountsMarker` (`{ slug, staff, own? }`, in `custom.ipalAccounts`; `own`: the operations that had a rule of the project's at config time, kept when the collection becomes staff later), `LateAdoption` (`{ slug, applied, kept, known, password, firstUser }`; `known`: in the config when ipalKit ran and staff only afterwards, `kept`: its operations whose own rule was left as written), `StaffAccountRules` (what the plugin put on a staff collection, in `custom.ipalAccountRules`: `{ applied, ownRoles }`), `WriteOnlySecretOptions` (`{ boundTo?, appliesWhen? }`), `PasswordRuleOptions` (`{ minLength? }`), `FirstUserRouteOption` (`'panel' \| 'all' \| string[]`), `TurnstileOnConfigError` / `TurnstileOnConfigErrorOption` / `TurnstileFormKind` (`@intecion/ipal-kit/server`), `VerifyLimitOptions` (`twoFactor.verifyLimit`: `{ max?, windowMinutes?, store? }`), `RequireSetupOptions` (`twoFactor.requireSetup`), `TwoFactorResetOptions`, `TwoFactorSetupState`, `SafeBackRule` / `SafeBackContext` (`twoFactor.safeBack` as a function: `(back, { adminRoute, origin? }) => string`), `TotpViewComponent` (a view component as registered: a path or `{ path, exportName?, clientProps?, serverProps? }`), `SafeTotpViewProps` (`@intecion/ipal-kit/admin`), `Role` (`'user' \| 'editor' \| 'admin'`), `AccessOption` (the plugin's `access` option: `authCollection`, `defaultRole`, `authAccess`, `firstUserAdmin`, `staffCollections`). ## Accessibility — widget (`accessibility`) — details: `node_modules/@intecion/ipal-kit/docs/accessibility.md` diff --git a/reference/.agents/skills/ipal-setup/SKILL.md b/reference/.agents/skills/ipal-setup/SKILL.md index 858bc1f..3ca0a81 100644 --- a/reference/.agents/skills/ipal-setup/SKILL.md +++ b/reference/.agents/skills/ipal-setup/SKILL.md @@ -259,7 +259,9 @@ the panel shows Site settings, Site integrations, Cookies, Form messages, the Fo one each of its accounts is an admin to the plugin. Every slug in `access.staffCollections` must be an auth collection of the config, or Payload does not start (`/api/health` 503, the slug in the log); a staff collection from a plugin listed after ipalKit gets the rules in front of its own (`custom: { ipal: { accountRules: false } }` - on it keeps its own as they are); Payload's first-user route answers only for the + on it keeps its own as they are); a collection of the config that a later plugin makes the panel's (`admin.user`) + keeps the rules you wrote and gets the plugin's for the rest — name the login collection in + `access.staffCollections` so it is handled at config time; Payload's first-user route answers only for the panel's login collection (`firstUserRoute`) — so **create the first account right after the first deploy**, it becomes the admin; a new password has at least 12 characters (`password`). A customer collection with sign-up: write its own `create: () => true`; the rules do not touch it. Do not combine diff --git a/reference/.agents/skills/ipal-upgrade/SKILL.md b/reference/.agents/skills/ipal-upgrade/SKILL.md index 3966a74..724605e 100644 --- a/reference/.agents/skills/ipal-upgrade/SKILL.md +++ b/reference/.agents/skills/ipal-upgrade/SKILL.md @@ -477,6 +477,12 @@ account → "Two-step verification: Set up." and the reset button; delete the ac A staff collection added by a plugin listed after ipalKit gets the same rules at start, put in FRONT of the rules it has (both must allow). If that plugin's collection needs a rule wider than the plugin's default, set `custom: { ipal: { accountRules: false } }` on it. + From the release after 1.16.7: a **copy** of a staff collection made by such a plugin (`{ ...staff, slug: 'copy' }`) + gets the plugin's rule for its own slug in front of the copied rules — the copy's accounts edit themselves only + after `access: { ...staff.access, update: adminOrSelfIn('copy') }`, and the original's accounts no longer manage + the copy's. A collection of your config that such a plugin makes the panel's (`admin.user`) keeps the rules you + wrote and gets the plugin's for the operations without one — name it in `access.staffCollections` instead + (docs/access.md "Account rules"; the start log says what was put and what was kept). `first-register` on any auth collection other than the panel's login collection answers `403` unless that collection allows sign-up. `access.firstUserAdmin: false` with a default role below `editor`: the panel role is not applied (a warning at start), or — with `accounts.panelRole` set — the start fails with the fix in the diff --git a/reference/e2e/late-staff-fixture.ts b/reference/e2e/late-staff-fixture.ts index e32d7c8..a8f16e4 100644 --- a/reference/e2e/late-staff-fixture.ts +++ b/reference/e2e/late-staff-fixture.ts @@ -10,7 +10,7 @@ import type { Config, Plugin } from 'payload' export const E2E_LATE_STAFF = process.env.E2E_LATE_STAFF === '1' /** Slugs the fixture names as staff (payload.config.ts → `access.staffCollections`). */ -export const E2E_STAFF_SLUGS = ['late-staff', 'e2e-crew', 'e2e-late-text'] +export const E2E_STAFF_SLUGS = ['late-staff', 'e2e-crew', 'e2e-late-text', 'e2e-staff', 'e2e-team', 'e2e-copy', 'e2e-copy-own-rules', 'e2e-copy-cross-op', 'e2e-copy-values', 'e2e-copy-team-admin', 'e2e-copy-opt-out'] /** * Listed BEFORE ipalKit: a staff collection of the project's own, without rules, whose roles are the plugin's values @@ -18,15 +18,44 @@ export const E2E_STAFF_SLUGS = ['late-staff', 'e2e-crew', 'e2e-late-text'] */ export const e2eEarlyStaff: Plugin = (config: Config) => E2E_LATE_STAFF - ? { ...config, collections: [...(config.collections ?? []), { slug: 'e2e-crew', auth: true, fields: [{ name: 'roles', type: 'select', hasMany: true, options: ['user', 'editor', 'admin', 'boss'], saveToJWT: true }] }] } + ? { + ...config, + collections: [ + ...(config.collections ?? []), + { slug: 'e2e-crew', auth: true, fields: [{ name: 'roles', type: 'select', hasMany: true, options: ['user', 'editor', 'admin', 'boss'], saveToJWT: true }] }, + // the two originals the later plugin copies: the plugin's roles, and roles of the project's own + { slug: 'e2e-staff', auth: true, fields: [{ name: 'roles', type: 'select', hasMany: true, options: ['user', 'editor', 'admin'], saveToJWT: true }] }, + { slug: 'e2e-team', auth: true, fields: [{ name: 'roles', type: 'select', hasMany: true, options: ['lead', 'member'], saveToJWT: true }] }, + ], + } : config +/** + * Copies of staff collections under new slugs — the shapes in which a rule could become WIDER when the plugin + * rewrote copied rules. It never replaces a rule now: its rule for the copy's slug goes in front of what came along. + */ +const copies = (config: Config): NonNullable => { + const of = (slug: string) => (config.collections ?? []).find((c) => c.slug === slug)! + const staff = of('e2e-staff') + const roles = (options: string[]) => [{ name: 'roles', type: 'select' as const, hasMany: true as const, options, saveToJWT: true }] + return [ + { ...staff, slug: 'e2e-copy' }, // plain: the original's namesake is not "the account itself" here + { ...staff, slug: 'e2e-copy-own-rules', access: { ...staff.access, create: () => false, delete: () => false, read: () => false, update: () => false } }, // "nobody" stays "nobody" + { ...staff, slug: 'e2e-copy-cross-op', access: { ...staff.access, read: staff.access?.create, update: staff.access?.create } }, // the admin-only create rule used for read and update + { ...staff, slug: 'e2e-copy-values', fields: roles(['user', 'editor', 'admin', 'boss']) }, // one more role value + { ...of('e2e-team'), slug: 'e2e-copy-team-admin', fields: roles(['user', 'editor', 'admin']) }, // "an account of the collection" copied onto a collection with `admin` + { ...staff, slug: 'e2e-copy-opt-out', custom: { ...staff.custom, ipal: { accountRules: false } }, fields: roles(['user', 'editor', 'admin']) }, // keeps its own rules, brings its own roles field + { ...staff, slug: 'e2e-copy-not-staff' }, // not named as a staff collection + ] +} + export const e2eLateStaff: Plugin = (config: Config) => E2E_LATE_STAFF ? { ...config, collections: [ ...(config.collections ?? []), + ...copies(config), // no access rules at all: Payload's defaults ("any logged-in user") are what ipalKit must replace { slug: 'late-staff', auth: true, fields: [{ name: 'roles', type: 'select', hasMany: true, options: ['user', 'editor', 'admin'], saveToJWT: true }], versions: true }, // a late staff collection whose `roles` is a text field: any value can be written there, `admin` included diff --git a/reference/e2e/late-staff.spec.ts b/reference/e2e/late-staff.spec.ts index fe2e48b..314f091 100644 --- a/reference/e2e/late-staff.spec.ts +++ b/reference/e2e/late-staff.spec.ts @@ -96,6 +96,45 @@ test.describe('a late staff collection on a built site', () => { await api.dispose() } + // Copies of staff collections (e2e/late-staff-fixture.ts → copies): the lowest account of each copy, and an account + // of the ORIGINAL with the role `user`, get nothing that a plugin rule or the copy's own rule refuses — whatever + // role values the copy has and wherever it uses a copied rule. (Each of these shapes was open in some version that + // REWROTE copied rules; the plugin now only ever puts its rule in front.) + const original = await admin.post('/api/e2e-staff', { data: { email: `o-${tag}@staff.example.com`, password: PASSWORD, roles: ['user'] } }) + expect(original.status()).toBe(201) + const fromOriginal = await context(playwright, baseURL!) + expect((await fromOriginal.post('/api/e2e-staff/login', { data: { email: `o-${tag}@staff.example.com`, password: PASSWORD } })).status()).toBe(200) + for (const slug of ['e2e-copy', 'e2e-copy-cross-op', 'e2e-copy-values', 'e2e-copy-team-admin', 'e2e-copy-opt-out', 'e2e-copy-not-staff']) { + const top = await admin.post(`/api/${slug}`, { data: { email: `a-${tag}@${slug}.example.com`, password: PASSWORD, roles: ['admin'] } }) + const lowest = await admin.post(`/api/${slug}`, { data: { email: `u-${tag}@${slug}.example.com`, password: PASSWORD, roles: ['user'] } }) + expect([slug, top.status(), lowest.status()]).toEqual([slug, 201, 201]) + const topId = (await top.json()).doc.id as string + const lowestId = (await lowest.json()).doc.id as string + const own = await context(playwright, baseURL!) + expect((await own.post(`/api/${slug}/login`, { data: { email: `u-${tag}@${slug}.example.com`, password: PASSWORD } })).status()).toBe(200) + for (const [who, api] of [['its own lowest account', own], ['an account of the original', fromOriginal], ['a visitor', visitor]] as [string, APIRequestContext][]) { + expect([slug, who, { + create: (await api.post(`/api/${slug}`, { data: { email: `made-${tag}-${who.length}@${slug}.example.com`, password: PASSWORD, roles: ['admin'] } })).status(), + integrations: (await api.get('/api/globals/site-integrations')).status(), + patchLowest: who === 'its own lowest account' ? 'itself' : (await api.patch(`/api/${slug}/${lowestId}`, { data: { password: `taken-${PASSWORD}` } })).status(), + patchTop: (await api.patch(`/api/${slug}/${topId}`, { data: { password: `taken-${PASSWORD}` } })).status(), + zDelete: (await api.delete(`/api/${slug}/${topId}`)).status(), + }]).toEqual([slug, who, { create: 403, integrations: 403, patchLowest: who === 'its own lowest account' ? 'itself' : 403, patchTop: 403, zDelete: 403 }]) + } + await own.patch(`/api/${slug}/${lowestId}`, { data: { roles: ['admin'] } }) + expect((await (await admin.get(`/api/${slug}/${lowestId}`)).json()).roles, `${slug}: its own roles`).toEqual(['user']) + for (const id of [topId, lowestId]) {expect((await admin.delete(`/api/${slug}/${id}`)).status(), `${slug}: an admin cleans up`).toBe(200)} + await own.dispose() + } + // a copy with rules of its own ("nobody"): an admin is refused too — the plugin's rule went in front, it replaced nothing + expect((await admin.post('/api/e2e-copy-own-rules', { data: { email: `x-${tag}@own.example.com`, password: PASSWORD, roles: ['admin'] } })).status(), 'own rules: create').toBe(403) + expect((await admin.get('/api/e2e-copy-own-rules')).status(), 'own rules: read').toBe(403) + // the cross-op copy: read is "an admin" there (the create rule), also for the copy's own accounts — checked above through + // create / patch; and the list itself: + expect((await fromOriginal.get('/api/e2e-copy-cross-op')).status()).toBe(403) + expect((await admin.get('/api/e2e-copy-cross-op')).status()).toBe(200) + await fromOriginal.dispose() + // an admin: everything, and it cleans up expect((await admin.get('/api/late-staff/versions')).status()).toBe(200) expect((await admin.post('/api/late-staff/unlock', { data: { email: `low-${tag}@example.com` } })).status()).toBe(200) diff --git a/scripts/reference-index.mjs b/scripts/reference-index.mjs index fa64395..384386c 100644 --- a/scripts/reference-index.mjs +++ b/scripts/reference-index.mjs @@ -60,8 +60,8 @@ export const DESCRIPTIONS = { 'README.md': 'how to run the reference site and what is where', 'docs/DEPLOY.md': 'the Coolify runbook: local check, app settings, MongoDB resource, env, targeted seeds, DNS, rollback', 'e2e/create-test-admin.ts': 'two test admins with a known TOTP secret (the specs share out the five 2FA verify attempts per account), their stored verify counts cleared, and e-mail sending pointed at the tests\' mail sink (local / CI database only)', - 'e2e/late-staff-fixture.ts': 'test fixture, on only with E2E_LATE_STAFF=1: one plugin before ipalKit (a staff collection of the config whose roles are the plugin\'s values plus one more) and one after it (a staff collection without rules, one whose roles field is text, a visitor collection with open sign-up)', - 'e2e/late-staff.spec.ts': 'the account rules on a BUILT site (run by `pnpm e2e:built` after a webpack and a Turbopack build): a staff collection a later plugin adds, and staff collections whose accounts can hold `admin` — a visitor account gets nothing, nobody raises its own role or makes an admin', + 'e2e/late-staff-fixture.ts': 'test fixture, on only with E2E_LATE_STAFF=1: one plugin before ipalKit (staff collections of the config: roles with one more value, the plugin\'s roles, roles of the project\'s own) and one after it (a staff collection without rules, one whose roles field is text, copies of staff collections under new slugs — plain, with rules of their own, one rule used for another operation, other role values, the opt-out, not staff — and a visitor collection with open sign-up)', + 'e2e/late-staff.spec.ts': 'the account rules on a BUILT site (run by `pnpm e2e:built` after a webpack and a Turbopack build): a staff collection a later plugin adds, staff collections whose accounts can hold `admin`, and copies of staff collections — a visitor account gets nothing, nobody raises its own role or makes an admin, a copy is never wider than the plugin\'s rule', 'e2e/global-setup.ts': 'Playwright global setup: resets the test admins and clears their stored 2FA attempt counts before every run, so specs do not depend on run order', 'e2e/two-factor-setup.spec.ts': 'browser check of "2FA setup required": the first admin of a fresh site, a new editor, the administrator\'s reset on the account page', 'e2e/smoke.spec.ts': 'the smoke tests every release must pass: pages, showcase, forms (also a file sent by e-mail), sitemap, SEO/GEO, headers, consent, 2FA', diff --git a/src/index.ts b/src/index.ts index c567a78..4c8bf76 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,6 +24,8 @@ export { export { applyPanelRole, countBelowPanelRole, DEFAULT_PANEL_ROLE, panelAccess, resolvePanelRole } from './modules/access/panelRole.js' export { applyPasswordRule, buildPasswordRuleHook, checkPassword, DEFAULT_PASSWORD_MIN_LENGTH, resolvePasswordRule } from './modules/access/passwordRule.js' export type { PasswordRuleOptions } from './modules/access/passwordRule.js' +export { isPasswordRuleHook, staffRuleOf } from './modules/access/ruleMark.js' +export type { StaffRuleMark } from './modules/access/ruleMark.js' export { adoptLateAuthCollections, applyFirstUserRoute, @@ -45,7 +47,7 @@ export { staffUpdateAccess, unknownStaffCollections, } from './modules/access/selfRegistration.js' -export type { LateAdoption, StaffAccountAccessOptions, StaffAccountRules } from './modules/access/selfRegistration.js' +export type { AccountsMarker, LateAdoption, StaffAccountAccessOptions, StaffAccountRules } from './modules/access/selfRegistration.js' export type { FirstUserRouteOption } from './modules/access/selfRegistration.js' export type { AccountsOptions } from './modules/access/types.js' // Concrete files, not module barrels: a barrel that also re-exports 'use client' diff --git a/src/modules/access/passwordRule.ts b/src/modules/access/passwordRule.ts index af88586..e87a8a4 100644 --- a/src/modules/access/passwordRule.ts +++ b/src/modules/access/passwordRule.ts @@ -3,6 +3,7 @@ import type { CollectionBeforeOperationHook, Config } from 'payload' import { ValidationError } from 'payload' import { serverText } from '../integrations/texts.js' +import { markPasswordRule } from './ruleMark.js' /** * A password rule for staff accounts. @@ -47,7 +48,7 @@ export function checkPassword(password: string, { email, minLength = DEFAULT_PAS * (`create`, `update`, `resetPassword`). Login, refresh and every other operation pass untouched. */ export function buildPasswordRuleHook({ minLength = DEFAULT_PASSWORD_MIN_LENGTH }: PasswordRuleOptions = {}): CollectionBeforeOperationHook { - return async ({ args, collection, operation, req }) => { + const hook: CollectionBeforeOperationHook = async ({ args, collection, operation, req }) => { if (operation !== 'create' && operation !== 'update' && operation !== 'resetPassword') {return args} const data = (args as { data?: { email?: unknown; password?: unknown } }).data const password = data?.password @@ -88,6 +89,8 @@ export function buildPasswordRuleHook({ minLength = DEFAULT_PASSWORD_MIN_LENGTH if (problem) {return refuse(problem)} return args } + // marked on the function itself: a copied collection brings the hook along, and it is not put there twice + return markPasswordRule(hook) } /** Adds the rule to the named auth collections that log in with a password. */ diff --git a/src/modules/access/ruleMark.ts b/src/modules/access/ruleMark.ts new file mode 100644 index 0000000..2a13383 --- /dev/null +++ b/src/modules/access/ruleMark.ts @@ -0,0 +1,72 @@ +/** + * The plugin's mark on an access function it put on a staff collection: "this is the plugin's + * rule, written for the collection `slug`". + * + * A later plugin may copy a collection (`{ ...staff, slug: 'copy' }`) or reuse its access object: + * the functions travel along, and a rule written for the original — "an account of `staff`", + * "the account itself" = one of the original's — then sits on a collection it does not speak of. + * The mark lets the plugin see that. It is on the function itself, so it: + * - travels with every copy (it is the same function object); + * - is on the function that ends up on the collection (set after the 2FA package wrapped the + * rule; ipal-kit's own 2FA guard gets a mark of its own for its wrapper); + * - is the same for every instance of this module (`Symbol.for`): after a `next dev` reload the + * config was built by one instance and is adopted by another. + * It counts only on the very function it was made for (`self`): a Proxy around a marked rule, a + * function with the rule as its prototype, a function that got the rule's property descriptors + * copied answer with the same property but are somebody's own rule. + * + * What the plugin DOES with a rule marked for another collection: it never replaces it. It puts + * its rule for this collection in front, and both must allow (selfRegistration.ts). So the mark + * says nothing about what the rule is — no operation, no kind: nothing is decided from it but + * "this rule speaks of another collection". + */ +const STAFF_RULE = Symbol.for('ipal.staffRule') +const PASSWORD_RULE = Symbol.for('ipal.passwordRule') + +export type StaffRuleMark = { + /** The function the mark was made for. */ + self: unknown + /** The collection the rule was written for. */ + slug: string +} + +type Marked = { [PASSWORD_RULE]?: { self: unknown }; [STAFF_RULE]?: StaffRuleMark } +const settable = (value: unknown): value is Marked => typeof value === 'function' && Object.isExtensible(value) +const setMark = (rule: Marked, slug: string): void => { + Object.defineProperty(rule, STAFF_RULE, { configurable: true, value: { slug, self: rule } satisfies StaffRuleMark }) +} + +/** + * A NEW function that does what `rule` does and carries the mark. Always a new one: the plugin's + * exported rules are shared (`adminOnly`), and a mark on a shared function would follow it into + * collections where the project itself used it. Not exported from the package. + */ +export function markedStaffRule unknown>(rule: T, slug: string): T { + const marked = ((...args: never[]) => rule(...args)) as unknown as Marked & T + setMark(marked, slug) + return marked +} + +/** + * The plugin's mark on a function, or undefined: then it is not a rule the plugin put there. + * Only a mark that is the function's OWN property and was made for this very function counts. + */ +export const staffRuleOf = (rule: unknown): StaffRuleMark | undefined => { + if (typeof rule !== 'function' || !Object.hasOwn(rule, STAFF_RULE)) {return undefined} + const mark = (rule as Marked)[STAFF_RULE] + return mark && typeof mark === 'object' && typeof mark.slug === 'string' && mark.self === rule ? mark : undefined +} + +/** For a wrapper the PLUGIN puts around an access function (its 2FA guard): the wrapper answers for the same rule and gets a mark of its own. */ +export function carryStaffRule(from: unknown, to: unknown): void { + const mark = staffRuleOf(from) + if (mark && settable(to)) {setMark(to, mark.slug)} +} + +/** Marks a `beforeOperation` hook as the plugin's password rule (so it is not put on a collection twice). */ +export function markPasswordRule(hook: T): T { + if (settable(hook)) {Object.defineProperty(hook, PASSWORD_RULE, { configurable: true, value: { self: hook } })} + return hook +} +/** True for a hook made by `buildPasswordRuleHook` — in any instance of the module; only the hook itself, not a wrapper around it. */ +export const isPasswordRuleHook = (hook: unknown): boolean => typeof hook === 'function' && Object.hasOwn(hook, PASSWORD_RULE) && (hook as Marked)[PASSWORD_RULE]?.self === hook diff --git a/src/modules/access/selfRegistration.ts b/src/modules/access/selfRegistration.ts index 96dd767..7449c67 100644 --- a/src/modules/access/selfRegistration.ts +++ b/src/modules/access/selfRegistration.ts @@ -2,6 +2,7 @@ import type { Access, CollectionConfig, Config, Endpoint, PayloadRequest } from import { secondFactorPassed } from '../security/totp/secondFactor.js' import { staffCollectionSlugs, userMeetsRole } from './predicates.js' +import { isPasswordRuleHook, markedStaffRule, staffRuleOf } from './ruleMark.js' import { ROLE_HIERARCHY } from './types.js' /** @@ -152,8 +153,32 @@ export function canHoldStaffRole(collection: Staffish): boolean { return values === null || values.some((value) => value === 'editor' || value === 'admin') } -/** What the plugin put on a staff collection (`custom.ipalAccountRules`) — for the doctor and for late collections. */ -export type StaffAccountRules = { applied: string[]; ownRoles: boolean } +/** + * What the plugin put on a collection (`custom.ipalAccountRules`) — for the doctor and the log. `slug`: the + * collection the record was written for (a copy of the collection carries the original's record along). + */ +export type StaffAccountRules = { applied: string[]; ownRoles: boolean; slug?: string } + +/** + * The "seen" marker (`custom.ipalAccounts`): which collection ipalKit handled, and whether as a staff + * collection. Not a plain `true`: a later plugin may spread a collection into a new slug + * (`{ ...staff, slug: 'copy' }`) and the marker travels with it; and in `next dev` a collection object can + * outlive a reload in which it became staff. + */ +export type AccountsMarker = { + /** + * The operations that had a rule in the project's config when ipalKit ran (before Payload and the 2FA package + * filled the missing ones). A collection of the config that becomes staff LATER — a plugin listed after ipalKit + * sets `admin.user` to it — keeps exactly those rules; an operation that had none gets the plugin's. + */ + own?: string[] + slug: string + staff: boolean +} +const markerOf = (collection: { custom?: unknown }): AccountsMarker | undefined => { + const marker = (collection.custom as { ipalAccounts?: unknown } | undefined)?.ipalAccounts + return marker && typeof marker === 'object' && typeof (marker as AccountsMarker).slug === 'string' ? (marker as AccountsMarker) : undefined +} /** * BOTH rules must allow: the plugin's and the one the collection already has. For a collection @@ -188,52 +213,124 @@ export type StaffAccountAccessOptions = { write?: boolean } +/** Field access: both must allow (a `roles` field's own rule and the plugin's guard). */ +const bothAllowField = + (first: (args: never) => unknown, second: unknown) => + async (args: never): Promise => + Boolean(await first(args)) && (typeof second !== 'function' || Boolean(await (second as (a: never) => unknown)(args))) + /** - * Puts the defaults on ONE staff collection, in place: the operations without a rule, and the - * `roles` field when the plugin's `update` rule is the one in force. Returns what it applied. - * `late`: the collection's config is already sanitized (see `bothAllow`) — the plugin's rule is - * combined with whatever is there instead of only filling gaps. + * Puts the plugin's rules on ONE collection, in place, and returns what it put. + * + * **A rule that cannot widen.** The plugin fills an operation that has NO rule (config time), or puts its rule + * in FRONT of the rule that is there, so that both must allow (`bothAllow`). It never replaces a rule and never + * rewrites one. Whatever is on the collection — the project's rule, Payload's default, a rule the plugin wrote for + * ANOTHER collection that a copy brought along — still has to allow. So the result is never wider than what was + * there and never wider than the plugin's rule for this collection, whatever role values, operations or wrappers + * are involved. + * + * `mode`: + * - `'config'` (ipalKit is running, nothing is sanitized): an operation without a rule gets the plugin's; + * - `'late'` (a staff collection a later plugin added; the config is sanitized, so Payload's default cannot be + * told from a written rule): the plugin's rule in front of every rule — except the operations named in `kept`: + * the collection was in the config when ipalKit ran and had a rule of the project's for them then (the marker's + * `own`), so they are left as a rule the project wrote, exactly as at config time; + * - `'copied'` (a late collection that is not staff, or that keeps its own rules — `custom.ipal.accountRules: + * false`): the plugin's rule goes in front ONLY of a rule the plugin wrote for another collection (its mark, + * ruleMark.ts). Such a rule says "an account of the original", "the account itself" = one of the original's; + * with this collection's rule in front, the original's namesake with the same id is not "itself" here. + * Accepted cost: where a copied rule says "itself" for the ORIGINAL's accounts, the copy's own account cannot + * edit itself (as before this change) — the copying plugin writes the copy's `access.update`. */ -function ruleStaffCollection(collection: CollectionConfig, { create = true, pluginRoles = [], read = true, write = true }: StaffAccountAccessOptions, late = false): StaffAccountRules { +function ruleStaffCollection(collection: CollectionConfig, { create = true, pluginRoles = [], read = true, write = true }: StaffAccountAccessOptions, mode: 'config' | 'copied' | 'late' = 'config', kept: string[] = []): StaffAccountRules { const slug = collection.slug // the admin rules: where the roles are the plugin's, and wherever an account can hold `editor` or `admin` (canHoldStaffRole) const ours = pluginRoles.includes(slug) || hasPluginRoles(collection) || canHoldStaffRole(collection) const other = sameStaffCollectionAccess(slug) - const access = (collection.access ?? {}) as Record - const applied: string[] = [] - const put = (operation: string, rule: Access) => { - if (late) {access[operation] = bothAllow(rule, access[operation])} - else if (!access[operation]) {access[operation] = rule} - else {return} // a rule the project wrote - applied.push(operation) - } - if (create) {put('create', ours ? staffCreateAccess : other)} - if (write) { - put('update', ours ? staffUpdateAccess(slug) : other) - put('delete', ours ? staffCreateAccess : other) - put('unlock', ours ? staffCreateAccess : other) - } - if (read) { - put('read', staffReadAccess) + // a new object: a copied collection shares the original's + const access = { ...collection.access } as Record + const before = (collection.custom as { ipalAccountRules?: StaffAccountRules } | undefined)?.ipalAccountRules + // what the plugin put there earlier for THIS slug (the injected collection's own rules, plugin.ts) + const applied: string[] = before?.slug === slug ? [...before.applied] : [] + // The plugin's rule for each operation of THIS collection, and whether that default is switched on. + const rules: [operation: string, rule: Access, enabled: boolean][] = [ + ['create', ours ? staffCreateAccess : other, create], + ['update', ours ? staffUpdateAccess(slug) : other, write], + ['delete', ours ? staffCreateAccess : other, write], + ['unlock', ours ? staffCreateAccess : other, write], + ['read', staffReadAccess, read], // versions of an account hold what the account holds (e-mail addresses, roles) - put('readVersions', staffReadAccess) + ['readVersions', staffReadAccess, read], + ] + /** A rule of ANOTHER collection is on this one: it is a copy, or it reuses another collection's access. */ + let copied = Boolean(before?.slug && before.slug !== slug) || Boolean(markerOf(collection) && markerOf(collection)?.slug !== slug) + for (const [operation, rule, enabled] of rules) { + const there = access[operation] + // A mark — for another collection, or one that claims this one — only ever ADDS the plugin's rule in front; a + // function is never left alone because of what its mark says (whether a collection was handled is the marker's + // business, not the function's). + const mark = staffRuleOf(there) + if (mark && mark.slug !== slug) {copied = true} + if (mode === 'config') { + if (there || !enabled) {continue} // a rule the project wrote + access[operation] = rule // marked when ipalKit finishes (markStaffRules): the 2FA package wraps it first + } else if ((mode === 'late' && enabled && !kept.includes(operation)) || mark) { + access[operation] = markedStaffRule(bothAllow(rule, there), slug) + } else {continue} + if (!applied.includes(operation)) {applied.push(operation)} } collection.access = access as CollectionConfig['access'] - // The plugin's `update` rule lets an account change itself (or, with roles of its own, every account of - // the collection change every other): a `roles` field without access of its own would let it raise itself. - const roles = findRolesField(collection.fields as FieldLike[]) - if (applied.includes('update')) { - if (roles && !roles.access?.update) { - roles.access = { ...roles.access, update: ours ? rolesByAdminOnly : rolesNotOwn(slug) } - applied.push('roles') + // The `roles` field. An account that may update itself would raise itself through a `roles` field without access of + // its own. The guard (the plugin's roles: only an admin changes them; others: never one's own) is put: + // - config: where the plugin's `update` rule is the one in force (it says "the account itself"); + // - late: on every staff collection the plugin rules (as at config time, not where the project's own `update` + // rule was kept); + // - on every COPY, whatever the mode — also one that keeps its own rules and one that is not staff: its field came + // without a rule of its own, and its accounts must not write their own roles because the original's could not. + // A rule the field has is kept: the guard goes in front of it only when it is the plugin's rule for another collection. + let roles = findRolesField(collection.fields as FieldLike[]) + if (roles) { + const guard = (ours ? rolesByAdminOnly : rolesNotOwn(slug)) as (args: never) => unknown + const there = roles.access?.update + const fieldMark = staffRuleOf(there) + const foreign = Boolean(fieldMark) && mode !== 'config' + const wanted = mode === 'config' ? write && applied.includes('update') : (mode === 'late' && write && !kept.includes('update')) || copied + if (foreign || (!there && wanted)) { + // the field object may be shared with the collection this one was copied from — give this one its own + if (mode !== 'config') {roles = ownCopyOfField(collection, roles)} + roles.access = { ...roles.access, update: markedStaffRule(foreign ? bothAllowField(guard, there) : guard, slug) as never } + if (!applied.includes('roles')) {applied.push('roles')} } } // "roles of its own": a roles field whose values are not the plugin's (a collection without the field has no roles to rank) - const rules: StaffAccountRules = { applied, ownRoles: !ours && Boolean(roles) } - collection.custom = { ...collection.custom, ipalAccountRules: rules } - return rules + const record: StaffAccountRules = { slug, applied, ownRoles: !ours && Boolean(roles) } + // (a late collection that is not staff and brought nothing of the plugin's along gets no record) + if (applied.length || before || mode !== 'copied') {collection.custom = { ...collection.custom, ipalAccountRules: record }} + return record } +/** + * Gives a (sanitized) collection its OWN copy of one field object, in `fields` and `flattenedFields`, and returns + * the copy: a collection made by spreading another shares the field objects — and the arrays — with it. + */ +function ownCopyOfField(collection: CollectionConfig, field: FieldLike): FieldLike { + const copy = { ...field } + const rebuild = (list: FieldLike[]): FieldLike[] => + list.map((entry) => { + if (entry === field) {return copy} + if (!entry.name && entry.fields) {return { ...entry, fields: rebuild(entry.fields) }} + if (entry.tabs) {return { ...entry, tabs: entry.tabs.map((tab) => (tab.name ? tab : { ...tab, fields: rebuild(tab.fields) })) }} + return entry + }) + const own = collection as unknown as { fields?: FieldLike[]; flattenedFields?: FieldLike[] } + if (Array.isArray(own.fields)) {own.fields = rebuild(own.fields)} + if (Array.isArray(own.flattenedFields)) {own.flattenedFields = own.flattenedFields.map((entry) => (entry === field ? copy : entry))} + return copy +} + +/** The operations the plugin has a rule for. */ +const OPERATIONS = ['create', 'update', 'delete', 'unlock', 'read', 'readVersions'] + /** A copy of the field tree down to the `roles` field, so the project's own objects are not changed. */ const copyToRoles = (fields: FieldLike[] | undefined): FieldLike[] | undefined => fields?.map((field) => { @@ -253,16 +350,31 @@ export function applyStaffAccountAccess(config: Config, staffSlugs: string[], op return { ...config, collections: (config.collections ?? []).map((collection) => { - if (!collection.auth || !staffSlugs.includes(collection.slug)) {return collection} + if (!collection.auth) {return collection} + // Which operations have a rule of the project's NOW — later nobody can tell (Payload and the 2FA package fill + // the missing ones). Kept in the marker for a collection that becomes staff after ipalKit ran. + const own = OPERATIONS.filter((operation) => Boolean((collection.access as Record | undefined)?.[operation])) + if (!staffSlugs.includes(collection.slug)) { + return { ...collection, custom: { ...collection.custom, ipalAccounts: { slug: collection.slug, own, staff: false } satisfies AccountsMarker } } + } const copy = { ...collection, access: { ...collection.access }, fields: copyToRoles(collection.fields as FieldLike[]) as CollectionConfig['fields'] } - ruleStaffCollection(copy, options) + ruleStaffCollection(copy, options, 'config') return copy }), } } /** What was put on one late auth collection: for the log, which says only what was really done. */ -export type LateAdoption = { applied: string[]; firstUser: boolean; password: boolean; slug: string } +export type LateAdoption = { + applied: string[] + firstUser: boolean + /** The operations whose rule from the project's config was left as it is (a config collection that became staff later). */ + kept: string[] + /** True when the collection was in the config when ipalKit ran (and became staff afterwards); false when a later plugin added it. */ + known: boolean + password: boolean + slug: string +} /** * Collections that were not in the config when ipalKit ran — a plugin listed after it added them. @@ -279,14 +391,27 @@ export function adoptLateAuthCollections( ): LateAdoption[] { const adopted: LateAdoption[] = [] for (const collection of config.collections ?? []) { - const custom = collection.custom as { ipal?: { accountRules?: unknown }; ipalAccounts?: boolean } | undefined - if (!collection.auth || custom?.ipalAccounts) {continue} - collection.custom = { ...collection.custom, ipalAccounts: true } - const done: LateAdoption = { slug: collection.slug, applied: [], firstUser: false, password: false } - if (staffSlugs.includes(collection.slug)) { - if (access !== false && custom?.ipal?.accountRules !== false) {done.applied = ruleStaffCollection(collection, access ?? {}, true).applied} - if (beforeOperation) { - const hooks = (collection.hooks ?? {}) as { beforeOperation?: unknown[] } + if (!collection.auth) {continue} + const custom = collection.custom as { ipal?: { accountRules?: unknown } } | undefined + const staff = staffSlugs.includes(collection.slug) + // Handled already: under THIS slug, and as staff if it is staff now. A marker for another slug came along with + // a copy; a marker that says "not staff" on a collection that is staff now was made before it was named as one. + const marker = markerOf(collection) + if (marker?.slug === collection.slug && (marker.staff || !staff)) {continue} + // In the config when ipalKit ran, not staff then (a later plugin made it the panel's): the rules it had then stay. + const known = marker?.slug === collection.slug + const kept = known && Array.isArray(marker.own) ? marker.own : [] + const done: LateAdoption = { slug: collection.slug, applied: [], firstUser: false, kept: [], known, password: false } + // A staff collection gets the plugin's rules in front of its own. Any other late collection — not staff, or one + // that keeps its own rules — only where it carries a rule the plugin wrote for another collection (a copy). + const ruled = staff && access !== false && custom?.ipal?.accountRules !== false + done.kept = ruled ? kept : [] + done.applied = ruleStaffCollection(collection, access === false || !access ? {} : access, ruled ? 'late' : 'copied', kept).applied + collection.custom = { ...collection.custom, ipalAccounts: { slug: collection.slug, ...(kept.length ? { own: kept } : {}), staff } satisfies AccountsMarker } + if (staff) { + const hooks = (collection.hooks ?? {}) as { beforeOperation?: unknown[] } + // (a copied collection brings the original's hooks along: the password rule is put once) + if (beforeOperation && !(hooks.beforeOperation ?? []).some(isPasswordRuleHook)) { hooks.beforeOperation = [...(hooks.beforeOperation ?? []), beforeOperation] collection.hooks = hooks as CollectionConfig['hooks'] done.password = true @@ -301,9 +426,44 @@ export function adoptLateAuthCollections( return adopted } -/** Marks the auth collections ipalKit has seen at config time, so `adoptLateAuthCollections` leaves them alone. */ -export function markSeenAuthCollections(config: Config): Config { - return { ...config, collections: (config.collections ?? []).map((c) => (c.auth ? { ...c, custom: { ...c.custom, ipalAccounts: true } } : c)) } +/** + * Puts the plugin's mark on the rules it filled in during this run (`custom.ipalAccountRules.applied`, for the + * collection's own slug). Called AFTER the 2FA package has wrapped them — the mark must be on the function that is + * on the collection — and BEFORE ipal-kit's own 2FA guard, which carries the mark to its wrapper. Already marked + * functions are left, so it can run more than once. + */ +export function markStaffRules(config: Config): Config { + return { + ...config, + collections: (config.collections ?? []).map((c) => { + const record = (c.custom as { ipalAccountRules?: StaffAccountRules } | undefined)?.ipalAccountRules + if (!c.auth || !c.access || record?.slug !== c.slug) {return c} + const access = { ...c.access } as Record + for (const operation of record.applied) { + const rule = access[operation] + if (typeof rule === 'function' && !staffRuleOf(rule)) {access[operation] = markedStaffRule(rule as Access, c.slug)} + } + return { ...c, access: access as CollectionConfig['access'] } + }), + } +} + +/** + * Marks the auth collections ipalKit has seen at config time — with their slug and whether they are staff — so + * `adoptLateAuthCollections` leaves exactly those alone. + */ +export function markSeenAuthCollections(config: Config, staffSlugs: string[] = []): Config { + const marked = markStaffRules(config) // (a no-op where the plugin marked them before its 2FA guard) + return { + ...marked, + collections: (marked.collections ?? []).map((c) => { + if (!c.auth) {return c} + // (the rules the project wrote, noted before the 2FA package ran — applyStaffAccountAccess) + const before = markerOf(c) + const own = before?.slug === c.slug && Array.isArray(before.own) ? { own: before.own } : {} + return { ...c, custom: { ...c.custom, ipalAccounts: { slug: c.slug, ...own, staff: staffSlugs.includes(c.slug) } satisfies AccountsMarker } } + }), + } } /** Slugs named as staff that are not auth collections of the live config. */ @@ -482,7 +642,9 @@ export async function staffCollectionsOpenToOthers(payload: LivePayload): Promis * project's roles. For the doctor: the project should write its own rules. Slugs only. */ export function staffCollectionsOnOwnRoles(payload: LivePayload): string[] { + const staff = staffCollectionSlugs(payload as never) return Object.values(payload.collections ?? {}) + .filter(({ config }) => staff.includes(config.slug)) .map(({ config }) => ({ slug: config.slug, rules: (config as { custom?: { ipalAccountRules?: StaffAccountRules } }).custom?.ipalAccountRules })) .filter(({ rules }) => rules?.ownRoles && rules.applied.some((operation) => operation === 'create' || operation === 'update' || operation === 'delete')) .map(({ slug }) => slug) diff --git a/src/modules/security/totp/secondFactor.ts b/src/modules/security/totp/secondFactor.ts index 952d8e9..747a43f 100644 --- a/src/modules/security/totp/secondFactor.ts +++ b/src/modules/security/totp/secondFactor.ts @@ -1,5 +1,7 @@ import type { BasePayload, CollectionConfig, Config, GlobalConfig } from 'payload' +import { carryStaffRule } from '../../access/ruleMark.js' + /** * ipal-kit's own second-factor check, next to the access wrapper of * @clocklimited/payload-2fa. @@ -150,6 +152,8 @@ export function requireSecondFactor(access?: T): T { return access ? access(args as never) : Boolean(args.req?.user) }) as unknown as Guarded wrapped[GUARDED] = true + // the wrapper answers for the same rule: the plugin's mark on a staff account rule goes with it (access/ruleMark.ts) + carryStaffRule(access, wrapped) return wrapped as unknown as T } diff --git a/src/plugin.ts b/src/plugin.ts index ed49d04..aaacf4f 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -15,7 +15,7 @@ import { buildSiteSettings } from './globals/SiteSettings/index.js' import { adminOnly, adminOrSelfIn, injectRoles, registerStaffCollections, staffCollectionSlugs } from './modules/access/index.js' import { applyPanelRole, countBelowPanelRole, resolvePanelRole } from './modules/access/panelRole.js' import { applyPasswordRule, buildPasswordRuleHook, resolvePasswordRule } from './modules/access/passwordRule.js' -import { adoptLateAuthCollections, applyFirstUserRoute, applyStaffAccountAccess, markSeenAuthCollections, staffCollectionsNobodyManages, unknownStaffCollections } from './modules/access/selfRegistration.js' +import { adoptLateAuthCollections, applyFirstUserRoute, applyStaffAccountAccess, markSeenAuthCollections, markStaffRules, staffCollectionsNobodyManages, unknownStaffCollections } from './modules/access/selfRegistration.js' import { ROLE_HIERARCHY } from './modules/access/types.js' import { applyAdminI18n } from './modules/admin-i18n/apply.js' import { buildAdminImageEndpoints } from './modules/branding/adminImages.js' @@ -159,6 +159,11 @@ export const ipalKit = (options: IpalOptions): Plugin => { : {}), admin: { useAsTitle: 'email' }, auth: true, + // these rules are the plugin's, written for this slug (marked as such when ipalKit finishes) — not the ones + // the project passed in access.authAccess + ...(hasRoles + ? { custom: { ipalAccountRules: { slug: authSlug, applied: ['create', 'delete', 'read', 'unlock', 'update'].filter((k) => !(k in (options.access?.authAccess ?? {}))), ownRoles: false } } } + : {}), fields: [], }, ] @@ -207,7 +212,8 @@ export const ipalKit = (options: IpalOptions): Plugin => { // said exactly: what was put, on which collection for (const late of lateAccounts) { const parts = [late.applied.length ? `access rules for ${late.applied.join(', ')}` : '', late.password ? 'the password rule' : '', late.firstUser ? 'the first-user endpoint' : ''].filter(Boolean) - payload.logger.info(`[ipal] "${late.slug}" was added after ipalKit: put on it — ${parts.join('; ')}.`) + const kept = late.kept.length ? ` Its own rules for ${late.kept.join(', ')} are kept as written.` : '' + payload.logger.info(`[ipal] "${late.slug}" ${late.known ? 'became a staff collection after ipalKit ran' : 'was added after ipalKit'}: put on it — ${parts.join('; ')}.${kept}`) } } if (!secondFactorGuard) {return} @@ -891,6 +897,8 @@ export const ipalKit = (options: IpalOptions): Plugin => { // collections (wrapped by the package already; twice is harmless), the // plugin's globals and collections, the form builder's. if (secondFactorGuard) { + // the plugin's account rules get their mark first (the 2FA package has wrapped them by now): the guard carries it over + config = markStaffRules(config) config = guardConfigAccess(config) } @@ -987,7 +995,10 @@ export const ipalKit = (options: IpalOptions): Plugin => { } // Every auth collection of this config has been seen: what appears later is a late one (adoptConfig). - if (accounts) {config = markSeenAuthCollections(config)} + if (accounts) { + const panel = config.admin?.user ?? (config.collections ?? []).find((c) => c.auth)?.slug + config = markSeenAuthCollections(config, staffCollectionSlugs({ admin: { user: panel }, custom: config.custom })) + } return config } } diff --git a/test/accountCopyTable.test.ts b/test/accountCopyTable.test.ts new file mode 100644 index 0000000..cdf8bf5 --- /dev/null +++ b/test/accountCopyTable.test.ts @@ -0,0 +1,9 @@ +/** The copy rules as one table, 2FA off — see accountCopyTableSuite.ts. */ +import { vi } from 'vitest' + +import { copyTableSuite } from './accountCopyTableSuite.js' + +vi.mock('server-only', () => ({})) +vi.mock('next/headers.js', async () => (await import('./http/server.js')).nextHeadersMock) + +copyTableSuite(false) diff --git a/test/accountCopyTable2fa.test.ts b/test/accountCopyTable2fa.test.ts new file mode 100644 index 0000000..f315ca4 --- /dev/null +++ b/test/accountCopyTable2fa.test.ts @@ -0,0 +1,9 @@ +/** The copy rules as one table, 2FA ON — see accountCopyTableSuite.ts. */ +import { vi } from 'vitest' + +import { copyTableSuite } from './accountCopyTableSuite.js' + +vi.mock('server-only', () => ({})) +vi.mock('next/headers.js', async () => (await import('./http/server.js')).nextHeadersMock) + +copyTableSuite(true) diff --git a/test/accountCopyTableSuite.ts b/test/accountCopyTableSuite.ts new file mode 100644 index 0000000..206073d --- /dev/null +++ b/test/accountCopyTableSuite.ts @@ -0,0 +1,285 @@ +/** + * The copy rules as ONE table (review round 4 of the follow-ups: "a rule that cannot widen"). + * + * A plugin listed after ipalKit copies staff collections, reuses their access objects, wraps their rules, writes + * rules of its own next to them — every shape the reviews of 1.16.7's follow-ups tried (zzcopy3's table, R4-1, F-1, + * F-2, G-1, G-2, H-1, J-1, J-2). For every shape, every kind of account and every operation two things must hold: + * + * 1. NOT WIDER THAN 1.16.7. What an account may do is measured as a number (0 / 1, or how many documents it + * reads) and compared with the same measurement taken on the released 1.16.7 + * (test/fixtures/copyRulesBaseline.json, written by this suite with IPAL_COPY_BASELINE=write on that tree). + * 2. NOT WIDER THAN THE PLUGIN'S RULE for that collection: nobody from outside, no account of another staff + * collection that is not an admin, nobody raises its own role, and — on every shape — the account with the + * same id in the ORIGINAL collection is not "the account itself" (the one thing 1.16.7 itself had open). + * + * The plugin never replaces a rule on these collections; it puts its own in front (bothAllow). So both hold by + * construction, and this table is the proof on real HTTP. SQLite by default; Postgres / MongoDB with the usual + * variables; 2FA off and on (one file each). + */ +import type { CollectionConfig, Config, Field, Payload, Plugin } from 'payload' + +import { payloadTotp } from '@clocklimited/payload-2fa' +import { lexicalEditor } from '@payloadcms/richtext-lexical' +import { existsSync, readFileSync, writeFileSync } from 'node:fs' +import os from 'os' +import path from 'path' +import { getPayload } from 'payload' +import { expect, test } from 'vitest' + +import { ipalKit } from '../src/plugin.js' +import { buildTestConfig } from './helpers.js' +import { testDatabase } from './http/db.js' +import { startPayloadServer } from './http/server.js' + +const PASSWORD = 'a-long-test-password-1' +const BASELINE = path.resolve(import.meta.dirname, 'fixtures/copyRulesBaseline.json') +const MARK = Symbol.for('ipal.staffRule') + +const roles = (options: string[], extra: Record = {}): Field => ({ name: 'roles', type: 'select', hasMany: true, options, saveToJWT: true, ...extra }) as Field +const PLUGIN = ['user', 'editor', 'admin'] +const MORE = ['user', 'editor', 'admin', 'boss'] +const note: Field = { name: 'note', type: 'text' } +const nobody = () => false +/** A function with a hand-made mark, as deliberate code could write one. */ +const forged = unknown>(fn: T, mark: Record): T => { + Object.defineProperty(fn, MARK, { configurable: true, value: { self: fn, ...mark } }) + return fn +} + +/** Shapes that are NOT named in `access.staffCollections`. */ +const NOT_STAFF = ['nonstaff', 'crewnon', 'crossopt', 'ownvalsnon', 'teamnon'] + +const late: Plugin = (config: Config) => { + const of = (slug: string) => (config.collections ?? []).find((c) => c.slug === slug)! + const a = of('agents') + const acc = a.access! + const optOut = { ...a.custom, ipal: { accountRules: false } } + const shapes: CollectionConfig[] = [ + { ...a, slug: 'plain' }, + { ...a, slug: 'ownrules', access: { ...acc, create: nobody, delete: nobody, read: ({ req }) => ((req.user as { roles?: string[] } | null)?.roles?.includes('admin') ? { email: { equals: 'victim@ownrules.example.com' } } : false), update: nobody } }, + { ...a, slug: 'ownfield', fields: [roles(PLUGIN, { access: { update: nobody } }), note] }, + { ...a, slug: 'optout', custom: optOut }, + { ...a, slug: 'nonstaff' }, + { ...of('users'), slug: 'userscopy' }, + { ...of('proj'), slug: 'projcopy' }, + { ...a, slug: 'lesscopy', access: { create: acc.create } }, + // one rule of the original used for other operations + { ...a, slug: 'crossop', access: { ...acc, read: acc.create, update: acc.create } }, + { ...a, slug: 'crossopt', access: { ...acc, read: acc.create, update: acc.create } }, + // wrappers that are not the plugin's + { ...a, slug: 'proxied', access: { ...acc, create: new Proxy(acc.create!, { apply: nobody }), read: new Proxy(acc.read!, { apply: nobody }), update: new Proxy(acc.update!, { apply: nobody }) } }, + { ...a, slug: 'protod', access: { ...acc, update: Object.setPrototypeOf(() => false, acc.update!) as never } }, + { ...a, slug: 'mimic', access: { ...acc, update: Object.defineProperties(() => false, Object.getOwnPropertyDescriptors(acc.update!)) as never } }, + { ...a, slug: 'bound', access: { ...acc, update: acc.update!.bind(null) } }, + { ...a, slug: 'wrapnarrow', access: { ...acc, read: async (x) => Boolean(await acc.read!(x)) && Boolean((x.req.user as { roles?: string[] } | null)?.roles?.includes('admin')), update: async (x) => Boolean(await acc.update!(x)) && Boolean((x.req.user as { roles?: string[] } | null)?.roles?.includes('admin')) } }, + { ...a, slug: 'whererule', access: { ...acc, read: () => ({ email: { equals: 'low@whererule.example.com' } }), update: () => ({ email: { equals: 'nobody@example.com' } }) } }, + { ...a, slug: 'frozen', access: Object.freeze({ ...acc, update: Object.freeze(() => false) }) }, + { ...a, slug: 'shared1' }, + { ...a, slug: 'shared2', access: { ...acc, delete: acc.update } }, + { ...a, slug: 'hookproxy', hooks: { ...a.hooks, beforeOperation: (a.hooks?.beforeOperation ?? []).map((hook) => new Proxy(hook, {})) } }, + // the opt-out with rules of its own + { ...a, slug: 'optopen', access: { ...acc, create: () => true, read: () => true }, custom: optOut }, + { ...a, slug: 'optsame', custom: optOut, fields: [roles(PLUGIN), note] }, // J-2: its own roles field, no field access + { ...a, slug: 'optvals', custom: optOut, fields: [roles(MORE), note] }, + { ...a, slug: 'optplain', custom: optOut }, + // other role values than the original's + { ...a, slug: 'ownvals', fields: [roles(MORE)] }, // H-1 + { ...a, slug: 'ownvalsnon', fields: [roles(MORE)] }, + { slug: 'freshown', access: { ...acc }, auth: true, fields: [roles(MORE)] }, + { ...a, slug: 'renamed', fields: [roles(['lead', 'member']), note] }, + { ...a, slug: 'noroles', fields: [note] }, + { ...of('crew'), slug: 'crewcopy' }, + { ...of('crew'), slug: 'crewnon' }, + { ...of('crew'), slug: 'crewadmin', fields: [roles(PLUGIN)] }, + { ...of('team'), slug: 'teamcopy' }, + { ...of('team'), slug: 'teamnon' }, + { ...of('team'), slug: 'teamadmin', fields: [roles(PLUGIN)] }, // J-1: "an account of the collection" on a collection with `admin` + { slug: 'teamfresh', access: { ...of('team').access }, auth: true, fields: [roles(PLUGIN)] }, + // hand-made marks + { slug: 'forged', access: { create: forged(() => true, { slug: 'forged' }), update: forged(() => false, { slug: 'elsewhere' }) }, auth: true, fields: [roles(PLUGIN)] }, + { ...a, slug: 'handmark', access: { ...acc, update: Object.defineProperty(() => false, MARK, { configurable: true, value: (acc.update as unknown as Record)[MARK] }) as never } }, + { slug: 'liar', access: { create: forged(() => true, { slug: 'agents', kind: 'bogus', operation: 'bogus' }), update: forged(() => false, { slug: 'agents', kind: 'admin', operation: 'update' }) }, auth: true, fields: [roles(PLUGIN)] }, + { slug: 'protoop', access: { create: forged(() => false, { slug: 'agents', kind: 'toString', operation: 'toString' }), read: forged(() => false, { slug: 'agents', kind: 'toString', operation: 'toString' }) }, auth: true, fields: [roles(PLUGIN)] }, + ] + return { ...config, collections: [...(config.collections ?? []), ...shapes] } +} + +type Session = Record +type Table = Record + +/** One Payload instance per test file: run from a file of its own for 2FA off and on. */ +export function copyTableSuite(twoFactor: boolean): void { + test(`copies of staff collections: never wider than 1.16.7, never wider than the plugin's rule (2FA on: ${twoFactor})`, async () => { + let shapeSlugs: string[] = [] + const capture: Plugin = (config) => { + shapeSlugs = (config.collections ?? []).filter((c) => c.auth).map((c) => c.slug).filter((slug) => !['agents', 'crew', 'customers', 'proj', 'team', 'users'].includes(slug)) + return config + } + const staffShapes = (all: string[]) => all.filter((slug) => !NOT_STAFF.includes(slug)) + // the slugs are needed for `access.staffCollections` before the late plugin runs: build them once from a dry call + const names = ((late({ collections: [{ slug: 'agents', access: { create: nobody, read: nobody, update: nobody }, auth: true, fields: [] }, { slug: 'users', auth: true, fields: [] }, { slug: 'proj', auth: true, fields: [] }, { slug: 'crew', auth: true, fields: [] }, { slug: 'team', auth: true, fields: [] }] } as never) as Config).collections ?? []).map((c) => c.slug).filter((slug) => !['agents', 'crew', 'proj', 'team', 'users'].includes(slug)) + const config = buildTestConfig({ + admin: { user: 'users' }, + collections: [ + { slug: 'customers', access: { create: () => true }, auth: true, fields: [] }, + { slug: 'agents', auth: true, fields: [roles(PLUGIN), note] }, + { slug: 'crew', auth: true, fields: [roles(['user', 'boss', 'admin'])] }, + { slug: 'team', auth: true, fields: [roles(['lead', 'member'])] }, + { slug: 'proj', access: { update: ({ req }) => (req.user as { email?: string } | null)?.email === 'boss@example.com' }, auth: true, fields: [roles(PLUGIN)] }, + { slug: 'media', fields: [], upload: { staticDir: path.join(os.tmpdir(), 'ipal-test-media') } }, + ], + db: testDatabase(twoFactor ? 'copy_table_2fa' : 'copy_table'), + editor: lexicalEditor(), + plugins: [ + ipalKit({ + access: { authCollection: 'users', staffCollections: ['agents', 'crew', 'team', 'proj', ...staffShapes(names)] }, + i18n: { defaultLocale: 'en', locales: [{ code: 'en', label: 'English' }] }, + twoFactor: twoFactor ? { issuer: 'Example', plugin: payloadTotp, verifyLimit: false } : false, + }), + late, + capture, + ], + secret: 'integration-test-secret-0123456789', + telemetry: false, + }) + const payload: Payload = await getPayload({ config }) + const server = await startPayloadServer(config) + const call = (method: string, pathname: string, session: Session = {}, body?: unknown) => + fetch(`${server.url}/api${pathname}`, { body: body === undefined ? undefined : JSON.stringify(body), headers: { 'content-type': 'application/json', ...session }, method }) + const make = async (collection: string, email: string, value: string[] | undefined) => { + try { + return await payload.create({ collection: collection as never, data: { email, password: PASSWORD, ...(value ? { roles: value } : {}) } as never }) + } catch { + return null + } + } + const login = async (collection: string, email: string): Promise => { + const body = (await (await call('POST', `/${collection}/login`, {}, { email, password: PASSWORD })).json()) as { token?: string } + return body.token ? { authorization: `JWT ${body.token}` } : null + } + const rolesOf = async (collection: string, id: unknown) => JSON.stringify(((await payload.findByID({ id: id as never, collection: collection as never }).catch(() => null)) as { roles?: unknown } | null)?.roles ?? null) + const reset = (collection: string, id: unknown, data: Record) => payload.update({ id: id as never, collection: collection as never, data: data as never }).catch(() => null) + try { + // the original's first account: on the SQL adapters it has the same id as the first account of every copy + await make('agents', 'low@agents.example.com', ['user']) + await make('agents', 'admin@agents.example.com', ['admin']) + await call('POST', '/customers', {}, { email: 'visitor@example.com', password: PASSWORD }) + const outside: [string, Session][] = [ + ['anonymous', {}], + ['customer', (await login('customers', 'visitor@example.com'))!], + ['namesake', (await login('agents', 'low@agents.example.com'))!], // an `agents` account with the role user + ['agentsAdmin', (await login('agents', 'admin@agents.example.com'))!], + ] + const table: Table = {} + const shapes: Record = {} + for (const slug of shapeSlugs) { + const collection = payload.collections[slug as never].config as CollectionConfig + const field = (collection.fields as { name?: string; options?: unknown[]; type?: string }[]).find((f) => f.name === 'roles') + const options = field?.type === 'select' && Array.isArray(field.options) ? field.options.map((o) => (typeof o === 'string' ? o : (o as { value: string }).value)) : null + const low = field ? [options?.includes('user') ? 'user' : (options?.at(-1) ?? 'user')] : undefined + const top = field ? [options?.includes('admin') ? 'admin' : (options?.[0] ?? 'admin')] : undefined + shapes[slug] = { + adminRules: Boolean(field) && (!options || options.some((o) => o === 'editor' || o === 'admin') || options.every((o) => PLUGIN.includes(o))), + hasRoles: Boolean(field), + optOut: (collection.custom as { ipal?: { accountRules?: unknown } } | undefined)?.ipal?.accountRules === false, + staff: !NOT_STAFF.includes(slug), + } + const mine = await make(slug, `low@${slug}.example.com`, low) // FIRST: the namesake's twin + let victim = await make(slug, `victim@${slug}.example.com`, low) + const boss = await make(slug, `top@${slug}.example.com`, top) + if (!mine || !victim || !boss) {continue} // the shape cannot hold accounts on this tree: nothing to compare + // The shape's own accounts log in at the START of their turn: a password that was put back after another + // actor's turn ends the sessions an account had (and an account that cannot log in has no rows). + const actors: [string, (() => Promise) | Session][] = [...outside, ['ownLow', () => login(slug, `low@${slug}.example.com`)], ['ownTop', () => login(slug, `top@${slug}.example.com`)]] + for (const [actor, who] of actors) { + const session = typeof who === 'function' ? await who() : who + if (!session) {continue} + if (actor === 'ownLow' || actor === 'ownTop') { + // a session that works at all: `me` answers with the account + const me = (await (await call('GET', `/${slug}/me`, session)).json()) as { user?: { email?: string } | null } + table[`${slug} | ${actor} | signedIn`] = me.user?.email ? 1 : 0 + } + const set = (action: string, value: number) => { + table[`${slug} | ${actor} | ${action}`] = value + } + const list = await call('GET', `/${slug}?limit=100`, session) + set('read', list.status === 200 ? (((await list.json()) as { totalDocs?: number }).totalDocs ?? 0) : 0) + const made = `made-${actor}@${slug}.example.com` + set('create', (await call('POST', `/${slug}`, session, { email: made, password: PASSWORD, ...(top ? { roles: top } : {}) })).status === 201 ? 1 : 0) + await payload.delete({ collection: slug as never, where: { email: { equals: made } } }).catch(() => null) + set('patchVictim', (await call('PATCH', `/${slug}/${victim.id}`, session, { password: 'taken-over-password-1' })).status === 200 ? 1 : 0) + if (actor !== 'ownTop') {set('patchTop', (await call('PATCH', `/${slug}/${boss.id}`, session, { password: 'taken-over-password-1' })).status === 200 ? 1 : 0)} + // the account with the SAME id as the namesake's own (R4-1) + if (actor !== 'ownLow') {set('patchTwin', (await call('PATCH', `/${slug}/${mine.id}`, session, { password: 'taken-over-password-1' })).status === 200 ? 1 : 0)} + if (actor === 'ownLow') { + if (top) { + const before = await rolesOf(slug, mine.id) + await call('PATCH', `/${slug}/${mine.id}`, session, { roles: top }) + await call('PATCH', `/${slug}?where[email][equals]=low@${slug}.example.com`, session, { roles: top }) + set('raiseSelf', (await rolesOf(slug, mine.id)) === before ? 0 : 1) + await reset(slug, mine.id, { roles: low }) + } + } + if (top) { + const before = await rolesOf(slug, victim.id) + await call('PATCH', `/${slug}/${victim.id}`, session, { roles: top }) + set('rolesVictim', (await rolesOf(slug, victim.id)) === before ? 0 : 1) + await reset(slug, victim.id, { roles: low }) + } + set('unlock', (await call('POST', `/${slug}/unlock`, session, { email: `victim@${slug}.example.com` })).status === 200 ? 1 : 0) + const gone = (await call('DELETE', `/${slug}/${victim.id}`, session)).status === 200 + set('delete', gone ? 1 : 0) + if (gone) {victim = (await make(slug, `victim@${slug}.example.com`, low))!} + // last in its turn: a new password ends the account's own session + if (actor === 'ownLow') {set('ownPassword', (await call('PATCH', `/${slug}/${mine.id}`, session, { password: 'my-own-new-password-1' })).status === 200 ? 1 : 0)} + for (const [id, email] of [[victim.id, `victim@${slug}.example.com`], [boss.id, `top@${slug}.example.com`], [mine.id, `low@${slug}.example.com`]] as [unknown, string][]) { + await reset(slug, id, { email, password: PASSWORD }) + } + } + } + expect(Object.keys(table).length).toBeGreaterThan(1000) + // the table measures something: the shapes' own accounts were signed in, and on a plain staff copy staff reads staff + expect(Object.keys(table).filter((key) => key.endsWith('| signedIn') && table[key] === 1).length).toBeGreaterThan(40) + expect(table['plain | ownTop | read']).toBeGreaterThan(0) + + if (process.env.IPAL_COPY_BASELINE === 'write') { + writeFileSync(BASELINE, `${JSON.stringify(table, null, 1)}\n`) + return + } + // ── 1. not wider than 1.16.7 ── + expect(existsSync(BASELINE), 'test/fixtures/copyRulesBaseline.json (IPAL_COPY_BASELINE=write on the 1.16.7 tree)').toBe(true) + const baseline = JSON.parse(readFileSync(BASELINE, 'utf8')) as Table + const compared = Object.keys(table).filter((key) => key in baseline) + expect(compared.length).toBeGreaterThan(1000) + expect(Object.keys(shapes).filter((slug) => !compared.some((key) => key.startsWith(`${slug} | `)))).toEqual([]) // every shape is in the baseline + const wider = compared.filter((key) => table[key] > baseline[key]).map((key) => `${key}: ${baseline[key]} → ${table[key]}`) + expect(wider, 'wider than 1.16.7').toEqual([]) + + // ── 2. not wider than the plugin's rule ── + const over: string[] = [] + const must = (key: string, most: number) => { + if (key in table && table[key] > most) {over.push(`${key}: ${table[key]} (at most ${most})`)} + } + const WRITES = ['create', 'patchVictim', 'patchTop', 'patchTwin', 'rolesVictim', 'unlock', 'delete'] + for (const [slug, shape] of Object.entries(shapes)) { + // on EVERY shape: the original's account with the same id is not "the account itself", and nobody raises its own role + must(`${slug} | namesake | patchTwin`, 0) + if (shape.hasRoles) {must(`${slug} | ownLow | raiseSelf`, 0)} + if (!shape.staff || shape.optOut) {continue} // its own rules decide the rest (part 1 holds them to 1.16.7) + for (const actor of ['anonymous', 'customer']) { + for (const action of ['read', ...WRITES]) {must(`${slug} | ${actor} | ${action}`, 0)} + } + // a staff account of ANOTHER collection that is not an admin writes nothing + for (const action of WRITES) {must(`${slug} | namesake | ${action}`, 0)} + // where the admin rules apply, the collection's own lowest account writes nothing but itself + if (shape.adminRules) { + for (const action of WRITES.filter((a) => a !== 'patchTwin')) {must(`${slug} | ownLow | ${action}`, 0)} + } + } + expect(over, "wider than the plugin's rule").toEqual([]) + } finally { + await server.close() + await payload.destroy?.() + } + }, 600_000) +} diff --git a/test/accountRulesLateStaff.test.ts b/test/accountRulesLateStaff.test.ts new file mode 100644 index 0000000..a81ae46 --- /dev/null +++ b/test/accountRulesLateStaff.test.ts @@ -0,0 +1,9 @@ +/** A config collection that a later plugin makes the panel's, 2FA off — see accountRulesLateStaffSuite.ts. */ +import { vi } from 'vitest' + +import { lateStaffSuite } from './accountRulesLateStaffSuite.js' + +vi.mock('server-only', () => ({})) +vi.mock('next/headers.js', async () => (await import('./http/server.js')).nextHeadersMock) + +lateStaffSuite(false) diff --git a/test/accountRulesLateStaff2fa.test.ts b/test/accountRulesLateStaff2fa.test.ts new file mode 100644 index 0000000..e8f997f --- /dev/null +++ b/test/accountRulesLateStaff2fa.test.ts @@ -0,0 +1,9 @@ +/** A config collection that a later plugin makes the panel's, 2FA ON — see accountRulesLateStaffSuite.ts. */ +import { vi } from 'vitest' + +import { lateStaffSuite } from './accountRulesLateStaffSuite.js' + +vi.mock('server-only', () => ({})) +vi.mock('next/headers.js', async () => (await import('./http/server.js')).nextHeadersMock) + +lateStaffSuite(true) diff --git a/test/accountRulesLateStaffSuite.ts b/test/accountRulesLateStaffSuite.ts new file mode 100644 index 0000000..5202a49 --- /dev/null +++ b/test/accountRulesLateStaffSuite.ts @@ -0,0 +1,103 @@ +/** + * A collection of the config that becomes staff LATER (review of the copy rules, L-2): `people` is in the config and + * is not named as staff; a plugin listed after ipalKit sets `admin.user` to it. At config time the plugin saw which + * operations had a rule of the project's (the marker's `own`); when the collection is handled again at start: + * - an operation that HAD a rule keeps it, exactly as written (here `create`: any signed-in account); + * - an operation that had none gets the plugin's rule (on 1.16.7 a visitor account changed and deleted panel + * accounts there: Payload's default). + * Real HTTP; SQLite by default, Postgres / MongoDB with the usual variables; 2FA off and on (one file each). + */ +import type { Config, Payload, Plugin } from 'payload' + +import { payloadTotp } from '@clocklimited/payload-2fa' +import { lexicalEditor } from '@payloadcms/richtext-lexical' +import os from 'os' +import path from 'path' +import { getPayload } from 'payload' +import { expect, test } from 'vitest' + +import { ipalKit } from '../src/plugin.js' +import { buildTestConfig } from './helpers.js' +import { testDatabase } from './http/db.js' +import { startPayloadServer } from './http/server.js' + +const PASSWORD = 'a-long-test-password-1' + +/** The later plugin: the panel logs in with `people` from now on. */ +const panelIsPeople: Plugin = (config: Config) => ({ ...config, admin: { ...config.admin, user: 'people' } }) + +/** One Payload instance per test file: run from a file of its own for 2FA off and on. */ +export function lateStaffSuite(twoFactor: boolean): void { + test(`a config collection a later plugin makes the panel's: its own rules stay, the missing ones are the plugin's (2FA on: ${twoFactor})`, async () => { + const config = buildTestConfig({ + admin: { user: 'users' }, + collections: [ + { slug: 'customers', access: { create: () => true }, auth: true, fields: [] }, + { slug: 'people', access: { create: ({ req }) => Boolean(req.user) }, auth: true, fields: [{ name: 'roles', type: 'select', hasMany: true, options: ['user', 'editor', 'admin'], saveToJWT: true }] }, + { slug: 'media', fields: [], upload: { staticDir: path.join(os.tmpdir(), 'ipal-test-media') } }, + ], + db: testDatabase(twoFactor ? 'late_staff_2fa' : 'late_staff'), + editor: lexicalEditor(), + plugins: [ + ipalKit({ access: { authCollection: 'users' }, i18n: { defaultLocale: 'en', locales: [{ code: 'en', label: 'English' }] }, twoFactor: twoFactor ? { issuer: 'Example', plugin: payloadTotp, verifyLimit: false } : false }), + panelIsPeople, + ], + secret: 'integration-test-secret-0123456789', + telemetry: false, + }) + const payload: Payload = await getPayload({ config }) + const server = await startPayloadServer(config) + type Session = Record + const call = (method: string, pathname: string, session: Session = {}, body?: unknown) => + fetch(`${server.url}/api${pathname}`, { body: body === undefined ? undefined : JSON.stringify(body), headers: { 'content-type': 'application/json', ...session }, method }) + const login = async (collection: string, email: string): Promise => { + const body = (await (await call('POST', `/${collection}/login`, {}, { email, password: PASSWORD })).json()) as { token?: string } + if (!body.token) {throw new Error(`login failed for ${email}`)} + return { authorization: `JWT ${body.token}` } + } + const make = (email: string, role: string) => payload.create({ collection: 'people' as never, data: { email, password: PASSWORD, roles: [role] } as never }) + const rolesOf = async (id: number | string) => ((await payload.findByID({ id, collection: 'people' as never, overrideAccess: true })) as { roles?: string[] }).roles + try { + // what the plugin wrote down, and what it put + const custom = payload.collections['people' as never].config.custom as { ipalAccountRules?: { applied: string[] }; ipalAccounts?: unknown } + expect(custom.ipalAccounts).toEqual({ slug: 'people', own: ['create'], staff: true }) + expect([...custom.ipalAccountRules!.applied].sort()).toEqual(['delete', 'read', 'readVersions', 'roles', 'unlock', 'update']) + + const victim = await make('victim@example.com', 'user') + const low = await make('low@example.com', 'user') + await make('admin@example.com', 'admin') + expect((await call('POST', '/customers', {}, { email: 'visitor@example.com', password: PASSWORD })).status).toBe(201) + const visitor = await login('customers', 'visitor@example.com') + const lowSession = await login('people', 'low@example.com') + const adminSession = await login('people', 'admin@example.com') + const got: Record = {} + for (const [who, session] of [['nobody', {}], ['visitor', visitor], ['low', lowSession]] as [string, Session][]) { + got[who] = { + create: (await call('POST', '/people', session, { email: `by-${who}@example.com`, password: PASSWORD })).status, + delete: (await call('DELETE', `/people/${victim.id}`, session)).status, + patch: (await call('PATCH', `/people/${victim.id}`, session, { password: `changed-by-${who}-123456` })).status, + read: (await call('GET', '/people', session)).status, + unlock: (await call('POST', '/people/unlock', session, { email: 'victim@example.com' })).status, + } + } + const no = { create: 403, delete: 403, patch: 403, read: 403, unlock: 403 } + expect(got).toEqual({ + low: { ...no, create: 201, read: 200 }, // the plugin's rules: an admin, or the account itself + nobody: no, + // `create` is the project's own rule ("any signed-in account"): kept as written. The rest had no rule: the plugin's. + visitor: { ...no, create: 201 }, + }) + // the account itself: may edit itself, never its own roles + expect((await call('PATCH', `/people/${low.id}`, lowSession, { roles: ['admin'] })).status).toBe(200) + expect(await rolesOf(low.id)).toEqual(['user']) + // an admin of the collection manages it + expect((await call('PATCH', `/people/${victim.id}`, adminSession, { roles: ['editor'] })).status).toBe(200) + expect(await rolesOf(victim.id)).toEqual(['editor']) + expect((await call('POST', '/people/unlock', adminSession, { email: 'victim@example.com' })).status).toBe(200) + expect((await call('DELETE', `/people/${victim.id}`, adminSession)).status).toBe(200) + } finally { + await server.close() + await payload.destroy?.() + } + }, 120_000) +} diff --git a/test/accountRulesSuite.ts b/test/accountRulesSuite.ts index 322b16b..3f06589 100644 --- a/test/accountRulesSuite.ts +++ b/test/accountRulesSuite.ts @@ -17,9 +17,12 @@ import { afterAll, beforeAll, describe, expect, test } from 'vitest' import type { I18nConfig } from '../src/modules/i18n/types.js' +import { adminOrSelfIn } from '../src/modules/access/index.js' import { countBelowPanelRole, panelAccess, resolvePanelRole } from '../src/modules/access/panelRole.js' -import { checkPassword, resolvePasswordRule } from '../src/modules/access/passwordRule.js' -import { adoptLateAuthCollections, bothAllow, canHoldStaffRole, hasPluginRoles, openSignUpCollections, rolesAreAList, rolesByAdminOnly, rolesNotOwn, sameStaffCollectionAccess, staffCollectionsNobodyManages, staffCollectionsOnOwnRoles, staffCollectionsOpenToOthers, staffCreateAccess, staffReadAccess, staffUpdateAccess, unknownStaffCollections } from '../src/modules/access/selfRegistration.js' +import { buildPasswordRuleHook, checkPassword, resolvePasswordRule } from '../src/modules/access/passwordRule.js' +import { isPasswordRuleHook, markedStaffRule, staffRuleOf } from '../src/modules/access/ruleMark.js' +import { adoptLateAuthCollections, bothAllow, canHoldStaffRole, hasPluginRoles, openSignUpCollections, rolesAreAList, rolesNotOwn, sameStaffCollectionAccess, staffCollectionsNobodyManages, staffCollectionsOnOwnRoles, staffCollectionsOpenToOthers, staffCreateAccess, staffReadAccess, staffUpdateAccess, unknownStaffCollections } from '../src/modules/access/selfRegistration.js' +import { requireSecondFactor } from '../src/modules/security/totp/secondFactor.js' import { ipalKit } from '../src/plugin.js' import { buildTestConfig, withTotpParts } from './helpers.js' import { testDatabase } from './http/db.js' @@ -555,8 +558,11 @@ export function accountRulesSuite(twoFactor: boolean): void { expect([of(own, 'users').access?.create, of(own, 'users').access?.update, of(own, 'users').access?.delete]).toEqual([mine, mine, mine]) // the collection that carries the plugin's roles: the admin rule, although the field is injected later const ownNoRule = await build({}, { collections: [{ slug: 'users', auth: true, fields: [] }] } as never) - expect(of(ownNoRule, 'users').access?.create).toBe(staffCreateAccess) - expect(of(ownNoRule, 'users').access?.delete).toBe(staffCreateAccess) + // (the plugin's rules carry its mark for the slug, on the function: that is how a copy of the collection is told later) + expect(['create', 'delete', 'update', 'unlock', 'read', 'readVersions'].map((op) => staffRuleOf((of(ownNoRule, 'users').access as Record)[op])?.slug)).toEqual(Array(6).fill('users')) + expect(await (of(ownNoRule, 'users').access!.create as (a: unknown) => unknown)({ req: { payload: { staffCollections: ['users'] }, user: { id: 1, collection: 'users', roles: ['editor'] } } })).toBe(false) + expect(staffRuleOf(mine)).toBeUndefined() // a rule the project wrote is not marked + expect(staffRuleOf(staffCreateAccess)).toBeUndefined() // nor the exported rule itself: the mark is on a function of its own }) test('whose roles: the plugin\'s rule only where the roles are the plugin\'s', () => { @@ -622,7 +628,7 @@ export function accountRulesSuite(twoFactor: boolean): void { expect([guards(on, 'users'), guards(on, 'staff2'), guards(on, 'customers'), guards(on, 'pages')]).toEqual([1, 1, 0, 0]) expect([firstUser(on, 'users'), firstUser(on, 'staff2'), firstUser(on, 'customers'), firstUser(on, 'pages')]).toEqual([1, 1, 1, 0]) const payloadWay = await build({ accounts: { adminOnlyCreate: false, adminOnlyWrite: false, firstUserRoute: 'all', password: false } }) - expect(of(payloadWay, 'staff2').access).toEqual({ read: staffReadAccess, readVersions: staffReadAccess }) + expect(Object.keys(of(payloadWay, 'staff2').access ?? {}).sort()).toEqual(['read', 'readVersions']) expect(of(await build({ accounts: { adminOnlyCreate: false, adminOnlyWrite: false, firstUserRoute: 'all', password: false, staffOnlyRead: false } }), 'staff2').access).toBeUndefined() expect([guards(payloadWay, 'staff2'), firstUser(payloadWay, 'staff2')]).toEqual([0, 0]) // each switch on its own @@ -642,7 +648,7 @@ export function accountRulesSuite(twoFactor: boolean): void { // without the plugin's roles nobody is an admin to it const noAccess = await ipalKit({ i18n, twoFactor: false })({ collections: [{ slug: 'users', auth: true, fields: [] }], secret: 'x' } as unknown as Config) expect(of(noAccess, 'users').access?.create).toBeTypeOf('function') - expect(of(noAccess, 'users').access?.create).not.toBe(staffCreateAccess) + expect(await (of(noAccess, 'users').access!.create as (a: unknown) => unknown)({ req: { payload: { staffCollections: ['users'] }, user: { id: 1, collection: 'users' } } })).toBe(true) }) test('the roles field: protected where the plugin\'s update rule is in force and the field has no access of its own', async () => { @@ -651,7 +657,10 @@ export function accountRulesSuite(twoFactor: boolean): void { const collections = (extra: object = {}, field: object = own) => ({ collections: [{ slug: 'staff2', auth: true, fields: [{ type: 'row', fields: [field] }], ...extra }] }) as never const inRow = (config: Config) => (of(config, 'staff2').fields[0] as unknown as { fields: { access?: { update?: unknown } }[] }).fields[0] // the plugin's roles: only an admin; found inside a row too; the project's own field object is not changed - expect(inRow(await build({}, collections())).access?.update).toBe(rolesByAdminOnly) + const fieldRule0 = inRow(await build({}, collections())).access?.update as (a: unknown) => boolean + expect(staffRuleOf(fieldRule0)?.slug).toBe('staff2') + expect(fieldRule0({ req: { payload: { staffCollections: ['staff2'] }, user: { id: 1, collection: 'staff2', roles: ['editor'] } } })).toBe(false) + expect(fieldRule0({ req: { payload: { staffCollections: ['staff2'] }, user: { id: 1, collection: 'staff2', roles: ['admin'] } } })).toBe(true) expect((own as { access?: unknown }).access).toBeUndefined() // roles of the project's own: never the account itself const mine = inRow(await build({}, collections({}, { ...own, options: ['boss', 'worker'] }))).access?.update as (a: unknown) => boolean @@ -671,23 +680,75 @@ export function accountRulesSuite(twoFactor: boolean): void { // Review round 3 (R3-1): nothing may depend on recognising Payload's default — a production build minifies // its name away. The functions below have the names a bundler gives them: none that means anything. + // Review of the copy rules (L-2): a collection that WAS in the config and becomes staff later (a later plugin sets + // `admin.user`). The plugin noted at config time which operations had a rule; those stay as written. + test('a config collection that becomes staff later keeps the rules it had at config time', async () => { + const own = ({ req }: { req: { user: unknown } }) => Boolean(req.user) + const rolesField = () => ({ name: 'roles', type: 'select', hasMany: true, options: ['user', 'editor', 'admin'] }) + const { ipalKit } = await import('../src/plugin.js') + const built = await ipalKit({ access: { authCollection: 'users' }, i18n, twoFactor: false } as never)({ + admin: { user: 'users' }, + collections: [ + { slug: 'users', auth: true, fields: [] }, + { slug: 'none', auth: true, fields: [rolesField()] }, + { slug: 'some', access: { create: own, update: own }, auth: true, fields: [rolesField()] }, + { slug: 'pages', fields: [] }, + ], + secret: 'x', + } as unknown as Config) + const of = (slug: string) => built.collections!.find((c) => c.slug === slug)! + expect(of('none').custom?.ipalAccounts).toEqual({ slug: 'none', own: [], staff: false }) + expect(of('some').custom?.ipalAccounts).toEqual({ slug: 'some', own: ['create', 'update'], staff: false }) + expect(of('users').custom?.ipalAccounts).toEqual({ slug: 'users', staff: true }) + expect(of('pages').custom?.ipalAccounts).toBeUndefined() + // Payload sanitizes: every missing rule is a function now, none with a telling name + const filled = (slug: string) => { + const c = of(slug) + const access = Object.fromEntries(['create', 'update', 'delete', 'unlock', 'read', 'readVersions'].map((operation) => [operation, (c.access as Record)?.[operation] ?? (({ req }: { req: { user: unknown } }) => Boolean(req.user))])) + return { ...c, access, endpoints: [] } + } + const none = filled('none') + const some = filled('some') + // a copy of it under a new slug brings the marker along: its `own` says nothing about the copy + const copy = { ...filled('some'), slug: 'copy' } + const config = { collections: [none, some, copy] } as never + expect(adoptLateAuthCollections(config, ['none', 'some', 'copy'], { access: {}, firstUserRoute: 'all' })).toEqual([ + { slug: 'none', applied: ['create', 'update', 'delete', 'unlock', 'read', 'readVersions', 'roles'], firstUser: false, kept: [], known: true, password: false }, + { slug: 'some', applied: ['delete', 'unlock', 'read', 'readVersions'], firstUser: false, kept: ['create', 'update'], known: true, password: false }, + { slug: 'copy', applied: ['create', 'update', 'delete', 'unlock', 'read', 'readVersions', 'roles'], firstUser: false, kept: [], known: false, password: false }, + ]) + // the kept rules are the very functions the project wrote; the roles field is not guarded where its own `update` rule stays (as at config time) + expect([(some.access as Record).create, (some.access as Record).update]).toEqual([own, own]) + expect((some.fields as { access?: unknown }[])[0].access).toBeUndefined() + expect(some.custom?.ipalAccounts).toEqual({ slug: 'some', own: ['create', 'update'], staff: true }) + const visitor = { req: { payload: { config: { admin: { user: 'some' }, custom: { ipal: { staffCollections: ['none', 'some', 'copy'] } } } }, user: { id: 1, collection: 'customers' } } } as never + const answers = async (c: { access: Record }) => Object.fromEntries(await Promise.all(Object.entries(c.access).map(async ([operation, rule]) => [operation, Boolean(await (rule as (a: never) => unknown)(visitor))]))) + expect(await answers(none as never)).toEqual({ create: false, delete: false, read: false, readVersions: false, unlock: false, update: false }) + expect(await answers(some as never)).toEqual({ create: true, delete: false, read: false, readVersions: false, unlock: false, update: true }) + // handled: a second pass changes nothing + expect(adoptLateAuthCollections(config, ['none', 'some', 'copy'], { access: {}, firstUserRoute: 'all' })).toEqual([]) + // the opt-out keeps everything; and a collection that never became staff is left alone + const asIs = { ...filled('some'), custom: { ...of('some').custom, ipal: { accountRules: false } } } + expect(adoptLateAuthCollections({ collections: [asIs, filled('none')] } as never, ['some'], { access: {}, firstUserRoute: 'all' })).toEqual([]) + }) + test('late collections: the plugin\'s rule goes in FRONT of whatever is there, whatever it is called', async () => { const g = ({ req }: { req: { user: unknown } }) => Boolean(req.user) // Payload's default as a built site holds it: no telling name const bw = ({ req }: { req: { user: unknown } }) => Boolean(req.user) const narrow = () => false const where = () => ({ team: { equals: 'a' } }) - const hook = () => undefined + const hook = buildPasswordRuleHook() // a real one: the plugin knows its own hook by a mark on the function const late = { slug: 'late', access: { create: g, delete: narrow, read: g, readVersions: g, unlock: bw, update: where }, auth: true, endpoints: [{ handler: () => undefined, method: 'post', path: '/first-register' }], fields: [{ name: 'roles', type: 'select', access: {}, hasMany: true, options: ['user', 'admin'] }] } - const seen = { slug: 'users', access: { create: g }, auth: true, custom: { ipalAccounts: true }, endpoints: [], fields: [] } + const seen = { slug: 'users', access: { create: g }, auth: true, custom: { ipalAccounts: { slug: 'users', staff: true } }, endpoints: [], fields: [] } const visitors = { slug: 'visitors', access: { create: g }, auth: true, endpoints: [], fields: [] } const asIs = { slug: 'as-is', access: { create: g }, auth: true, custom: { ipal: { accountRules: false } }, endpoints: [], fields: [] } const pages = { slug: 'pages', access: {}, endpoints: [], fields: [] } const config = { collections: [late, pages, seen, visitors, asIs] } as never const staff = { staffCollections: ['users', 'late', 'as-is'] } expect(adoptLateAuthCollections(config, ['users', 'late', 'as-is'], { beforeOperation: hook })).toEqual([ - { slug: 'late', applied: ['create', 'update', 'delete', 'unlock', 'read', 'readVersions', 'roles'], firstUser: true, password: true }, - { slug: 'visitors', applied: [], firstUser: true, password: false }, - { slug: 'as-is', applied: [], firstUser: true, password: true }, // its own rules as they are: it said so + { slug: 'late', applied: ['create', 'update', 'delete', 'unlock', 'read', 'readVersions', 'roles'], firstUser: true, kept: [], known: false, password: true }, + { slug: 'visitors', applied: [], firstUser: true, kept: [], known: false, password: false }, + { slug: 'as-is', applied: [], firstUser: true, kept: [], known: false, password: true }, // its own rules as they are: it said so ]) const ask = (operation: keyof typeof late.access, user: unknown) => (late.access[operation] as (a: unknown) => unknown)({ req: { payload: staff, user } }) const admin = { id: 1, collection: 'users', roles: ['admin'] } @@ -708,7 +769,7 @@ export function accountRulesSuite(twoFactor: boolean): void { expect(await ask('delete', admin)).toBe(false) expect(await ask('update', admin)).toEqual({ team: { equals: 'a' } }) expect(await ask('update', own)).toEqual({ and: [{ id: { equals: 7 } }, { team: { equals: 'a' } }] }) - expect((late.fields[0] as { access?: { update?: unknown } }).access?.update).toBe(rolesByAdminOnly) + expect(staffRuleOf((late.fields[0] as { access?: { update?: unknown } }).access?.update)?.slug).toBe('late') expect((late as { hooks?: { beforeOperation?: unknown[] } }).hooks?.beforeOperation).toEqual([hook]) expect((late.endpoints[0] as { custom?: { ipalFirstUser?: boolean } }).custom?.ipalFirstUser).toBe(true) // in FRONT of Payload's // a late auth collection that is not staff: the first-user endpoint only @@ -727,6 +788,101 @@ export function accountRulesSuite(twoFactor: boolean): void { expect(await bothAllow(() => false, () => { throw new Error('not asked') })({} as never)).toBe(false) }) + // The copy rules ("a rule that cannot widen"): the HTTP proof is the table in accountCopyTableSuite.ts; here the parts. + test('the plugin\'s mark: on the function itself, never on a shared rule or through somebody\'s wrapper', async () => { + const marked = markedStaffRule(staffCreateAccess, 'agents') + expect(marked).not.toBe(staffCreateAccess) + expect(staffRuleOf(marked)).toEqual({ slug: 'agents', self: marked }) + expect(staffRuleOf(staffCreateAccess)).toBeUndefined() // the exported rule is shared: a project may use it anywhere + expect(staffRuleOf(() => true)).toBeUndefined() + expect(staffRuleOf(undefined)).toBeUndefined() + expect(await marked({ req: { payload: { staffCollections: ['users'] }, user: { id: 1, collection: 'users', roles: ['admin'] } } } as never)).toBe(true) + // the plugin's own wrapper (its 2FA guard) gets a mark made for IT + const guarded = requireSecondFactor(marked) + expect(staffRuleOf(guarded)).toEqual({ slug: 'agents', self: guarded }) + expect(staffRuleOf(requireSecondFactor(() => true))).toBeUndefined() + // wrappers that are not the plugin's answer with the same property — and are not the rule + const symbol = Symbol.for('ipal.staffRule') + for (const [name, fn] of [['a Proxy', new Proxy(marked, { apply: () => false })], ['the rule as prototype', Object.setPrototypeOf(() => false, marked)], ['copied descriptors', Object.defineProperties(() => false, Object.getOwnPropertyDescriptors(marked))]] as [string, unknown][]) { + expect([name, (fn as Record)[symbol] !== undefined, staffRuleOf(fn)]).toEqual([name, true, undefined]) + } + expect(staffRuleOf(marked.bind(null))).toBeUndefined() + // the password hook: marked the same way, so a copy has it once — also across module instances (a registered symbol) + const hook = buildPasswordRuleHook() + expect(isPasswordRuleHook(hook)).toBe(true) + expect((hook as unknown as Record)[Symbol.for('ipal.passwordRule')]).toEqual({ self: hook }) + expect([isPasswordRuleHook(() => undefined), isPasswordRuleHook(new Proxy(hook, {}))]).toEqual([false, false]) + // with 2FA wiring that wraps every access function: the function that ENDS UP on the collection carries the mark… + const wrapping = ((o: { collection: string }) => (c: Config) => withTotpParts({ ...c, collections: (c.collections ?? []).map((col) => ({ ...col, access: Object.fromEntries(Object.entries(col.access ?? {}).map(([k, v]) => [k, (x: never) => (v as (x: never) => unknown)(x)])) })) } as Config, o.collection)) as never + const withFactory = await build({ twoFactor: { issuer: 'A', plugin: wrapping } }) + expect(['create', 'update', 'delete', 'unlock', 'read', 'readVersions'].map((op) => staffRuleOf((of(withFactory, 'staff2').access as Record)[op])?.slug)).toEqual(Array(6).fill('staff2')) + expect(staffRuleOf(of(withFactory, 'customers').access?.create)).toBeUndefined() // the project's own rule + // …and marking does not undo ipal-kit's 2FA guard: a plain 2FA config has nothing left to guard at start + const { ensurePayloadGuarded } = await import('../src/modules/security/totp/secondFactor.js') + const plain = await build({ twoFactor: { issuer: 'A', plugin: ((o: { collection: string }) => (c: Config) => withTotpParts(c, o.collection)) as never } }) + expect([ensurePayloadGuarded({ config: plain } as never), ensurePayloadGuarded({ config: withFactory } as never)]).toEqual([[], []]) + }) + + test('a copied collection: the plugin\'s rule for ITS slug goes in front of every rule it brought; nothing is replaced', async () => { + const mk = (slug: string, rule: unknown) => markedStaffRule(rule as () => unknown, slug) + const access = { create: mk('agents', staffCreateAccess), delete: mk('agents', staffCreateAccess), read: mk('agents', staffReadAccess), update: mk('agents', staffUpdateAccess('agents')) } + const pluginRoles = () => ({ name: 'roles', type: 'select', hasMany: true, options: ['user', 'editor', 'admin'] }) as { access?: { update?: (a: unknown) => unknown }; name: string; options: string[]; type: string } + const agents = { slug: 'agents', access, auth: true, custom: { ipalAccountRules: { slug: 'agents', applied: Object.keys(access), ownRoles: false }, ipalAccounts: { slug: 'agents', staff: true } }, endpoints: [], fields: [pluginRoles()], hooks: { beforeOperation: [buildPasswordRuleHook()] } } + const nobody = () => false + const copy = { ...agents, slug: 'copy', endpoints: [], fields: [pluginRoles()] } + const ownRule = { ...agents, slug: 'own-rule', access: { ...access, update: nobody }, endpoints: [], fields: [pluginRoles()] } + const optOut = { ...agents, slug: 'opt-out', custom: { ...agents.custom, ipal: { accountRules: false } }, endpoints: [], fields: [pluginRoles()] } + const notStaff = { ...agents, slug: 'not-staff', endpoints: [], fields: [pluginRoles()] } + const claims = { slug: 'claims', access: { create: mk('claims', () => true) }, auth: true, endpoints: [], fields: [] } // a mark that claims this very collection + const hook = buildPasswordRuleHook() + const adopted = adoptLateAuthCollections({ collections: [agents, copy, ownRule, optOut, notStaff, claims] } as never, ['agents', 'copy', 'own-rule', 'opt-out', 'claims'], { beforeOperation: hook }) + expect(adopted.map((x) => [x.slug, x.applied, x.password])).toEqual([ + ['copy', ['create', 'update', 'delete', 'unlock', 'read', 'readVersions', 'roles'], false], // the hook came along: not put twice + ['own-rule', ['create', 'update', 'delete', 'unlock', 'read', 'readVersions', 'roles'], false], + ['opt-out', ['create', 'update', 'delete', 'read', 'roles'], false], // only in front of the rules the plugin wrote for `agents`, and the roles field + ['not-staff', ['create', 'update', 'delete', 'read', 'roles'], false], + ['claims', ['create', 'update', 'delete', 'unlock', 'read', 'readVersions'], true], + ]) + const staff = { staffCollections: ['users', 'agents', 'copy', 'own-rule', 'opt-out', 'claims'] } + const ask = (c: { access: Record }, operation: string, user: unknown) => (c.access[operation] as (a: unknown) => unknown)({ req: { payload: staff, user } }) + const admin = { id: 1, collection: 'users', roles: ['admin'] } + const namesake = { id: 7, collection: 'agents', roles: ['user'] } + for (const c of [copy, ownRule, optOut, notStaff]) { + const own = { id: 7, collection: c.slug, roles: ['user'] } + // the original's account with the same id is not "the account itself" here; nor does the copy's own account pass + // the rule that still says "an account of `agents`" — both rules must allow (the accepted cost: the copy writes its own update rule) + expect([c.slug, await ask(c, 'update', namesake), await ask(c, 'update', own), await ask(c, 'create', own), await ask(c, 'delete', own)]).toEqual([c.slug, false, false, false, false]) + // the functions that came along are still inside: nothing was replaced + expect([c.slug, staffRuleOf(c.access.update)?.slug]).toEqual([c.slug, c.slug]) + expect([c.slug, await ask(c, 'create', admin)]).toEqual([c.slug, true]) + // the roles field of every copy is guarded, whatever the mode + const field = (c.fields[0]).access?.update + expect([c.slug, staffRuleOf(field)?.slug, await field?.({ id: 7, req: { payload: staff, user: own } })]).toEqual([c.slug, c.slug, false]) + expect(c.fields[0]).not.toBe(agents.fields[0]) + expect(c.access).not.toBe(agents.access) + } + expect(await ask(ownRule, 'update', admin)).toBe(false) // its own "nobody" still has to allow + expect(await ask(copy, 'update', admin)).toBe(true) + // the one line a copying plugin writes so that the copy's own accounts edit themselves (docs/access.md) + const fixed = { ...agents, slug: 'fixed', access: { ...access, update: adminOrSelfIn('fixed') }, endpoints: [], fields: [pluginRoles()] } + adoptLateAuthCollections({ collections: [fixed] } as never, ['agents', 'fixed'], { beforeOperation: hook }) + const all = { staffCollections: ['users', 'agents', 'fixed'] } + const askFixed = (user: unknown) => (fixed.access.update as (a: unknown) => unknown)({ req: { payload: all, user } }) + expect(await askFixed({ id: 7, collection: 'fixed', roles: ['user'] })).toEqual({ and: [{ id: { equals: 7 } }, { id: { equals: 7 } }] }) + expect([await askFixed(namesake), await askFixed(admin)]).toEqual([false, true]) + // a mark that claims the collection does not leave the function alone + expect([await ask(claims, 'create', { id: 9, collection: 'customers' }), await ask(claims, 'create', null), await ask(claims, 'create', admin)]).toEqual([false, false, true]) + // the original is untouched + expect(await ask(agents, 'update', namesake)).toEqual({ id: { equals: 7 } }) + expect(staffRuleOf(agents.access.update)?.slug).toBe('agents') + // R4-2: an object seen as NOT staff (a `next dev` edit names it as staff afterwards) is handled again; a second call changes nothing + const visitors = { slug: 'visitors', access: { create: () => true }, auth: true, endpoints: [], fields: [] } + expect(adoptLateAuthCollections({ collections: [visitors] } as never, [], { beforeOperation: hook }).map((x) => [x.slug, x.applied, x.firstUser])).toEqual([['visitors', [], true]]) + expect(adoptLateAuthCollections({ collections: [visitors] } as never, ['visitors'], { beforeOperation: hook }).map((x) => [x.slug, x.applied.length > 0, x.password, x.firstUser])).toEqual([['visitors', true, true, false]]) + expect(adoptLateAuthCollections({ collections: [visitors] } as never, ['visitors'], { beforeOperation: hook })).toEqual([]) + expect(await (visitors.access.create as (a: unknown) => unknown)({ req: { payload: { staffCollections: ['visitors'] }, user: { id: 9, collection: 'customers' } } })).toBe(false) + }) + test('the rules are on the collections BEFORE the 2FA package wraps them', async () => { // the package gives every collection a create / update / delete of its own; afterwards "no rule" cannot be seen const seen: Record = {} diff --git a/test/fixtures/copyRulesBaseline.json b/test/fixtures/copyRulesBaseline.json new file mode 100644 index 0000000..965121a --- /dev/null +++ b/test/fixtures/copyRulesBaseline.json @@ -0,0 +1,1995 @@ +{ + "plain | anonymous | read": 0, + "plain | anonymous | create": 0, + "plain | anonymous | patchVictim": 0, + "plain | anonymous | patchTop": 0, + "plain | anonymous | patchTwin": 0, + "plain | anonymous | rolesVictim": 0, + "plain | anonymous | unlock": 0, + "plain | anonymous | delete": 0, + "plain | customer | read": 0, + "plain | customer | create": 0, + "plain | customer | patchVictim": 0, + "plain | customer | patchTop": 0, + "plain | customer | patchTwin": 0, + "plain | customer | rolesVictim": 0, + "plain | customer | unlock": 0, + "plain | customer | delete": 0, + "plain | namesake | read": 3, + "plain | namesake | create": 0, + "plain | namesake | patchVictim": 0, + "plain | namesake | patchTop": 0, + "plain | namesake | patchTwin": 1, + "plain | namesake | rolesVictim": 0, + "plain | namesake | unlock": 0, + "plain | namesake | delete": 0, + "plain | agentsAdmin | read": 3, + "plain | agentsAdmin | create": 1, + "plain | agentsAdmin | patchVictim": 1, + "plain | agentsAdmin | patchTop": 1, + "plain | agentsAdmin | patchTwin": 1, + "plain | agentsAdmin | rolesVictim": 1, + "plain | agentsAdmin | unlock": 1, + "plain | agentsAdmin | delete": 1, + "plain | ownLow | signedIn": 1, + "plain | ownLow | read": 4, + "plain | ownLow | create": 0, + "plain | ownLow | patchVictim": 0, + "plain | ownLow | patchTop": 0, + "plain | ownLow | raiseSelf": 0, + "plain | ownLow | rolesVictim": 0, + "plain | ownLow | unlock": 0, + "plain | ownLow | delete": 0, + "plain | ownLow | ownPassword": 0, + "plain | ownTop | signedIn": 1, + "plain | ownTop | read": 4, + "plain | ownTop | create": 1, + "plain | ownTop | patchVictim": 1, + "plain | ownTop | patchTwin": 1, + "plain | ownTop | rolesVictim": 1, + "plain | ownTop | unlock": 1, + "plain | ownTop | delete": 1, + "ownrules | anonymous | read": 0, + "ownrules | anonymous | create": 0, + "ownrules | anonymous | patchVictim": 0, + "ownrules | anonymous | patchTop": 0, + "ownrules | anonymous | patchTwin": 0, + "ownrules | anonymous | rolesVictim": 0, + "ownrules | anonymous | unlock": 0, + "ownrules | anonymous | delete": 0, + "ownrules | customer | read": 0, + "ownrules | customer | create": 0, + "ownrules | customer | patchVictim": 0, + "ownrules | customer | patchTop": 0, + "ownrules | customer | patchTwin": 0, + "ownrules | customer | rolesVictim": 0, + "ownrules | customer | unlock": 0, + "ownrules | customer | delete": 0, + "ownrules | namesake | read": 0, + "ownrules | namesake | create": 0, + "ownrules | namesake | patchVictim": 0, + "ownrules | namesake | patchTop": 0, + "ownrules | namesake | patchTwin": 0, + "ownrules | namesake | rolesVictim": 0, + "ownrules | namesake | unlock": 0, + "ownrules | namesake | delete": 0, + "ownrules | agentsAdmin | read": 1, + "ownrules | agentsAdmin | create": 0, + "ownrules | agentsAdmin | patchVictim": 0, + "ownrules | agentsAdmin | patchTop": 0, + "ownrules | agentsAdmin | patchTwin": 0, + "ownrules | agentsAdmin | rolesVictim": 0, + "ownrules | agentsAdmin | unlock": 1, + "ownrules | agentsAdmin | delete": 0, + "ownrules | ownLow | signedIn": 0, + "ownrules | ownLow | read": 0, + "ownrules | ownLow | create": 0, + "ownrules | ownLow | patchVictim": 0, + "ownrules | ownLow | patchTop": 0, + "ownrules | ownLow | raiseSelf": 0, + "ownrules | ownLow | rolesVictim": 0, + "ownrules | ownLow | unlock": 0, + "ownrules | ownLow | delete": 0, + "ownrules | ownLow | ownPassword": 0, + "ownrules | ownTop | signedIn": 0, + "ownrules | ownTop | read": 1, + "ownrules | ownTop | create": 0, + "ownrules | ownTop | patchVictim": 0, + "ownrules | ownTop | patchTwin": 0, + "ownrules | ownTop | rolesVictim": 0, + "ownrules | ownTop | unlock": 1, + "ownrules | ownTop | delete": 0, + "ownfield | anonymous | read": 0, + "ownfield | anonymous | create": 0, + "ownfield | anonymous | patchVictim": 0, + "ownfield | anonymous | patchTop": 0, + "ownfield | anonymous | patchTwin": 0, + "ownfield | anonymous | rolesVictim": 0, + "ownfield | anonymous | unlock": 0, + "ownfield | anonymous | delete": 0, + "ownfield | customer | read": 0, + "ownfield | customer | create": 0, + "ownfield | customer | patchVictim": 0, + "ownfield | customer | patchTop": 0, + "ownfield | customer | patchTwin": 0, + "ownfield | customer | rolesVictim": 0, + "ownfield | customer | unlock": 0, + "ownfield | customer | delete": 0, + "ownfield | namesake | read": 3, + "ownfield | namesake | create": 0, + "ownfield | namesake | patchVictim": 0, + "ownfield | namesake | patchTop": 0, + "ownfield | namesake | patchTwin": 1, + "ownfield | namesake | rolesVictim": 0, + "ownfield | namesake | unlock": 0, + "ownfield | namesake | delete": 0, + "ownfield | agentsAdmin | read": 3, + "ownfield | agentsAdmin | create": 1, + "ownfield | agentsAdmin | patchVictim": 1, + "ownfield | agentsAdmin | patchTop": 1, + "ownfield | agentsAdmin | patchTwin": 1, + "ownfield | agentsAdmin | rolesVictim": 0, + "ownfield | agentsAdmin | unlock": 1, + "ownfield | agentsAdmin | delete": 1, + "ownfield | ownLow | signedIn": 1, + "ownfield | ownLow | read": 4, + "ownfield | ownLow | create": 0, + "ownfield | ownLow | patchVictim": 0, + "ownfield | ownLow | patchTop": 0, + "ownfield | ownLow | raiseSelf": 0, + "ownfield | ownLow | rolesVictim": 0, + "ownfield | ownLow | unlock": 0, + "ownfield | ownLow | delete": 0, + "ownfield | ownLow | ownPassword": 0, + "ownfield | ownTop | signedIn": 1, + "ownfield | ownTop | read": 4, + "ownfield | ownTop | create": 1, + "ownfield | ownTop | patchVictim": 1, + "ownfield | ownTop | patchTwin": 1, + "ownfield | ownTop | rolesVictim": 0, + "ownfield | ownTop | unlock": 1, + "ownfield | ownTop | delete": 1, + "optout | anonymous | read": 0, + "optout | anonymous | create": 0, + "optout | anonymous | patchVictim": 0, + "optout | anonymous | patchTop": 0, + "optout | anonymous | patchTwin": 0, + "optout | anonymous | rolesVictim": 0, + "optout | anonymous | unlock": 0, + "optout | anonymous | delete": 0, + "optout | customer | read": 0, + "optout | customer | create": 0, + "optout | customer | patchVictim": 0, + "optout | customer | patchTop": 0, + "optout | customer | patchTwin": 0, + "optout | customer | rolesVictim": 0, + "optout | customer | unlock": 0, + "optout | customer | delete": 0, + "optout | namesake | read": 3, + "optout | namesake | create": 0, + "optout | namesake | patchVictim": 0, + "optout | namesake | patchTop": 0, + "optout | namesake | patchTwin": 1, + "optout | namesake | rolesVictim": 0, + "optout | namesake | unlock": 0, + "optout | namesake | delete": 0, + "optout | agentsAdmin | read": 3, + "optout | agentsAdmin | create": 1, + "optout | agentsAdmin | patchVictim": 1, + "optout | agentsAdmin | patchTop": 1, + "optout | agentsAdmin | patchTwin": 1, + "optout | agentsAdmin | rolesVictim": 1, + "optout | agentsAdmin | unlock": 1, + "optout | agentsAdmin | delete": 1, + "optout | ownLow | signedIn": 1, + "optout | ownLow | read": 4, + "optout | ownLow | create": 0, + "optout | ownLow | patchVictim": 0, + "optout | ownLow | patchTop": 0, + "optout | ownLow | raiseSelf": 0, + "optout | ownLow | rolesVictim": 0, + "optout | ownLow | unlock": 0, + "optout | ownLow | delete": 0, + "optout | ownLow | ownPassword": 0, + "optout | ownTop | signedIn": 1, + "optout | ownTop | read": 4, + "optout | ownTop | create": 1, + "optout | ownTop | patchVictim": 1, + "optout | ownTop | patchTwin": 1, + "optout | ownTop | rolesVictim": 1, + "optout | ownTop | unlock": 1, + "optout | ownTop | delete": 1, + "nonstaff | anonymous | read": 0, + "nonstaff | anonymous | create": 0, + "nonstaff | anonymous | patchVictim": 0, + "nonstaff | anonymous | patchTop": 0, + "nonstaff | anonymous | patchTwin": 0, + "nonstaff | anonymous | rolesVictim": 0, + "nonstaff | anonymous | unlock": 0, + "nonstaff | anonymous | delete": 0, + "nonstaff | customer | read": 0, + "nonstaff | customer | create": 0, + "nonstaff | customer | patchVictim": 0, + "nonstaff | customer | patchTop": 0, + "nonstaff | customer | patchTwin": 0, + "nonstaff | customer | rolesVictim": 0, + "nonstaff | customer | unlock": 0, + "nonstaff | customer | delete": 0, + "nonstaff | namesake | read": 3, + "nonstaff | namesake | create": 0, + "nonstaff | namesake | patchVictim": 0, + "nonstaff | namesake | patchTop": 0, + "nonstaff | namesake | patchTwin": 1, + "nonstaff | namesake | rolesVictim": 0, + "nonstaff | namesake | unlock": 0, + "nonstaff | namesake | delete": 0, + "nonstaff | agentsAdmin | read": 3, + "nonstaff | agentsAdmin | create": 1, + "nonstaff | agentsAdmin | patchVictim": 1, + "nonstaff | agentsAdmin | patchTop": 1, + "nonstaff | agentsAdmin | patchTwin": 1, + "nonstaff | agentsAdmin | rolesVictim": 1, + "nonstaff | agentsAdmin | unlock": 1, + "nonstaff | agentsAdmin | delete": 1, + "nonstaff | ownLow | signedIn": 0, + "nonstaff | ownLow | read": 0, + "nonstaff | ownLow | create": 0, + "nonstaff | ownLow | patchVictim": 0, + "nonstaff | ownLow | patchTop": 0, + "nonstaff | ownLow | raiseSelf": 0, + "nonstaff | ownLow | rolesVictim": 0, + "nonstaff | ownLow | unlock": 0, + "nonstaff | ownLow | delete": 0, + "nonstaff | ownLow | ownPassword": 0, + "nonstaff | ownTop | signedIn": 0, + "nonstaff | ownTop | read": 0, + "nonstaff | ownTop | create": 0, + "nonstaff | ownTop | patchVictim": 0, + "nonstaff | ownTop | patchTwin": 0, + "nonstaff | ownTop | rolesVictim": 0, + "nonstaff | ownTop | unlock": 0, + "nonstaff | ownTop | delete": 0, + "userscopy | anonymous | read": 0, + "userscopy | anonymous | create": 0, + "userscopy | anonymous | patchVictim": 0, + "userscopy | anonymous | patchTop": 0, + "userscopy | anonymous | patchTwin": 0, + "userscopy | anonymous | rolesVictim": 0, + "userscopy | anonymous | unlock": 0, + "userscopy | anonymous | delete": 0, + "userscopy | customer | read": 0, + "userscopy | customer | create": 0, + "userscopy | customer | patchVictim": 0, + "userscopy | customer | patchTop": 0, + "userscopy | customer | patchTwin": 0, + "userscopy | customer | rolesVictim": 0, + "userscopy | customer | unlock": 0, + "userscopy | customer | delete": 0, + "userscopy | namesake | read": 0, + "userscopy | namesake | create": 0, + "userscopy | namesake | patchVictim": 0, + "userscopy | namesake | patchTop": 0, + "userscopy | namesake | patchTwin": 0, + "userscopy | namesake | rolesVictim": 0, + "userscopy | namesake | unlock": 0, + "userscopy | namesake | delete": 0, + "userscopy | agentsAdmin | read": 3, + "userscopy | agentsAdmin | create": 1, + "userscopy | agentsAdmin | patchVictim": 1, + "userscopy | agentsAdmin | patchTop": 1, + "userscopy | agentsAdmin | patchTwin": 1, + "userscopy | agentsAdmin | rolesVictim": 1, + "userscopy | agentsAdmin | unlock": 1, + "userscopy | agentsAdmin | delete": 1, + "userscopy | ownLow | signedIn": 0, + "userscopy | ownLow | read": 0, + "userscopy | ownLow | create": 0, + "userscopy | ownLow | patchVictim": 0, + "userscopy | ownLow | patchTop": 0, + "userscopy | ownLow | raiseSelf": 0, + "userscopy | ownLow | rolesVictim": 0, + "userscopy | ownLow | unlock": 0, + "userscopy | ownLow | delete": 0, + "userscopy | ownLow | ownPassword": 0, + "userscopy | ownTop | signedIn": 1, + "userscopy | ownTop | read": 4, + "userscopy | ownTop | create": 1, + "userscopy | ownTop | patchVictim": 1, + "userscopy | ownTop | patchTwin": 1, + "userscopy | ownTop | rolesVictim": 1, + "userscopy | ownTop | unlock": 1, + "userscopy | ownTop | delete": 1, + "projcopy | anonymous | read": 0, + "projcopy | anonymous | create": 0, + "projcopy | anonymous | patchVictim": 0, + "projcopy | anonymous | patchTop": 0, + "projcopy | anonymous | patchTwin": 0, + "projcopy | anonymous | rolesVictim": 0, + "projcopy | anonymous | unlock": 0, + "projcopy | anonymous | delete": 0, + "projcopy | customer | read": 0, + "projcopy | customer | create": 0, + "projcopy | customer | patchVictim": 0, + "projcopy | customer | patchTop": 0, + "projcopy | customer | patchTwin": 0, + "projcopy | customer | rolesVictim": 0, + "projcopy | customer | unlock": 0, + "projcopy | customer | delete": 0, + "projcopy | namesake | read": 3, + "projcopy | namesake | create": 0, + "projcopy | namesake | patchVictim": 0, + "projcopy | namesake | patchTop": 0, + "projcopy | namesake | patchTwin": 0, + "projcopy | namesake | rolesVictim": 0, + "projcopy | namesake | unlock": 0, + "projcopy | namesake | delete": 0, + "projcopy | agentsAdmin | read": 3, + "projcopy | agentsAdmin | create": 1, + "projcopy | agentsAdmin | patchVictim": 0, + "projcopy | agentsAdmin | patchTop": 0, + "projcopy | agentsAdmin | patchTwin": 0, + "projcopy | agentsAdmin | rolesVictim": 0, + "projcopy | agentsAdmin | unlock": 1, + "projcopy | agentsAdmin | delete": 1, + "projcopy | ownLow | signedIn": 1, + "projcopy | ownLow | read": 4, + "projcopy | ownLow | create": 0, + "projcopy | ownLow | patchVictim": 0, + "projcopy | ownLow | patchTop": 0, + "projcopy | ownLow | raiseSelf": 0, + "projcopy | ownLow | rolesVictim": 0, + "projcopy | ownLow | unlock": 0, + "projcopy | ownLow | delete": 0, + "projcopy | ownLow | ownPassword": 0, + "projcopy | ownTop | signedIn": 1, + "projcopy | ownTop | read": 4, + "projcopy | ownTop | create": 1, + "projcopy | ownTop | patchVictim": 0, + "projcopy | ownTop | patchTwin": 0, + "projcopy | ownTop | rolesVictim": 0, + "projcopy | ownTop | unlock": 1, + "projcopy | ownTop | delete": 1, + "lesscopy | anonymous | read": 0, + "lesscopy | anonymous | create": 0, + "lesscopy | anonymous | patchVictim": 0, + "lesscopy | anonymous | patchTop": 0, + "lesscopy | anonymous | patchTwin": 0, + "lesscopy | anonymous | rolesVictim": 0, + "lesscopy | anonymous | unlock": 0, + "lesscopy | anonymous | delete": 0, + "lesscopy | customer | read": 3, + "lesscopy | customer | create": 0, + "lesscopy | customer | patchVictim": 1, + "lesscopy | customer | patchTop": 1, + "lesscopy | customer | patchTwin": 1, + "lesscopy | customer | rolesVictim": 0, + "lesscopy | customer | unlock": 0, + "lesscopy | customer | delete": 1, + "lesscopy | namesake | read": 3, + "lesscopy | namesake | create": 0, + "lesscopy | namesake | patchVictim": 1, + "lesscopy | namesake | patchTop": 1, + "lesscopy | namesake | patchTwin": 1, + "lesscopy | namesake | rolesVictim": 0, + "lesscopy | namesake | unlock": 0, + "lesscopy | namesake | delete": 1, + "lesscopy | agentsAdmin | read": 3, + "lesscopy | agentsAdmin | create": 1, + "lesscopy | agentsAdmin | patchVictim": 1, + "lesscopy | agentsAdmin | patchTop": 1, + "lesscopy | agentsAdmin | patchTwin": 1, + "lesscopy | agentsAdmin | rolesVictim": 1, + "lesscopy | agentsAdmin | unlock": 0, + "lesscopy | agentsAdmin | delete": 1, + "lesscopy | ownLow | signedIn": 1, + "lesscopy | ownLow | read": 4, + "lesscopy | ownLow | create": 0, + "lesscopy | ownLow | patchVictim": 1, + "lesscopy | ownLow | patchTop": 1, + "lesscopy | ownLow | raiseSelf": 0, + "lesscopy | ownLow | rolesVictim": 0, + "lesscopy | ownLow | unlock": 0, + "lesscopy | ownLow | delete": 1, + "lesscopy | ownLow | ownPassword": 1, + "lesscopy | ownTop | signedIn": 1, + "lesscopy | ownTop | read": 4, + "lesscopy | ownTop | create": 1, + "lesscopy | ownTop | patchVictim": 1, + "lesscopy | ownTop | patchTwin": 1, + "lesscopy | ownTop | rolesVictim": 1, + "lesscopy | ownTop | unlock": 0, + "lesscopy | ownTop | delete": 1, + "crossop | anonymous | read": 0, + "crossop | anonymous | create": 0, + "crossop | anonymous | patchVictim": 0, + "crossop | anonymous | patchTop": 0, + "crossop | anonymous | patchTwin": 0, + "crossop | anonymous | rolesVictim": 0, + "crossop | anonymous | unlock": 0, + "crossop | anonymous | delete": 0, + "crossop | customer | read": 0, + "crossop | customer | create": 0, + "crossop | customer | patchVictim": 0, + "crossop | customer | patchTop": 0, + "crossop | customer | patchTwin": 0, + "crossop | customer | rolesVictim": 0, + "crossop | customer | unlock": 0, + "crossop | customer | delete": 0, + "crossop | namesake | read": 0, + "crossop | namesake | create": 0, + "crossop | namesake | patchVictim": 0, + "crossop | namesake | patchTop": 0, + "crossop | namesake | patchTwin": 0, + "crossop | namesake | rolesVictim": 0, + "crossop | namesake | unlock": 0, + "crossop | namesake | delete": 0, + "crossop | agentsAdmin | read": 3, + "crossop | agentsAdmin | create": 1, + "crossop | agentsAdmin | patchVictim": 1, + "crossop | agentsAdmin | patchTop": 1, + "crossop | agentsAdmin | patchTwin": 1, + "crossop | agentsAdmin | rolesVictim": 1, + "crossop | agentsAdmin | unlock": 1, + "crossop | agentsAdmin | delete": 1, + "crossop | ownLow | signedIn": 0, + "crossop | ownLow | read": 0, + "crossop | ownLow | create": 0, + "crossop | ownLow | patchVictim": 0, + "crossop | ownLow | patchTop": 0, + "crossop | ownLow | raiseSelf": 0, + "crossop | ownLow | rolesVictim": 0, + "crossop | ownLow | unlock": 0, + "crossop | ownLow | delete": 0, + "crossop | ownLow | ownPassword": 0, + "crossop | ownTop | signedIn": 1, + "crossop | ownTop | read": 4, + "crossop | ownTop | create": 1, + "crossop | ownTop | patchVictim": 1, + "crossop | ownTop | patchTwin": 1, + "crossop | ownTop | rolesVictim": 1, + "crossop | ownTop | unlock": 1, + "crossop | ownTop | delete": 1, + "crossopt | anonymous | read": 0, + "crossopt | anonymous | create": 0, + "crossopt | anonymous | patchVictim": 0, + "crossopt | anonymous | patchTop": 0, + "crossopt | anonymous | patchTwin": 0, + "crossopt | anonymous | rolesVictim": 0, + "crossopt | anonymous | unlock": 0, + "crossopt | anonymous | delete": 0, + "crossopt | customer | read": 0, + "crossopt | customer | create": 0, + "crossopt | customer | patchVictim": 0, + "crossopt | customer | patchTop": 0, + "crossopt | customer | patchTwin": 0, + "crossopt | customer | rolesVictim": 0, + "crossopt | customer | unlock": 0, + "crossopt | customer | delete": 0, + "crossopt | namesake | read": 0, + "crossopt | namesake | create": 0, + "crossopt | namesake | patchVictim": 0, + "crossopt | namesake | patchTop": 0, + "crossopt | namesake | patchTwin": 0, + "crossopt | namesake | rolesVictim": 0, + "crossopt | namesake | unlock": 0, + "crossopt | namesake | delete": 0, + "crossopt | agentsAdmin | read": 3, + "crossopt | agentsAdmin | create": 1, + "crossopt | agentsAdmin | patchVictim": 1, + "crossopt | agentsAdmin | patchTop": 1, + "crossopt | agentsAdmin | patchTwin": 1, + "crossopt | agentsAdmin | rolesVictim": 1, + "crossopt | agentsAdmin | unlock": 1, + "crossopt | agentsAdmin | delete": 1, + "crossopt | ownLow | signedIn": 0, + "crossopt | ownLow | read": 0, + "crossopt | ownLow | create": 0, + "crossopt | ownLow | patchVictim": 0, + "crossopt | ownLow | patchTop": 0, + "crossopt | ownLow | raiseSelf": 0, + "crossopt | ownLow | rolesVictim": 0, + "crossopt | ownLow | unlock": 0, + "crossopt | ownLow | delete": 0, + "crossopt | ownLow | ownPassword": 0, + "crossopt | ownTop | signedIn": 0, + "crossopt | ownTop | read": 0, + "crossopt | ownTop | create": 0, + "crossopt | ownTop | patchVictim": 0, + "crossopt | ownTop | patchTwin": 0, + "crossopt | ownTop | rolesVictim": 0, + "crossopt | ownTop | unlock": 0, + "crossopt | ownTop | delete": 0, + "proxied | anonymous | read": 0, + "proxied | anonymous | create": 0, + "proxied | anonymous | patchVictim": 0, + "proxied | anonymous | patchTop": 0, + "proxied | anonymous | patchTwin": 0, + "proxied | anonymous | rolesVictim": 0, + "proxied | anonymous | unlock": 0, + "proxied | anonymous | delete": 0, + "proxied | customer | read": 0, + "proxied | customer | create": 0, + "proxied | customer | patchVictim": 0, + "proxied | customer | patchTop": 0, + "proxied | customer | patchTwin": 0, + "proxied | customer | rolesVictim": 0, + "proxied | customer | unlock": 0, + "proxied | customer | delete": 0, + "proxied | namesake | read": 0, + "proxied | namesake | create": 0, + "proxied | namesake | patchVictim": 0, + "proxied | namesake | patchTop": 0, + "proxied | namesake | patchTwin": 0, + "proxied | namesake | rolesVictim": 0, + "proxied | namesake | unlock": 0, + "proxied | namesake | delete": 0, + "proxied | agentsAdmin | read": 0, + "proxied | agentsAdmin | create": 0, + "proxied | agentsAdmin | patchVictim": 0, + "proxied | agentsAdmin | patchTop": 0, + "proxied | agentsAdmin | patchTwin": 0, + "proxied | agentsAdmin | rolesVictim": 0, + "proxied | agentsAdmin | unlock": 1, + "proxied | agentsAdmin | delete": 1, + "proxied | ownLow | signedIn": 0, + "proxied | ownLow | read": 0, + "proxied | ownLow | create": 0, + "proxied | ownLow | patchVictim": 0, + "proxied | ownLow | patchTop": 0, + "proxied | ownLow | raiseSelf": 0, + "proxied | ownLow | rolesVictim": 0, + "proxied | ownLow | unlock": 0, + "proxied | ownLow | delete": 0, + "proxied | ownLow | ownPassword": 0, + "proxied | ownTop | signedIn": 0, + "proxied | ownTop | read": 0, + "proxied | ownTop | create": 0, + "proxied | ownTop | patchVictim": 0, + "proxied | ownTop | patchTwin": 0, + "proxied | ownTop | rolesVictim": 0, + "proxied | ownTop | unlock": 1, + "proxied | ownTop | delete": 1, + "protod | anonymous | read": 0, + "protod | anonymous | create": 0, + "protod | anonymous | patchVictim": 0, + "protod | anonymous | patchTop": 0, + "protod | anonymous | patchTwin": 0, + "protod | anonymous | rolesVictim": 0, + "protod | anonymous | unlock": 0, + "protod | anonymous | delete": 0, + "protod | customer | read": 0, + "protod | customer | create": 0, + "protod | customer | patchVictim": 0, + "protod | customer | patchTop": 0, + "protod | customer | patchTwin": 0, + "protod | customer | rolesVictim": 0, + "protod | customer | unlock": 0, + "protod | customer | delete": 0, + "protod | namesake | read": 3, + "protod | namesake | create": 0, + "protod | namesake | patchVictim": 0, + "protod | namesake | patchTop": 0, + "protod | namesake | patchTwin": 0, + "protod | namesake | rolesVictim": 0, + "protod | namesake | unlock": 0, + "protod | namesake | delete": 0, + "protod | agentsAdmin | read": 3, + "protod | agentsAdmin | create": 1, + "protod | agentsAdmin | patchVictim": 0, + "protod | agentsAdmin | patchTop": 0, + "protod | agentsAdmin | patchTwin": 0, + "protod | agentsAdmin | rolesVictim": 0, + "protod | agentsAdmin | unlock": 1, + "protod | agentsAdmin | delete": 1, + "protod | ownLow | signedIn": 1, + "protod | ownLow | read": 4, + "protod | ownLow | create": 0, + "protod | ownLow | patchVictim": 0, + "protod | ownLow | patchTop": 0, + "protod | ownLow | raiseSelf": 0, + "protod | ownLow | rolesVictim": 0, + "protod | ownLow | unlock": 0, + "protod | ownLow | delete": 0, + "protod | ownLow | ownPassword": 0, + "protod | ownTop | signedIn": 1, + "protod | ownTop | read": 4, + "protod | ownTop | create": 1, + "protod | ownTop | patchVictim": 0, + "protod | ownTop | patchTwin": 0, + "protod | ownTop | rolesVictim": 0, + "protod | ownTop | unlock": 1, + "protod | ownTop | delete": 1, + "mimic | anonymous | read": 0, + "mimic | anonymous | create": 0, + "mimic | anonymous | patchVictim": 0, + "mimic | anonymous | patchTop": 0, + "mimic | anonymous | patchTwin": 0, + "mimic | anonymous | rolesVictim": 0, + "mimic | anonymous | unlock": 0, + "mimic | anonymous | delete": 0, + "mimic | customer | read": 0, + "mimic | customer | create": 0, + "mimic | customer | patchVictim": 0, + "mimic | customer | patchTop": 0, + "mimic | customer | patchTwin": 0, + "mimic | customer | rolesVictim": 0, + "mimic | customer | unlock": 0, + "mimic | customer | delete": 0, + "mimic | namesake | read": 3, + "mimic | namesake | create": 0, + "mimic | namesake | patchVictim": 0, + "mimic | namesake | patchTop": 0, + "mimic | namesake | patchTwin": 0, + "mimic | namesake | rolesVictim": 0, + "mimic | namesake | unlock": 0, + "mimic | namesake | delete": 0, + "mimic | agentsAdmin | read": 3, + "mimic | agentsAdmin | create": 1, + "mimic | agentsAdmin | patchVictim": 0, + "mimic | agentsAdmin | patchTop": 0, + "mimic | agentsAdmin | patchTwin": 0, + "mimic | agentsAdmin | rolesVictim": 0, + "mimic | agentsAdmin | unlock": 1, + "mimic | agentsAdmin | delete": 1, + "mimic | ownLow | signedIn": 1, + "mimic | ownLow | read": 4, + "mimic | ownLow | create": 0, + "mimic | ownLow | patchVictim": 0, + "mimic | ownLow | patchTop": 0, + "mimic | ownLow | raiseSelf": 0, + "mimic | ownLow | rolesVictim": 0, + "mimic | ownLow | unlock": 0, + "mimic | ownLow | delete": 0, + "mimic | ownLow | ownPassword": 0, + "mimic | ownTop | signedIn": 1, + "mimic | ownTop | read": 4, + "mimic | ownTop | create": 1, + "mimic | ownTop | patchVictim": 0, + "mimic | ownTop | patchTwin": 0, + "mimic | ownTop | rolesVictim": 0, + "mimic | ownTop | unlock": 1, + "mimic | ownTop | delete": 1, + "bound | anonymous | read": 0, + "bound | anonymous | create": 0, + "bound | anonymous | patchVictim": 0, + "bound | anonymous | patchTop": 0, + "bound | anonymous | patchTwin": 0, + "bound | anonymous | rolesVictim": 0, + "bound | anonymous | unlock": 0, + "bound | anonymous | delete": 0, + "bound | customer | read": 0, + "bound | customer | create": 0, + "bound | customer | patchVictim": 0, + "bound | customer | patchTop": 0, + "bound | customer | patchTwin": 0, + "bound | customer | rolesVictim": 0, + "bound | customer | unlock": 0, + "bound | customer | delete": 0, + "bound | namesake | read": 3, + "bound | namesake | create": 0, + "bound | namesake | patchVictim": 0, + "bound | namesake | patchTop": 0, + "bound | namesake | patchTwin": 1, + "bound | namesake | rolesVictim": 0, + "bound | namesake | unlock": 0, + "bound | namesake | delete": 0, + "bound | agentsAdmin | read": 3, + "bound | agentsAdmin | create": 1, + "bound | agentsAdmin | patchVictim": 1, + "bound | agentsAdmin | patchTop": 1, + "bound | agentsAdmin | patchTwin": 1, + "bound | agentsAdmin | rolesVictim": 1, + "bound | agentsAdmin | unlock": 1, + "bound | agentsAdmin | delete": 1, + "bound | ownLow | signedIn": 1, + "bound | ownLow | read": 4, + "bound | ownLow | create": 0, + "bound | ownLow | patchVictim": 0, + "bound | ownLow | patchTop": 0, + "bound | ownLow | raiseSelf": 0, + "bound | ownLow | rolesVictim": 0, + "bound | ownLow | unlock": 0, + "bound | ownLow | delete": 0, + "bound | ownLow | ownPassword": 0, + "bound | ownTop | signedIn": 1, + "bound | ownTop | read": 4, + "bound | ownTop | create": 1, + "bound | ownTop | patchVictim": 1, + "bound | ownTop | patchTwin": 1, + "bound | ownTop | rolesVictim": 1, + "bound | ownTop | unlock": 1, + "bound | ownTop | delete": 1, + "wrapnarrow | anonymous | read": 0, + "wrapnarrow | anonymous | create": 0, + "wrapnarrow | anonymous | patchVictim": 0, + "wrapnarrow | anonymous | patchTop": 0, + "wrapnarrow | anonymous | patchTwin": 0, + "wrapnarrow | anonymous | rolesVictim": 0, + "wrapnarrow | anonymous | unlock": 0, + "wrapnarrow | anonymous | delete": 0, + "wrapnarrow | customer | read": 0, + "wrapnarrow | customer | create": 0, + "wrapnarrow | customer | patchVictim": 0, + "wrapnarrow | customer | patchTop": 0, + "wrapnarrow | customer | patchTwin": 0, + "wrapnarrow | customer | rolesVictim": 0, + "wrapnarrow | customer | unlock": 0, + "wrapnarrow | customer | delete": 0, + "wrapnarrow | namesake | read": 0, + "wrapnarrow | namesake | create": 0, + "wrapnarrow | namesake | patchVictim": 0, + "wrapnarrow | namesake | patchTop": 0, + "wrapnarrow | namesake | patchTwin": 0, + "wrapnarrow | namesake | rolesVictim": 0, + "wrapnarrow | namesake | unlock": 0, + "wrapnarrow | namesake | delete": 0, + "wrapnarrow | agentsAdmin | read": 3, + "wrapnarrow | agentsAdmin | create": 1, + "wrapnarrow | agentsAdmin | patchVictim": 1, + "wrapnarrow | agentsAdmin | patchTop": 1, + "wrapnarrow | agentsAdmin | patchTwin": 1, + "wrapnarrow | agentsAdmin | rolesVictim": 1, + "wrapnarrow | agentsAdmin | unlock": 1, + "wrapnarrow | agentsAdmin | delete": 1, + "wrapnarrow | ownLow | signedIn": 0, + "wrapnarrow | ownLow | read": 0, + "wrapnarrow | ownLow | create": 0, + "wrapnarrow | ownLow | patchVictim": 0, + "wrapnarrow | ownLow | patchTop": 0, + "wrapnarrow | ownLow | raiseSelf": 0, + "wrapnarrow | ownLow | rolesVictim": 0, + "wrapnarrow | ownLow | unlock": 0, + "wrapnarrow | ownLow | delete": 0, + "wrapnarrow | ownLow | ownPassword": 0, + "wrapnarrow | ownTop | signedIn": 1, + "wrapnarrow | ownTop | read": 4, + "wrapnarrow | ownTop | create": 1, + "wrapnarrow | ownTop | patchVictim": 1, + "wrapnarrow | ownTop | patchTwin": 1, + "wrapnarrow | ownTop | rolesVictim": 1, + "wrapnarrow | ownTop | unlock": 1, + "wrapnarrow | ownTop | delete": 1, + "whererule | anonymous | read": 1, + "whererule | anonymous | create": 0, + "whererule | anonymous | patchVictim": 0, + "whererule | anonymous | patchTop": 0, + "whererule | anonymous | patchTwin": 0, + "whererule | anonymous | rolesVictim": 0, + "whererule | anonymous | unlock": 0, + "whererule | anonymous | delete": 0, + "whererule | customer | read": 1, + "whererule | customer | create": 0, + "whererule | customer | patchVictim": 0, + "whererule | customer | patchTop": 0, + "whererule | customer | patchTwin": 0, + "whererule | customer | rolesVictim": 0, + "whererule | customer | unlock": 0, + "whererule | customer | delete": 0, + "whererule | namesake | read": 1, + "whererule | namesake | create": 0, + "whererule | namesake | patchVictim": 0, + "whererule | namesake | patchTop": 0, + "whererule | namesake | patchTwin": 0, + "whererule | namesake | rolesVictim": 0, + "whererule | namesake | unlock": 0, + "whererule | namesake | delete": 0, + "whererule | agentsAdmin | read": 1, + "whererule | agentsAdmin | create": 1, + "whererule | agentsAdmin | patchVictim": 0, + "whererule | agentsAdmin | patchTop": 0, + "whererule | agentsAdmin | patchTwin": 0, + "whererule | agentsAdmin | rolesVictim": 0, + "whererule | agentsAdmin | unlock": 1, + "whererule | agentsAdmin | delete": 1, + "whererule | ownLow | signedIn": 1, + "whererule | ownLow | read": 1, + "whererule | ownLow | create": 0, + "whererule | ownLow | patchVictim": 0, + "whererule | ownLow | patchTop": 0, + "whererule | ownLow | raiseSelf": 0, + "whererule | ownLow | rolesVictim": 0, + "whererule | ownLow | unlock": 0, + "whererule | ownLow | delete": 0, + "whererule | ownLow | ownPassword": 0, + "whererule | ownTop | signedIn": 0, + "whererule | ownTop | read": 1, + "whererule | ownTop | create": 1, + "whererule | ownTop | patchVictim": 0, + "whererule | ownTop | patchTwin": 0, + "whererule | ownTop | rolesVictim": 0, + "whererule | ownTop | unlock": 1, + "whererule | ownTop | delete": 1, + "frozen | anonymous | read": 0, + "frozen | anonymous | create": 0, + "frozen | anonymous | patchVictim": 0, + "frozen | anonymous | patchTop": 0, + "frozen | anonymous | patchTwin": 0, + "frozen | anonymous | rolesVictim": 0, + "frozen | anonymous | unlock": 0, + "frozen | anonymous | delete": 0, + "frozen | customer | read": 0, + "frozen | customer | create": 0, + "frozen | customer | patchVictim": 0, + "frozen | customer | patchTop": 0, + "frozen | customer | patchTwin": 0, + "frozen | customer | rolesVictim": 0, + "frozen | customer | unlock": 0, + "frozen | customer | delete": 0, + "frozen | namesake | read": 3, + "frozen | namesake | create": 0, + "frozen | namesake | patchVictim": 0, + "frozen | namesake | patchTop": 0, + "frozen | namesake | patchTwin": 0, + "frozen | namesake | rolesVictim": 0, + "frozen | namesake | unlock": 0, + "frozen | namesake | delete": 0, + "frozen | agentsAdmin | read": 3, + "frozen | agentsAdmin | create": 1, + "frozen | agentsAdmin | patchVictim": 0, + "frozen | agentsAdmin | patchTop": 0, + "frozen | agentsAdmin | patchTwin": 0, + "frozen | agentsAdmin | rolesVictim": 0, + "frozen | agentsAdmin | unlock": 1, + "frozen | agentsAdmin | delete": 1, + "frozen | ownLow | signedIn": 1, + "frozen | ownLow | read": 4, + "frozen | ownLow | create": 0, + "frozen | ownLow | patchVictim": 0, + "frozen | ownLow | patchTop": 0, + "frozen | ownLow | raiseSelf": 0, + "frozen | ownLow | rolesVictim": 0, + "frozen | ownLow | unlock": 0, + "frozen | ownLow | delete": 0, + "frozen | ownLow | ownPassword": 0, + "frozen | ownTop | signedIn": 1, + "frozen | ownTop | read": 4, + "frozen | ownTop | create": 1, + "frozen | ownTop | patchVictim": 0, + "frozen | ownTop | patchTwin": 0, + "frozen | ownTop | rolesVictim": 0, + "frozen | ownTop | unlock": 1, + "frozen | ownTop | delete": 1, + "shared1 | anonymous | read": 0, + "shared1 | anonymous | create": 0, + "shared1 | anonymous | patchVictim": 0, + "shared1 | anonymous | patchTop": 0, + "shared1 | anonymous | patchTwin": 0, + "shared1 | anonymous | rolesVictim": 0, + "shared1 | anonymous | unlock": 0, + "shared1 | anonymous | delete": 0, + "shared1 | customer | read": 0, + "shared1 | customer | create": 0, + "shared1 | customer | patchVictim": 0, + "shared1 | customer | patchTop": 0, + "shared1 | customer | patchTwin": 0, + "shared1 | customer | rolesVictim": 0, + "shared1 | customer | unlock": 0, + "shared1 | customer | delete": 0, + "shared1 | namesake | read": 3, + "shared1 | namesake | create": 0, + "shared1 | namesake | patchVictim": 0, + "shared1 | namesake | patchTop": 0, + "shared1 | namesake | patchTwin": 1, + "shared1 | namesake | rolesVictim": 0, + "shared1 | namesake | unlock": 0, + "shared1 | namesake | delete": 0, + "shared1 | agentsAdmin | read": 3, + "shared1 | agentsAdmin | create": 1, + "shared1 | agentsAdmin | patchVictim": 1, + "shared1 | agentsAdmin | patchTop": 1, + "shared1 | agentsAdmin | patchTwin": 1, + "shared1 | agentsAdmin | rolesVictim": 1, + "shared1 | agentsAdmin | unlock": 1, + "shared1 | agentsAdmin | delete": 1, + "shared1 | ownLow | signedIn": 1, + "shared1 | ownLow | read": 4, + "shared1 | ownLow | create": 0, + "shared1 | ownLow | patchVictim": 0, + "shared1 | ownLow | patchTop": 0, + "shared1 | ownLow | raiseSelf": 0, + "shared1 | ownLow | rolesVictim": 0, + "shared1 | ownLow | unlock": 0, + "shared1 | ownLow | delete": 0, + "shared1 | ownLow | ownPassword": 0, + "shared1 | ownTop | signedIn": 1, + "shared1 | ownTop | read": 4, + "shared1 | ownTop | create": 1, + "shared1 | ownTop | patchVictim": 1, + "shared1 | ownTop | patchTwin": 1, + "shared1 | ownTop | rolesVictim": 1, + "shared1 | ownTop | unlock": 1, + "shared1 | ownTop | delete": 1, + "shared2 | anonymous | read": 0, + "shared2 | anonymous | create": 0, + "shared2 | anonymous | patchVictim": 0, + "shared2 | anonymous | patchTop": 0, + "shared2 | anonymous | patchTwin": 0, + "shared2 | anonymous | rolesVictim": 0, + "shared2 | anonymous | unlock": 0, + "shared2 | anonymous | delete": 0, + "shared2 | customer | read": 0, + "shared2 | customer | create": 0, + "shared2 | customer | patchVictim": 0, + "shared2 | customer | patchTop": 0, + "shared2 | customer | patchTwin": 0, + "shared2 | customer | rolesVictim": 0, + "shared2 | customer | unlock": 0, + "shared2 | customer | delete": 0, + "shared2 | namesake | read": 3, + "shared2 | namesake | create": 0, + "shared2 | namesake | patchVictim": 0, + "shared2 | namesake | patchTop": 0, + "shared2 | namesake | patchTwin": 1, + "shared2 | namesake | rolesVictim": 0, + "shared2 | namesake | unlock": 0, + "shared2 | namesake | delete": 0, + "shared2 | agentsAdmin | read": 3, + "shared2 | agentsAdmin | create": 1, + "shared2 | agentsAdmin | patchVictim": 1, + "shared2 | agentsAdmin | patchTop": 1, + "shared2 | agentsAdmin | patchTwin": 1, + "shared2 | agentsAdmin | rolesVictim": 1, + "shared2 | agentsAdmin | unlock": 1, + "shared2 | agentsAdmin | delete": 1, + "shared2 | ownLow | signedIn": 1, + "shared2 | ownLow | read": 4, + "shared2 | ownLow | create": 0, + "shared2 | ownLow | patchVictim": 0, + "shared2 | ownLow | patchTop": 0, + "shared2 | ownLow | raiseSelf": 0, + "shared2 | ownLow | rolesVictim": 0, + "shared2 | ownLow | unlock": 0, + "shared2 | ownLow | delete": 0, + "shared2 | ownLow | ownPassword": 0, + "shared2 | ownTop | signedIn": 1, + "shared2 | ownTop | read": 4, + "shared2 | ownTop | create": 1, + "shared2 | ownTop | patchVictim": 1, + "shared2 | ownTop | patchTwin": 1, + "shared2 | ownTop | rolesVictim": 1, + "shared2 | ownTop | unlock": 1, + "shared2 | ownTop | delete": 1, + "hookproxy | anonymous | read": 0, + "hookproxy | anonymous | create": 0, + "hookproxy | anonymous | patchVictim": 0, + "hookproxy | anonymous | patchTop": 0, + "hookproxy | anonymous | patchTwin": 0, + "hookproxy | anonymous | rolesVictim": 0, + "hookproxy | anonymous | unlock": 0, + "hookproxy | anonymous | delete": 0, + "hookproxy | customer | read": 0, + "hookproxy | customer | create": 0, + "hookproxy | customer | patchVictim": 0, + "hookproxy | customer | patchTop": 0, + "hookproxy | customer | patchTwin": 0, + "hookproxy | customer | rolesVictim": 0, + "hookproxy | customer | unlock": 0, + "hookproxy | customer | delete": 0, + "hookproxy | namesake | read": 3, + "hookproxy | namesake | create": 0, + "hookproxy | namesake | patchVictim": 0, + "hookproxy | namesake | patchTop": 0, + "hookproxy | namesake | patchTwin": 1, + "hookproxy | namesake | rolesVictim": 0, + "hookproxy | namesake | unlock": 0, + "hookproxy | namesake | delete": 0, + "hookproxy | agentsAdmin | read": 3, + "hookproxy | agentsAdmin | create": 1, + "hookproxy | agentsAdmin | patchVictim": 1, + "hookproxy | agentsAdmin | patchTop": 1, + "hookproxy | agentsAdmin | patchTwin": 1, + "hookproxy | agentsAdmin | rolesVictim": 1, + "hookproxy | agentsAdmin | unlock": 1, + "hookproxy | agentsAdmin | delete": 1, + "hookproxy | ownLow | signedIn": 1, + "hookproxy | ownLow | read": 4, + "hookproxy | ownLow | create": 0, + "hookproxy | ownLow | patchVictim": 0, + "hookproxy | ownLow | patchTop": 0, + "hookproxy | ownLow | raiseSelf": 0, + "hookproxy | ownLow | rolesVictim": 0, + "hookproxy | ownLow | unlock": 0, + "hookproxy | ownLow | delete": 0, + "hookproxy | ownLow | ownPassword": 0, + "hookproxy | ownTop | signedIn": 1, + "hookproxy | ownTop | read": 4, + "hookproxy | ownTop | create": 1, + "hookproxy | ownTop | patchVictim": 1, + "hookproxy | ownTop | patchTwin": 1, + "hookproxy | ownTop | rolesVictim": 1, + "hookproxy | ownTop | unlock": 1, + "hookproxy | ownTop | delete": 1, + "optopen | anonymous | read": 3, + "optopen | anonymous | create": 1, + "optopen | anonymous | patchVictim": 0, + "optopen | anonymous | patchTop": 0, + "optopen | anonymous | patchTwin": 0, + "optopen | anonymous | rolesVictim": 0, + "optopen | anonymous | unlock": 0, + "optopen | anonymous | delete": 0, + "optopen | customer | read": 3, + "optopen | customer | create": 1, + "optopen | customer | patchVictim": 0, + "optopen | customer | patchTop": 0, + "optopen | customer | patchTwin": 0, + "optopen | customer | rolesVictim": 0, + "optopen | customer | unlock": 0, + "optopen | customer | delete": 0, + "optopen | namesake | read": 3, + "optopen | namesake | create": 1, + "optopen | namesake | patchVictim": 0, + "optopen | namesake | patchTop": 0, + "optopen | namesake | patchTwin": 1, + "optopen | namesake | rolesVictim": 0, + "optopen | namesake | unlock": 0, + "optopen | namesake | delete": 0, + "optopen | agentsAdmin | read": 3, + "optopen | agentsAdmin | create": 1, + "optopen | agentsAdmin | patchVictim": 1, + "optopen | agentsAdmin | patchTop": 1, + "optopen | agentsAdmin | patchTwin": 1, + "optopen | agentsAdmin | rolesVictim": 1, + "optopen | agentsAdmin | unlock": 1, + "optopen | agentsAdmin | delete": 1, + "optopen | ownLow | signedIn": 1, + "optopen | ownLow | read": 4, + "optopen | ownLow | create": 1, + "optopen | ownLow | patchVictim": 0, + "optopen | ownLow | patchTop": 0, + "optopen | ownLow | raiseSelf": 0, + "optopen | ownLow | rolesVictim": 0, + "optopen | ownLow | unlock": 0, + "optopen | ownLow | delete": 0, + "optopen | ownLow | ownPassword": 0, + "optopen | ownTop | signedIn": 1, + "optopen | ownTop | read": 5, + "optopen | ownTop | create": 1, + "optopen | ownTop | patchVictim": 1, + "optopen | ownTop | patchTwin": 1, + "optopen | ownTop | rolesVictim": 1, + "optopen | ownTop | unlock": 1, + "optopen | ownTop | delete": 1, + "optsame | anonymous | read": 0, + "optsame | anonymous | create": 0, + "optsame | anonymous | patchVictim": 0, + "optsame | anonymous | patchTop": 0, + "optsame | anonymous | patchTwin": 0, + "optsame | anonymous | rolesVictim": 0, + "optsame | anonymous | unlock": 0, + "optsame | anonymous | delete": 0, + "optsame | customer | read": 0, + "optsame | customer | create": 0, + "optsame | customer | patchVictim": 0, + "optsame | customer | patchTop": 0, + "optsame | customer | patchTwin": 0, + "optsame | customer | rolesVictim": 0, + "optsame | customer | unlock": 0, + "optsame | customer | delete": 0, + "optsame | namesake | read": 3, + "optsame | namesake | create": 0, + "optsame | namesake | patchVictim": 0, + "optsame | namesake | patchTop": 0, + "optsame | namesake | patchTwin": 1, + "optsame | namesake | rolesVictim": 0, + "optsame | namesake | unlock": 0, + "optsame | namesake | delete": 0, + "optsame | agentsAdmin | read": 3, + "optsame | agentsAdmin | create": 1, + "optsame | agentsAdmin | patchVictim": 1, + "optsame | agentsAdmin | patchTop": 1, + "optsame | agentsAdmin | patchTwin": 1, + "optsame | agentsAdmin | rolesVictim": 1, + "optsame | agentsAdmin | unlock": 1, + "optsame | agentsAdmin | delete": 1, + "optsame | ownLow | signedIn": 1, + "optsame | ownLow | read": 4, + "optsame | ownLow | create": 0, + "optsame | ownLow | patchVictim": 0, + "optsame | ownLow | patchTop": 0, + "optsame | ownLow | raiseSelf": 0, + "optsame | ownLow | rolesVictim": 0, + "optsame | ownLow | unlock": 0, + "optsame | ownLow | delete": 0, + "optsame | ownLow | ownPassword": 0, + "optsame | ownTop | signedIn": 1, + "optsame | ownTop | read": 4, + "optsame | ownTop | create": 1, + "optsame | ownTop | patchVictim": 1, + "optsame | ownTop | patchTwin": 1, + "optsame | ownTop | rolesVictim": 1, + "optsame | ownTop | unlock": 1, + "optsame | ownTop | delete": 1, + "optvals | anonymous | read": 0, + "optvals | anonymous | create": 0, + "optvals | anonymous | patchVictim": 0, + "optvals | anonymous | patchTop": 0, + "optvals | anonymous | patchTwin": 0, + "optvals | anonymous | rolesVictim": 0, + "optvals | anonymous | unlock": 0, + "optvals | anonymous | delete": 0, + "optvals | customer | read": 0, + "optvals | customer | create": 0, + "optvals | customer | patchVictim": 0, + "optvals | customer | patchTop": 0, + "optvals | customer | patchTwin": 0, + "optvals | customer | rolesVictim": 0, + "optvals | customer | unlock": 0, + "optvals | customer | delete": 0, + "optvals | namesake | read": 3, + "optvals | namesake | create": 0, + "optvals | namesake | patchVictim": 0, + "optvals | namesake | patchTop": 0, + "optvals | namesake | patchTwin": 1, + "optvals | namesake | rolesVictim": 0, + "optvals | namesake | unlock": 0, + "optvals | namesake | delete": 0, + "optvals | agentsAdmin | read": 3, + "optvals | agentsAdmin | create": 1, + "optvals | agentsAdmin | patchVictim": 1, + "optvals | agentsAdmin | patchTop": 1, + "optvals | agentsAdmin | patchTwin": 1, + "optvals | agentsAdmin | rolesVictim": 1, + "optvals | agentsAdmin | unlock": 1, + "optvals | agentsAdmin | delete": 1, + "optvals | ownLow | signedIn": 1, + "optvals | ownLow | read": 4, + "optvals | ownLow | create": 0, + "optvals | ownLow | patchVictim": 0, + "optvals | ownLow | patchTop": 0, + "optvals | ownLow | raiseSelf": 0, + "optvals | ownLow | rolesVictim": 0, + "optvals | ownLow | unlock": 0, + "optvals | ownLow | delete": 0, + "optvals | ownLow | ownPassword": 0, + "optvals | ownTop | signedIn": 1, + "optvals | ownTop | read": 4, + "optvals | ownTop | create": 1, + "optvals | ownTop | patchVictim": 1, + "optvals | ownTop | patchTwin": 1, + "optvals | ownTop | rolesVictim": 1, + "optvals | ownTop | unlock": 1, + "optvals | ownTop | delete": 1, + "optplain | anonymous | read": 0, + "optplain | anonymous | create": 0, + "optplain | anonymous | patchVictim": 0, + "optplain | anonymous | patchTop": 0, + "optplain | anonymous | patchTwin": 0, + "optplain | anonymous | rolesVictim": 0, + "optplain | anonymous | unlock": 0, + "optplain | anonymous | delete": 0, + "optplain | customer | read": 0, + "optplain | customer | create": 0, + "optplain | customer | patchVictim": 0, + "optplain | customer | patchTop": 0, + "optplain | customer | patchTwin": 0, + "optplain | customer | rolesVictim": 0, + "optplain | customer | unlock": 0, + "optplain | customer | delete": 0, + "optplain | namesake | read": 3, + "optplain | namesake | create": 0, + "optplain | namesake | patchVictim": 0, + "optplain | namesake | patchTop": 0, + "optplain | namesake | patchTwin": 1, + "optplain | namesake | rolesVictim": 0, + "optplain | namesake | unlock": 0, + "optplain | namesake | delete": 0, + "optplain | agentsAdmin | read": 3, + "optplain | agentsAdmin | create": 1, + "optplain | agentsAdmin | patchVictim": 1, + "optplain | agentsAdmin | patchTop": 1, + "optplain | agentsAdmin | patchTwin": 1, + "optplain | agentsAdmin | rolesVictim": 1, + "optplain | agentsAdmin | unlock": 1, + "optplain | agentsAdmin | delete": 1, + "optplain | ownLow | signedIn": 1, + "optplain | ownLow | read": 4, + "optplain | ownLow | create": 0, + "optplain | ownLow | patchVictim": 0, + "optplain | ownLow | patchTop": 0, + "optplain | ownLow | raiseSelf": 0, + "optplain | ownLow | rolesVictim": 0, + "optplain | ownLow | unlock": 0, + "optplain | ownLow | delete": 0, + "optplain | ownLow | ownPassword": 0, + "optplain | ownTop | signedIn": 1, + "optplain | ownTop | read": 4, + "optplain | ownTop | create": 1, + "optplain | ownTop | patchVictim": 1, + "optplain | ownTop | patchTwin": 1, + "optplain | ownTop | rolesVictim": 1, + "optplain | ownTop | unlock": 1, + "optplain | ownTop | delete": 1, + "ownvals | anonymous | read": 0, + "ownvals | anonymous | create": 0, + "ownvals | anonymous | patchVictim": 0, + "ownvals | anonymous | patchTop": 0, + "ownvals | anonymous | patchTwin": 0, + "ownvals | anonymous | rolesVictim": 0, + "ownvals | anonymous | unlock": 0, + "ownvals | anonymous | delete": 0, + "ownvals | customer | read": 0, + "ownvals | customer | create": 0, + "ownvals | customer | patchVictim": 0, + "ownvals | customer | patchTop": 0, + "ownvals | customer | patchTwin": 0, + "ownvals | customer | rolesVictim": 0, + "ownvals | customer | unlock": 0, + "ownvals | customer | delete": 0, + "ownvals | namesake | read": 3, + "ownvals | namesake | create": 0, + "ownvals | namesake | patchVictim": 0, + "ownvals | namesake | patchTop": 0, + "ownvals | namesake | patchTwin": 1, + "ownvals | namesake | rolesVictim": 0, + "ownvals | namesake | unlock": 0, + "ownvals | namesake | delete": 0, + "ownvals | agentsAdmin | read": 3, + "ownvals | agentsAdmin | create": 1, + "ownvals | agentsAdmin | patchVictim": 1, + "ownvals | agentsAdmin | patchTop": 1, + "ownvals | agentsAdmin | patchTwin": 1, + "ownvals | agentsAdmin | rolesVictim": 1, + "ownvals | agentsAdmin | unlock": 1, + "ownvals | agentsAdmin | delete": 1, + "ownvals | ownLow | signedIn": 1, + "ownvals | ownLow | read": 4, + "ownvals | ownLow | create": 0, + "ownvals | ownLow | patchVictim": 0, + "ownvals | ownLow | patchTop": 0, + "ownvals | ownLow | raiseSelf": 0, + "ownvals | ownLow | rolesVictim": 0, + "ownvals | ownLow | unlock": 0, + "ownvals | ownLow | delete": 0, + "ownvals | ownLow | ownPassword": 0, + "ownvals | ownTop | signedIn": 1, + "ownvals | ownTop | read": 4, + "ownvals | ownTop | create": 1, + "ownvals | ownTop | patchVictim": 1, + "ownvals | ownTop | patchTwin": 1, + "ownvals | ownTop | rolesVictim": 1, + "ownvals | ownTop | unlock": 1, + "ownvals | ownTop | delete": 1, + "ownvalsnon | anonymous | read": 0, + "ownvalsnon | anonymous | create": 0, + "ownvalsnon | anonymous | patchVictim": 0, + "ownvalsnon | anonymous | patchTop": 0, + "ownvalsnon | anonymous | patchTwin": 0, + "ownvalsnon | anonymous | rolesVictim": 0, + "ownvalsnon | anonymous | unlock": 0, + "ownvalsnon | anonymous | delete": 0, + "ownvalsnon | customer | read": 0, + "ownvalsnon | customer | create": 0, + "ownvalsnon | customer | patchVictim": 0, + "ownvalsnon | customer | patchTop": 0, + "ownvalsnon | customer | patchTwin": 0, + "ownvalsnon | customer | rolesVictim": 0, + "ownvalsnon | customer | unlock": 0, + "ownvalsnon | customer | delete": 0, + "ownvalsnon | namesake | read": 3, + "ownvalsnon | namesake | create": 0, + "ownvalsnon | namesake | patchVictim": 0, + "ownvalsnon | namesake | patchTop": 0, + "ownvalsnon | namesake | patchTwin": 1, + "ownvalsnon | namesake | rolesVictim": 0, + "ownvalsnon | namesake | unlock": 0, + "ownvalsnon | namesake | delete": 0, + "ownvalsnon | agentsAdmin | read": 3, + "ownvalsnon | agentsAdmin | create": 1, + "ownvalsnon | agentsAdmin | patchVictim": 1, + "ownvalsnon | agentsAdmin | patchTop": 1, + "ownvalsnon | agentsAdmin | patchTwin": 1, + "ownvalsnon | agentsAdmin | rolesVictim": 1, + "ownvalsnon | agentsAdmin | unlock": 1, + "ownvalsnon | agentsAdmin | delete": 1, + "ownvalsnon | ownLow | signedIn": 0, + "ownvalsnon | ownLow | read": 0, + "ownvalsnon | ownLow | create": 0, + "ownvalsnon | ownLow | patchVictim": 0, + "ownvalsnon | ownLow | patchTop": 0, + "ownvalsnon | ownLow | raiseSelf": 0, + "ownvalsnon | ownLow | rolesVictim": 0, + "ownvalsnon | ownLow | unlock": 0, + "ownvalsnon | ownLow | delete": 0, + "ownvalsnon | ownLow | ownPassword": 0, + "ownvalsnon | ownTop | signedIn": 0, + "ownvalsnon | ownTop | read": 0, + "ownvalsnon | ownTop | create": 0, + "ownvalsnon | ownTop | patchVictim": 0, + "ownvalsnon | ownTop | patchTwin": 0, + "ownvalsnon | ownTop | rolesVictim": 0, + "ownvalsnon | ownTop | unlock": 0, + "ownvalsnon | ownTop | delete": 0, + "freshown | anonymous | read": 0, + "freshown | anonymous | create": 0, + "freshown | anonymous | patchVictim": 0, + "freshown | anonymous | patchTop": 0, + "freshown | anonymous | patchTwin": 0, + "freshown | anonymous | rolesVictim": 0, + "freshown | anonymous | unlock": 0, + "freshown | anonymous | delete": 0, + "freshown | customer | read": 0, + "freshown | customer | create": 0, + "freshown | customer | patchVictim": 0, + "freshown | customer | patchTop": 0, + "freshown | customer | patchTwin": 0, + "freshown | customer | rolesVictim": 0, + "freshown | customer | unlock": 0, + "freshown | customer | delete": 0, + "freshown | namesake | read": 3, + "freshown | namesake | create": 0, + "freshown | namesake | patchVictim": 0, + "freshown | namesake | patchTop": 0, + "freshown | namesake | patchTwin": 0, + "freshown | namesake | rolesVictim": 0, + "freshown | namesake | unlock": 0, + "freshown | namesake | delete": 0, + "freshown | agentsAdmin | read": 3, + "freshown | agentsAdmin | create": 1, + "freshown | agentsAdmin | patchVictim": 1, + "freshown | agentsAdmin | patchTop": 1, + "freshown | agentsAdmin | patchTwin": 1, + "freshown | agentsAdmin | rolesVictim": 1, + "freshown | agentsAdmin | unlock": 1, + "freshown | agentsAdmin | delete": 1, + "freshown | ownLow | signedIn": 1, + "freshown | ownLow | read": 4, + "freshown | ownLow | create": 0, + "freshown | ownLow | patchVictim": 0, + "freshown | ownLow | patchTop": 0, + "freshown | ownLow | raiseSelf": 0, + "freshown | ownLow | rolesVictim": 0, + "freshown | ownLow | unlock": 0, + "freshown | ownLow | delete": 0, + "freshown | ownLow | ownPassword": 0, + "freshown | ownTop | signedIn": 1, + "freshown | ownTop | read": 4, + "freshown | ownTop | create": 1, + "freshown | ownTop | patchVictim": 1, + "freshown | ownTop | patchTwin": 1, + "freshown | ownTop | rolesVictim": 1, + "freshown | ownTop | unlock": 1, + "freshown | ownTop | delete": 1, + "renamed | anonymous | read": 0, + "renamed | anonymous | create": 0, + "renamed | anonymous | patchVictim": 0, + "renamed | anonymous | patchTop": 0, + "renamed | anonymous | patchTwin": 0, + "renamed | anonymous | rolesVictim": 0, + "renamed | anonymous | unlock": 0, + "renamed | anonymous | delete": 0, + "renamed | customer | read": 0, + "renamed | customer | create": 0, + "renamed | customer | patchVictim": 0, + "renamed | customer | patchTop": 0, + "renamed | customer | patchTwin": 0, + "renamed | customer | rolesVictim": 0, + "renamed | customer | unlock": 0, + "renamed | customer | delete": 0, + "renamed | namesake | read": 3, + "renamed | namesake | create": 0, + "renamed | namesake | patchVictim": 0, + "renamed | namesake | patchTop": 0, + "renamed | namesake | patchTwin": 1, + "renamed | namesake | rolesVictim": 0, + "renamed | namesake | unlock": 0, + "renamed | namesake | delete": 0, + "renamed | agentsAdmin | read": 3, + "renamed | agentsAdmin | create": 1, + "renamed | agentsAdmin | patchVictim": 1, + "renamed | agentsAdmin | patchTop": 1, + "renamed | agentsAdmin | patchTwin": 1, + "renamed | agentsAdmin | rolesVictim": 1, + "renamed | agentsAdmin | unlock": 1, + "renamed | agentsAdmin | delete": 1, + "renamed | ownLow | signedIn": 1, + "renamed | ownLow | read": 4, + "renamed | ownLow | create": 0, + "renamed | ownLow | patchVictim": 0, + "renamed | ownLow | patchTop": 0, + "renamed | ownLow | raiseSelf": 0, + "renamed | ownLow | rolesVictim": 0, + "renamed | ownLow | unlock": 0, + "renamed | ownLow | delete": 0, + "renamed | ownLow | ownPassword": 0, + "renamed | ownTop | signedIn": 1, + "renamed | ownTop | read": 4, + "renamed | ownTop | create": 0, + "renamed | ownTop | patchVictim": 0, + "renamed | ownTop | patchTwin": 0, + "renamed | ownTop | rolesVictim": 0, + "renamed | ownTop | unlock": 0, + "renamed | ownTop | delete": 0, + "noroles | anonymous | read": 0, + "noroles | anonymous | create": 0, + "noroles | anonymous | patchVictim": 0, + "noroles | anonymous | patchTop": 0, + "noroles | anonymous | patchTwin": 0, + "noroles | anonymous | unlock": 0, + "noroles | anonymous | delete": 0, + "noroles | customer | read": 0, + "noroles | customer | create": 0, + "noroles | customer | patchVictim": 0, + "noroles | customer | patchTop": 0, + "noroles | customer | patchTwin": 0, + "noroles | customer | unlock": 0, + "noroles | customer | delete": 0, + "noroles | namesake | read": 3, + "noroles | namesake | create": 0, + "noroles | namesake | patchVictim": 0, + "noroles | namesake | patchTop": 0, + "noroles | namesake | patchTwin": 1, + "noroles | namesake | unlock": 0, + "noroles | namesake | delete": 0, + "noroles | agentsAdmin | read": 3, + "noroles | agentsAdmin | create": 1, + "noroles | agentsAdmin | patchVictim": 1, + "noroles | agentsAdmin | patchTop": 1, + "noroles | agentsAdmin | patchTwin": 1, + "noroles | agentsAdmin | unlock": 1, + "noroles | agentsAdmin | delete": 1, + "noroles | ownLow | signedIn": 1, + "noroles | ownLow | read": 4, + "noroles | ownLow | create": 1, + "noroles | ownLow | patchVictim": 1, + "noroles | ownLow | patchTop": 1, + "noroles | ownLow | unlock": 1, + "noroles | ownLow | delete": 1, + "noroles | ownLow | ownPassword": 1, + "noroles | ownTop | signedIn": 1, + "noroles | ownTop | read": 5, + "noroles | ownTop | create": 1, + "noroles | ownTop | patchVictim": 1, + "noroles | ownTop | patchTwin": 1, + "noroles | ownTop | unlock": 1, + "noroles | ownTop | delete": 1, + "crewcopy | anonymous | read": 0, + "crewcopy | anonymous | create": 0, + "crewcopy | anonymous | patchVictim": 0, + "crewcopy | anonymous | patchTop": 0, + "crewcopy | anonymous | patchTwin": 0, + "crewcopy | anonymous | rolesVictim": 0, + "crewcopy | anonymous | unlock": 0, + "crewcopy | anonymous | delete": 0, + "crewcopy | customer | read": 0, + "crewcopy | customer | create": 0, + "crewcopy | customer | patchVictim": 0, + "crewcopy | customer | patchTop": 0, + "crewcopy | customer | patchTwin": 0, + "crewcopy | customer | rolesVictim": 0, + "crewcopy | customer | unlock": 0, + "crewcopy | customer | delete": 0, + "crewcopy | namesake | read": 3, + "crewcopy | namesake | create": 0, + "crewcopy | namesake | patchVictim": 0, + "crewcopy | namesake | patchTop": 0, + "crewcopy | namesake | patchTwin": 0, + "crewcopy | namesake | rolesVictim": 0, + "crewcopy | namesake | unlock": 0, + "crewcopy | namesake | delete": 0, + "crewcopy | agentsAdmin | read": 3, + "crewcopy | agentsAdmin | create": 1, + "crewcopy | agentsAdmin | patchVictim": 1, + "crewcopy | agentsAdmin | patchTop": 1, + "crewcopy | agentsAdmin | patchTwin": 1, + "crewcopy | agentsAdmin | rolesVictim": 1, + "crewcopy | agentsAdmin | unlock": 1, + "crewcopy | agentsAdmin | delete": 1, + "crewcopy | ownLow | signedIn": 1, + "crewcopy | ownLow | read": 4, + "crewcopy | ownLow | create": 0, + "crewcopy | ownLow | patchVictim": 0, + "crewcopy | ownLow | patchTop": 0, + "crewcopy | ownLow | raiseSelf": 0, + "crewcopy | ownLow | rolesVictim": 0, + "crewcopy | ownLow | unlock": 0, + "crewcopy | ownLow | delete": 0, + "crewcopy | ownLow | ownPassword": 0, + "crewcopy | ownTop | signedIn": 1, + "crewcopy | ownTop | read": 4, + "crewcopy | ownTop | create": 1, + "crewcopy | ownTop | patchVictim": 1, + "crewcopy | ownTop | patchTwin": 1, + "crewcopy | ownTop | rolesVictim": 1, + "crewcopy | ownTop | unlock": 1, + "crewcopy | ownTop | delete": 1, + "crewnon | anonymous | read": 0, + "crewnon | anonymous | create": 0, + "crewnon | anonymous | patchVictim": 0, + "crewnon | anonymous | patchTop": 0, + "crewnon | anonymous | patchTwin": 0, + "crewnon | anonymous | rolesVictim": 0, + "crewnon | anonymous | unlock": 0, + "crewnon | anonymous | delete": 0, + "crewnon | customer | read": 0, + "crewnon | customer | create": 0, + "crewnon | customer | patchVictim": 0, + "crewnon | customer | patchTop": 0, + "crewnon | customer | patchTwin": 0, + "crewnon | customer | rolesVictim": 0, + "crewnon | customer | unlock": 0, + "crewnon | customer | delete": 0, + "crewnon | namesake | read": 3, + "crewnon | namesake | create": 0, + "crewnon | namesake | patchVictim": 0, + "crewnon | namesake | patchTop": 0, + "crewnon | namesake | patchTwin": 0, + "crewnon | namesake | rolesVictim": 0, + "crewnon | namesake | unlock": 0, + "crewnon | namesake | delete": 0, + "crewnon | agentsAdmin | read": 3, + "crewnon | agentsAdmin | create": 1, + "crewnon | agentsAdmin | patchVictim": 1, + "crewnon | agentsAdmin | patchTop": 1, + "crewnon | agentsAdmin | patchTwin": 1, + "crewnon | agentsAdmin | rolesVictim": 1, + "crewnon | agentsAdmin | unlock": 1, + "crewnon | agentsAdmin | delete": 1, + "crewnon | ownLow | signedIn": 0, + "crewnon | ownLow | read": 0, + "crewnon | ownLow | create": 0, + "crewnon | ownLow | patchVictim": 0, + "crewnon | ownLow | patchTop": 0, + "crewnon | ownLow | raiseSelf": 0, + "crewnon | ownLow | rolesVictim": 0, + "crewnon | ownLow | unlock": 0, + "crewnon | ownLow | delete": 0, + "crewnon | ownLow | ownPassword": 0, + "crewnon | ownTop | signedIn": 0, + "crewnon | ownTop | read": 0, + "crewnon | ownTop | create": 0, + "crewnon | ownTop | patchVictim": 0, + "crewnon | ownTop | patchTwin": 0, + "crewnon | ownTop | rolesVictim": 0, + "crewnon | ownTop | unlock": 0, + "crewnon | ownTop | delete": 0, + "crewadmin | anonymous | read": 0, + "crewadmin | anonymous | create": 0, + "crewadmin | anonymous | patchVictim": 0, + "crewadmin | anonymous | patchTop": 0, + "crewadmin | anonymous | patchTwin": 0, + "crewadmin | anonymous | rolesVictim": 0, + "crewadmin | anonymous | unlock": 0, + "crewadmin | anonymous | delete": 0, + "crewadmin | customer | read": 0, + "crewadmin | customer | create": 0, + "crewadmin | customer | patchVictim": 0, + "crewadmin | customer | patchTop": 0, + "crewadmin | customer | patchTwin": 0, + "crewadmin | customer | rolesVictim": 0, + "crewadmin | customer | unlock": 0, + "crewadmin | customer | delete": 0, + "crewadmin | namesake | read": 3, + "crewadmin | namesake | create": 0, + "crewadmin | namesake | patchVictim": 0, + "crewadmin | namesake | patchTop": 0, + "crewadmin | namesake | patchTwin": 0, + "crewadmin | namesake | rolesVictim": 0, + "crewadmin | namesake | unlock": 0, + "crewadmin | namesake | delete": 0, + "crewadmin | agentsAdmin | read": 3, + "crewadmin | agentsAdmin | create": 1, + "crewadmin | agentsAdmin | patchVictim": 1, + "crewadmin | agentsAdmin | patchTop": 1, + "crewadmin | agentsAdmin | patchTwin": 1, + "crewadmin | agentsAdmin | rolesVictim": 1, + "crewadmin | agentsAdmin | unlock": 1, + "crewadmin | agentsAdmin | delete": 1, + "crewadmin | ownLow | signedIn": 1, + "crewadmin | ownLow | read": 4, + "crewadmin | ownLow | create": 0, + "crewadmin | ownLow | patchVictim": 0, + "crewadmin | ownLow | patchTop": 0, + "crewadmin | ownLow | raiseSelf": 0, + "crewadmin | ownLow | rolesVictim": 0, + "crewadmin | ownLow | unlock": 0, + "crewadmin | ownLow | delete": 0, + "crewadmin | ownLow | ownPassword": 0, + "crewadmin | ownTop | signedIn": 1, + "crewadmin | ownTop | read": 4, + "crewadmin | ownTop | create": 1, + "crewadmin | ownTop | patchVictim": 1, + "crewadmin | ownTop | patchTwin": 1, + "crewadmin | ownTop | rolesVictim": 1, + "crewadmin | ownTop | unlock": 1, + "crewadmin | ownTop | delete": 1, + "teamcopy | anonymous | read": 0, + "teamcopy | anonymous | create": 0, + "teamcopy | anonymous | patchVictim": 0, + "teamcopy | anonymous | patchTop": 0, + "teamcopy | anonymous | patchTwin": 0, + "teamcopy | anonymous | rolesVictim": 0, + "teamcopy | anonymous | unlock": 0, + "teamcopy | anonymous | delete": 0, + "teamcopy | customer | read": 0, + "teamcopy | customer | create": 0, + "teamcopy | customer | patchVictim": 0, + "teamcopy | customer | patchTop": 0, + "teamcopy | customer | patchTwin": 0, + "teamcopy | customer | rolesVictim": 0, + "teamcopy | customer | unlock": 0, + "teamcopy | customer | delete": 0, + "teamcopy | namesake | read": 3, + "teamcopy | namesake | create": 0, + "teamcopy | namesake | patchVictim": 0, + "teamcopy | namesake | patchTop": 0, + "teamcopy | namesake | patchTwin": 0, + "teamcopy | namesake | rolesVictim": 0, + "teamcopy | namesake | unlock": 0, + "teamcopy | namesake | delete": 0, + "teamcopy | agentsAdmin | read": 3, + "teamcopy | agentsAdmin | create": 1, + "teamcopy | agentsAdmin | patchVictim": 1, + "teamcopy | agentsAdmin | patchTop": 1, + "teamcopy | agentsAdmin | patchTwin": 1, + "teamcopy | agentsAdmin | rolesVictim": 1, + "teamcopy | agentsAdmin | unlock": 1, + "teamcopy | agentsAdmin | delete": 1, + "teamcopy | ownLow | signedIn": 1, + "teamcopy | ownLow | read": 4, + "teamcopy | ownLow | create": 0, + "teamcopy | ownLow | patchVictim": 0, + "teamcopy | ownLow | patchTop": 0, + "teamcopy | ownLow | raiseSelf": 0, + "teamcopy | ownLow | rolesVictim": 0, + "teamcopy | ownLow | unlock": 0, + "teamcopy | ownLow | delete": 0, + "teamcopy | ownLow | ownPassword": 0, + "teamcopy | ownTop | signedIn": 1, + "teamcopy | ownTop | read": 4, + "teamcopy | ownTop | create": 0, + "teamcopy | ownTop | patchVictim": 0, + "teamcopy | ownTop | patchTwin": 0, + "teamcopy | ownTop | rolesVictim": 0, + "teamcopy | ownTop | unlock": 0, + "teamcopy | ownTop | delete": 0, + "teamnon | anonymous | read": 0, + "teamnon | anonymous | create": 0, + "teamnon | anonymous | patchVictim": 0, + "teamnon | anonymous | patchTop": 0, + "teamnon | anonymous | patchTwin": 0, + "teamnon | anonymous | rolesVictim": 0, + "teamnon | anonymous | unlock": 0, + "teamnon | anonymous | delete": 0, + "teamnon | customer | read": 0, + "teamnon | customer | create": 0, + "teamnon | customer | patchVictim": 0, + "teamnon | customer | patchTop": 0, + "teamnon | customer | patchTwin": 0, + "teamnon | customer | rolesVictim": 0, + "teamnon | customer | unlock": 0, + "teamnon | customer | delete": 0, + "teamnon | namesake | read": 3, + "teamnon | namesake | create": 0, + "teamnon | namesake | patchVictim": 0, + "teamnon | namesake | patchTop": 0, + "teamnon | namesake | patchTwin": 0, + "teamnon | namesake | rolesVictim": 0, + "teamnon | namesake | unlock": 0, + "teamnon | namesake | delete": 0, + "teamnon | agentsAdmin | read": 3, + "teamnon | agentsAdmin | create": 1, + "teamnon | agentsAdmin | patchVictim": 1, + "teamnon | agentsAdmin | patchTop": 1, + "teamnon | agentsAdmin | patchTwin": 1, + "teamnon | agentsAdmin | rolesVictim": 1, + "teamnon | agentsAdmin | unlock": 1, + "teamnon | agentsAdmin | delete": 1, + "teamnon | ownLow | signedIn": 0, + "teamnon | ownLow | read": 0, + "teamnon | ownLow | create": 0, + "teamnon | ownLow | patchVictim": 0, + "teamnon | ownLow | patchTop": 0, + "teamnon | ownLow | raiseSelf": 0, + "teamnon | ownLow | rolesVictim": 0, + "teamnon | ownLow | unlock": 0, + "teamnon | ownLow | delete": 0, + "teamnon | ownLow | ownPassword": 0, + "teamnon | ownTop | signedIn": 0, + "teamnon | ownTop | read": 0, + "teamnon | ownTop | create": 0, + "teamnon | ownTop | patchVictim": 0, + "teamnon | ownTop | patchTwin": 0, + "teamnon | ownTop | rolesVictim": 0, + "teamnon | ownTop | unlock": 0, + "teamnon | ownTop | delete": 0, + "teamadmin | anonymous | read": 0, + "teamadmin | anonymous | create": 0, + "teamadmin | anonymous | patchVictim": 0, + "teamadmin | anonymous | patchTop": 0, + "teamadmin | anonymous | patchTwin": 0, + "teamadmin | anonymous | rolesVictim": 0, + "teamadmin | anonymous | unlock": 0, + "teamadmin | anonymous | delete": 0, + "teamadmin | customer | read": 0, + "teamadmin | customer | create": 0, + "teamadmin | customer | patchVictim": 0, + "teamadmin | customer | patchTop": 0, + "teamadmin | customer | patchTwin": 0, + "teamadmin | customer | rolesVictim": 0, + "teamadmin | customer | unlock": 0, + "teamadmin | customer | delete": 0, + "teamadmin | namesake | read": 3, + "teamadmin | namesake | create": 0, + "teamadmin | namesake | patchVictim": 0, + "teamadmin | namesake | patchTop": 0, + "teamadmin | namesake | patchTwin": 0, + "teamadmin | namesake | rolesVictim": 0, + "teamadmin | namesake | unlock": 0, + "teamadmin | namesake | delete": 0, + "teamadmin | agentsAdmin | read": 3, + "teamadmin | agentsAdmin | create": 1, + "teamadmin | agentsAdmin | patchVictim": 1, + "teamadmin | agentsAdmin | patchTop": 1, + "teamadmin | agentsAdmin | patchTwin": 1, + "teamadmin | agentsAdmin | rolesVictim": 1, + "teamadmin | agentsAdmin | unlock": 1, + "teamadmin | agentsAdmin | delete": 1, + "teamadmin | ownLow | signedIn": 1, + "teamadmin | ownLow | read": 4, + "teamadmin | ownLow | create": 0, + "teamadmin | ownLow | patchVictim": 0, + "teamadmin | ownLow | patchTop": 0, + "teamadmin | ownLow | raiseSelf": 0, + "teamadmin | ownLow | rolesVictim": 0, + "teamadmin | ownLow | unlock": 0, + "teamadmin | ownLow | delete": 0, + "teamadmin | ownLow | ownPassword": 0, + "teamadmin | ownTop | signedIn": 1, + "teamadmin | ownTop | read": 4, + "teamadmin | ownTop | create": 1, + "teamadmin | ownTop | patchVictim": 1, + "teamadmin | ownTop | patchTwin": 1, + "teamadmin | ownTop | rolesVictim": 1, + "teamadmin | ownTop | unlock": 1, + "teamadmin | ownTop | delete": 1, + "teamfresh | anonymous | read": 0, + "teamfresh | anonymous | create": 0, + "teamfresh | anonymous | patchVictim": 0, + "teamfresh | anonymous | patchTop": 0, + "teamfresh | anonymous | patchTwin": 0, + "teamfresh | anonymous | rolesVictim": 0, + "teamfresh | anonymous | unlock": 0, + "teamfresh | anonymous | delete": 0, + "teamfresh | customer | read": 0, + "teamfresh | customer | create": 0, + "teamfresh | customer | patchVictim": 0, + "teamfresh | customer | patchTop": 0, + "teamfresh | customer | patchTwin": 0, + "teamfresh | customer | rolesVictim": 0, + "teamfresh | customer | unlock": 0, + "teamfresh | customer | delete": 0, + "teamfresh | namesake | read": 3, + "teamfresh | namesake | create": 0, + "teamfresh | namesake | patchVictim": 0, + "teamfresh | namesake | patchTop": 0, + "teamfresh | namesake | patchTwin": 0, + "teamfresh | namesake | rolesVictim": 0, + "teamfresh | namesake | unlock": 0, + "teamfresh | namesake | delete": 0, + "teamfresh | agentsAdmin | read": 3, + "teamfresh | agentsAdmin | create": 1, + "teamfresh | agentsAdmin | patchVictim": 1, + "teamfresh | agentsAdmin | patchTop": 1, + "teamfresh | agentsAdmin | patchTwin": 1, + "teamfresh | agentsAdmin | rolesVictim": 1, + "teamfresh | agentsAdmin | unlock": 1, + "teamfresh | agentsAdmin | delete": 1, + "teamfresh | ownLow | signedIn": 1, + "teamfresh | ownLow | read": 4, + "teamfresh | ownLow | create": 0, + "teamfresh | ownLow | patchVictim": 0, + "teamfresh | ownLow | patchTop": 0, + "teamfresh | ownLow | raiseSelf": 0, + "teamfresh | ownLow | rolesVictim": 0, + "teamfresh | ownLow | unlock": 0, + "teamfresh | ownLow | delete": 0, + "teamfresh | ownLow | ownPassword": 0, + "teamfresh | ownTop | signedIn": 1, + "teamfresh | ownTop | read": 4, + "teamfresh | ownTop | create": 1, + "teamfresh | ownTop | patchVictim": 1, + "teamfresh | ownTop | patchTwin": 1, + "teamfresh | ownTop | rolesVictim": 1, + "teamfresh | ownTop | unlock": 1, + "teamfresh | ownTop | delete": 1, + "forged | anonymous | read": 0, + "forged | anonymous | create": 0, + "forged | anonymous | patchVictim": 0, + "forged | anonymous | patchTop": 0, + "forged | anonymous | patchTwin": 0, + "forged | anonymous | rolesVictim": 0, + "forged | anonymous | unlock": 0, + "forged | anonymous | delete": 0, + "forged | customer | read": 0, + "forged | customer | create": 0, + "forged | customer | patchVictim": 0, + "forged | customer | patchTop": 0, + "forged | customer | patchTwin": 0, + "forged | customer | rolesVictim": 0, + "forged | customer | unlock": 0, + "forged | customer | delete": 0, + "forged | namesake | read": 3, + "forged | namesake | create": 0, + "forged | namesake | patchVictim": 0, + "forged | namesake | patchTop": 0, + "forged | namesake | patchTwin": 0, + "forged | namesake | rolesVictim": 0, + "forged | namesake | unlock": 0, + "forged | namesake | delete": 0, + "forged | agentsAdmin | read": 3, + "forged | agentsAdmin | create": 1, + "forged | agentsAdmin | patchVictim": 0, + "forged | agentsAdmin | patchTop": 0, + "forged | agentsAdmin | patchTwin": 0, + "forged | agentsAdmin | rolesVictim": 0, + "forged | agentsAdmin | unlock": 0, + "forged | agentsAdmin | delete": 1, + "forged | ownLow | signedIn": 1, + "forged | ownLow | read": 4, + "forged | ownLow | create": 0, + "forged | ownLow | patchVictim": 0, + "forged | ownLow | patchTop": 0, + "forged | ownLow | raiseSelf": 0, + "forged | ownLow | rolesVictim": 0, + "forged | ownLow | unlock": 0, + "forged | ownLow | delete": 0, + "forged | ownLow | ownPassword": 0, + "forged | ownTop | signedIn": 1, + "forged | ownTop | read": 4, + "forged | ownTop | create": 1, + "forged | ownTop | patchVictim": 0, + "forged | ownTop | patchTwin": 0, + "forged | ownTop | rolesVictim": 0, + "forged | ownTop | unlock": 0, + "forged | ownTop | delete": 1, + "handmark | anonymous | read": 0, + "handmark | anonymous | create": 0, + "handmark | anonymous | patchVictim": 0, + "handmark | anonymous | patchTop": 0, + "handmark | anonymous | patchTwin": 0, + "handmark | anonymous | rolesVictim": 0, + "handmark | anonymous | unlock": 0, + "handmark | anonymous | delete": 0, + "handmark | customer | read": 0, + "handmark | customer | create": 0, + "handmark | customer | patchVictim": 0, + "handmark | customer | patchTop": 0, + "handmark | customer | patchTwin": 0, + "handmark | customer | rolesVictim": 0, + "handmark | customer | unlock": 0, + "handmark | customer | delete": 0, + "handmark | namesake | read": 3, + "handmark | namesake | create": 0, + "handmark | namesake | patchVictim": 0, + "handmark | namesake | patchTop": 0, + "handmark | namesake | patchTwin": 0, + "handmark | namesake | rolesVictim": 0, + "handmark | namesake | unlock": 0, + "handmark | namesake | delete": 0, + "handmark | agentsAdmin | read": 3, + "handmark | agentsAdmin | create": 1, + "handmark | agentsAdmin | patchVictim": 0, + "handmark | agentsAdmin | patchTop": 0, + "handmark | agentsAdmin | patchTwin": 0, + "handmark | agentsAdmin | rolesVictim": 0, + "handmark | agentsAdmin | unlock": 1, + "handmark | agentsAdmin | delete": 1, + "handmark | ownLow | signedIn": 1, + "handmark | ownLow | read": 4, + "handmark | ownLow | create": 0, + "handmark | ownLow | patchVictim": 0, + "handmark | ownLow | patchTop": 0, + "handmark | ownLow | raiseSelf": 0, + "handmark | ownLow | rolesVictim": 0, + "handmark | ownLow | unlock": 0, + "handmark | ownLow | delete": 0, + "handmark | ownLow | ownPassword": 0, + "handmark | ownTop | signedIn": 1, + "handmark | ownTop | read": 4, + "handmark | ownTop | create": 1, + "handmark | ownTop | patchVictim": 0, + "handmark | ownTop | patchTwin": 0, + "handmark | ownTop | rolesVictim": 0, + "handmark | ownTop | unlock": 1, + "handmark | ownTop | delete": 1, + "liar | anonymous | read": 0, + "liar | anonymous | create": 0, + "liar | anonymous | patchVictim": 0, + "liar | anonymous | patchTop": 0, + "liar | anonymous | patchTwin": 0, + "liar | anonymous | rolesVictim": 0, + "liar | anonymous | unlock": 0, + "liar | anonymous | delete": 0, + "liar | customer | read": 0, + "liar | customer | create": 0, + "liar | customer | patchVictim": 0, + "liar | customer | patchTop": 0, + "liar | customer | patchTwin": 0, + "liar | customer | rolesVictim": 0, + "liar | customer | unlock": 0, + "liar | customer | delete": 0, + "liar | namesake | read": 3, + "liar | namesake | create": 0, + "liar | namesake | patchVictim": 0, + "liar | namesake | patchTop": 0, + "liar | namesake | patchTwin": 0, + "liar | namesake | rolesVictim": 0, + "liar | namesake | unlock": 0, + "liar | namesake | delete": 0, + "liar | agentsAdmin | read": 3, + "liar | agentsAdmin | create": 1, + "liar | agentsAdmin | patchVictim": 0, + "liar | agentsAdmin | patchTop": 0, + "liar | agentsAdmin | patchTwin": 0, + "liar | agentsAdmin | rolesVictim": 0, + "liar | agentsAdmin | unlock": 0, + "liar | agentsAdmin | delete": 1, + "liar | ownLow | signedIn": 1, + "liar | ownLow | read": 4, + "liar | ownLow | create": 0, + "liar | ownLow | patchVictim": 0, + "liar | ownLow | patchTop": 0, + "liar | ownLow | raiseSelf": 0, + "liar | ownLow | rolesVictim": 0, + "liar | ownLow | unlock": 0, + "liar | ownLow | delete": 0, + "liar | ownLow | ownPassword": 0, + "liar | ownTop | signedIn": 1, + "liar | ownTop | read": 4, + "liar | ownTop | create": 1, + "liar | ownTop | patchVictim": 0, + "liar | ownTop | patchTwin": 0, + "liar | ownTop | rolesVictim": 0, + "liar | ownTop | unlock": 0, + "liar | ownTop | delete": 1, + "protoop | anonymous | read": 0, + "protoop | anonymous | create": 0, + "protoop | anonymous | patchVictim": 0, + "protoop | anonymous | patchTop": 0, + "protoop | anonymous | patchTwin": 0, + "protoop | anonymous | rolesVictim": 0, + "protoop | anonymous | unlock": 0, + "protoop | anonymous | delete": 0, + "protoop | customer | read": 0, + "protoop | customer | create": 0, + "protoop | customer | patchVictim": 0, + "protoop | customer | patchTop": 0, + "protoop | customer | patchTwin": 0, + "protoop | customer | rolesVictim": 0, + "protoop | customer | unlock": 0, + "protoop | customer | delete": 0, + "protoop | namesake | read": 0, + "protoop | namesake | create": 0, + "protoop | namesake | patchVictim": 0, + "protoop | namesake | patchTop": 0, + "protoop | namesake | patchTwin": 0, + "protoop | namesake | rolesVictim": 0, + "protoop | namesake | unlock": 0, + "protoop | namesake | delete": 0, + "protoop | agentsAdmin | read": 0, + "protoop | agentsAdmin | create": 0, + "protoop | agentsAdmin | patchVictim": 1, + "protoop | agentsAdmin | patchTop": 1, + "protoop | agentsAdmin | patchTwin": 1, + "protoop | agentsAdmin | rolesVictim": 1, + "protoop | agentsAdmin | unlock": 0, + "protoop | agentsAdmin | delete": 1, + "protoop | ownLow | signedIn": 0, + "protoop | ownLow | read": 0, + "protoop | ownLow | create": 0, + "protoop | ownLow | patchVictim": 0, + "protoop | ownLow | patchTop": 0, + "protoop | ownLow | raiseSelf": 0, + "protoop | ownLow | rolesVictim": 0, + "protoop | ownLow | unlock": 0, + "protoop | ownLow | delete": 0, + "protoop | ownLow | ownPassword": 1, + "protoop | ownTop | signedIn": 0, + "protoop | ownTop | read": 0, + "protoop | ownTop | create": 0, + "protoop | ownTop | patchVictim": 1, + "protoop | ownTop | patchTwin": 1, + "protoop | ownTop | rolesVictim": 1, + "protoop | ownTop | unlock": 0, + "protoop | ownTop | delete": 1 +} diff --git a/test/secondFactorGuard.test.ts b/test/secondFactorGuard.test.ts index 6094d55..7281b40 100644 --- a/test/secondFactorGuard.test.ts +++ b/test/secondFactorGuard.test.ts @@ -512,7 +512,7 @@ describe('ipalKit and the 2FA plugin', () => { admin: { user: 'users' }, } as Config) const warnings: string[] = [] - const auth = (slug: string) => ({ slug, auth: true, custom: { ipalAccounts: true }, fields: [] }) + const auth = (slug: string) => ({ slug, auth: true, custom: { ipalAccounts: { slug, staff: true } }, fields: [] }) const payload = { collections: {}, config: { admin: { user: 'users' }, collections: [auth('partners'), auth('users')], custom: config.custom, globals: [] },