M1 review round 2: the transport is no way round, nobody raises its own role, late staff collections

R2-1 the SMTP password is bound to server, port and user whatever the transport says; the transport alone is not bound.
R2-2 where the plugin's update rule is in force the roles field is closed for the account itself
     (the plugin's roles: only an admin; roles of the project's own: never one's own).
R2-3 auth collections a later plugin adds get the account rules, the password rule and the first-user endpoint when
     the config goes live; a staff slug that is not an auth collection stops the start.
R2-4 smtpRequireTls is taken out: the branch adds no field, column or collection.
Also: read (a staff account) and unlock (an admin) defaults on staff collections (accounts.staffOnlyRead);
doctor staff-own-roles and read / unlock in staff-accounts-open; r1 NULL against the default, also inside a row;
r2 bound values compared exactly.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 00:39:24 +01:00
co-authored by Claude Fable 5.2
parent a32329fbb4
commit 7002ebbfa6
20 changed files with 519 additions and 122 deletions
+24 -3
View File
@@ -191,16 +191,37 @@ export const securityRules: DoctorRule[] = [
check: (ctx) =>
(ctx.deep?.staffOpenToOthers ?? []).map((entry) => {
const [slug, operation] = entry.split(':')
const what: Record<string, string> = {
create: ': it can make itself a staff account',
read: ': it can list the staff accounts (addresses, roles)',
unlock: ': it can lift the lock after failed logins, which helps guessing a password',
update: ": it can change a staff account's password",
}
const option = operation === 'create' ? 'adminOnlyCreate' : operation === 'read' ? 'staffOnlyRead' : 'adminOnlyWrite'
return {
fix: `give "${slug}" an access.${operation} rule that asks for a staff account (staffCreateAccess, staffUpdateAccess('${slug}'), adminOrSelfIn('${slug}')), or drop accounts: false / accounts.adminOnly${operation === 'create' ? 'Create' : 'Write'}: false`,
message: `an account of another auth collection may ${operation} in the staff collection "${slug}"${operation === 'create' ? ': it can make itself a staff account' : operation === 'update' ? ": it can change a staff account's password" : ''}`,
severity: 'error' as const,
fix: `give "${slug}" an access.${operation} rule that asks for a staff account (staffCreateAccess, staffUpdateAccess('${slug}'), staffReadAccess, adminOrSelfIn('${slug}')), or drop accounts: false / accounts.${option}: false`,
message: `an account of another auth collection may ${operation} in the staff collection "${slug}"${what[operation] ?? ''}`,
severity: operation === 'read' ? ('warning' as const) : ('error' as const),
}
}),
docs: 'docs/access.md',
group: 'security',
source: 'deep',
},
{
// A staff collection with role values of its own on the plugin's default rules: the plugin cannot rank
// those roles, so inside the collection every account may create an account with any role.
id: 'staff-own-roles',
check: (ctx) =>
(ctx.deep?.staffOnOwnRoles ?? []).map((slug) => ({
fix: `write "${slug}"'s own access.create / update / delete rules (and field access on its roles field) from its own roles`,
message: `the staff collection "${slug}" has role values of its own and no access rules: accounts of other collections are kept out, but inside it every account may create, change and delete accounts, with any role`,
severity: 'warning' as const,
})),
docs: 'docs/access.md',
group: 'security',
source: 'deep',
},
{
// Turnstile lets submissions through while it is misconfigured or Cloudflare fails ("degraded") — visible here.
id: 'turnstile-degraded',
+8 -2
View File
@@ -5,7 +5,7 @@ import { readFileSync } from 'node:fs'
import type { DoctorStatus } from './types.js'
import { openSignUpCollections, staffCollectionsOpenToOthers } from '../access/selfRegistration.js'
import { openSignUpCollections, staffCollectionsOnOwnRoles, staffCollectionsOpenToOthers } from '../access/selfRegistration.js'
import { countPendingCookies } from '../consent/scanner/approval.js'
import { COOKIE_REVIEW_SLUG } from '../consent/scanner/collection.js'
import { secondFactorPassed, SETUP_FROM_FIELD } from '../security/totp/secondFactor.js'
@@ -74,7 +74,13 @@ export async function collectDoctorStatus(payload: BasePayload): Promise<DoctorS
} catch {
staffOpenToOthers = null
}
return { node: process.version, openSignUp, pendingCookies, plugin: pluginVersion(), staffOpenToOthers, turnstile, turnstileSecretFromEnv: secretFromEnv, usersSetupClosed, usersWithout2fa }
let staffOnOwnRoles: null | string[] = null
try {
staffOnOwnRoles = staffCollectionsOnOwnRoles(payload as never)
} catch {
staffOnOwnRoles = null
}
return { node: process.version, openSignUp, pendingCookies, plugin: pluginVersion(), staffOnOwnRoles, staffOpenToOthers, turnstile, turnstileSecretFromEnv: secretFromEnv, usersSetupClosed, usersWithout2fa }
}
export type DoctorEndpointOptions = {
+7 -2
View File
@@ -66,8 +66,13 @@ export type DoctorStatus = {
pendingCookies?: null | number
plugin?: string
/**
* Staff collections an account of ANOTHER, non-staff auth collection may create in, update or
* delete from: `'users:update'`. Slugs and operations only.
* Staff collections with role values of their own that run on the plugin's default account rules:
* inside them every account may create, change and delete accounts. Slugs only.
*/
staffOnOwnRoles?: null | string[]
/**
* Staff collections an account of ANOTHER, non-staff auth collection may create in, read, update,
* delete from or unlock: `'users:update'`. Slugs and operations only.
*/
staffOpenToOthers?: null | string[]
/** The Turnstile integration's recorded state (Site integrations): never a key, only the state. null = not known. */