M1 review: account rules before 2FA, the SMTP password stays with its server, the rest of the findings
M1-1 the first-user route is the plugin's own endpoint in front of Payload's; nothing is read from the path.
M1-2 the account rules are put on the collections before the 2FA package wraps them.
M1-6 the admin rule only where the roles are the plugin's; other staff collections: an account of that collection.
update / delete get the matching defaults (accounts.adminOnlyWrite); doctor rule staff-accounts-open.
M1-5 access.firstUserAdmin: false with a role below the panel role: the default panel role steps aside, an explicit one is refused.
M1-3 a save that changes the SMTP server, port, user or encryption must send the password again (secrets.reenterOnChange);
new panel field smtpRequireTls.
M1-4 a restore of a version masks the secrets (maskSecretsOnRestore).
M1-7 a refused origin is logged once with the ways to allow it; default ports are normalised.
Minors: m1 day boundary, m3 e-mail check on reset and bulk update, m4 text of 'all', m5 the mask is never kept.
The account suite runs with 2FA off and on.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
81cee02e78
commit
1141c749de
+52
-6
@@ -15,7 +15,8 @@ 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, resolvePasswordRule } from './modules/access/passwordRule.js'
|
||||
import { applyAdminOnlyCreate, applyFirstUserRoute } from './modules/access/selfRegistration.js'
|
||||
import { applyFirstUserRoute, applyStaffAccountAccess } 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'
|
||||
import { buildAdminMeta, DEFAULT_AGENCY, syncAdminMeta } from './modules/branding/adminMeta.js'
|
||||
@@ -40,7 +41,7 @@ import { serverText } from './modules/integrations/texts.js'
|
||||
import { buildSystemPagesFields } from './modules/pages/index.js'
|
||||
import { missingImportMapEntries } from './modules/security/totp/importMapCheck.js'
|
||||
import { changedViewKeys, copyViews, SAFE_TOTP_VIEW, wrapTotpViews } from './modules/security/totp/safeBack.js'
|
||||
import { requestFromOwnOrigin } from './modules/security/totp/sameOrigin.js'
|
||||
import { reportRefusedOrigin, requestFromOwnOrigin } from './modules/security/totp/sameOrigin.js'
|
||||
import {
|
||||
buildGuardStrategy,
|
||||
ensurePayloadGuarded,
|
||||
@@ -201,11 +202,25 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
let setupWindowHours = 0
|
||||
/** accounts.panelRole in force: the collection and the role, for the start-up line. */
|
||||
let panelRoleFor: { role: Role; slug: string } | null = null
|
||||
/** Why the default panel role was not applied (said once at start). */
|
||||
let panelRoleSkipped: null | string = null
|
||||
/** `accounts: false` turns every account rule off. */
|
||||
const accounts: AccountsOptions | null = options.accounts === false ? null : (options.accounts ?? {})
|
||||
/** requireSetup.setupNotice / statusField (on unless switched off). */
|
||||
let setupNotice = true
|
||||
let statusField = false
|
||||
// Account rules (accounts.*): nobody creates an account for themselves, or takes one over.
|
||||
// BEFORE the 2FA package: it gives every collection a create / update / delete function of
|
||||
// its own, and afterwards a missing rule cannot be told from one the project wrote.
|
||||
if (accounts) {
|
||||
const panelSlug = config.admin?.user ?? (config.collections ?? []).find((c) => c.auth)?.slug
|
||||
const staffSlugs = [...new Set([panelSlug, options.access?.authCollection, ...(options.access?.staffCollections ?? [])].filter((s): s is string => Boolean(s)))]
|
||||
config = applyStaffAccountAccess(config, staffSlugs, {
|
||||
create: accounts.adminOnlyCreate !== false,
|
||||
pluginRoles: options.access?.authCollection ? [options.access.authCollection] : [],
|
||||
write: accounts.adminOnlyWrite !== false,
|
||||
})
|
||||
}
|
||||
if (options.twoFactor !== false) {
|
||||
const tf = options.twoFactor
|
||||
if (!tf?.issuer) {
|
||||
@@ -277,7 +292,15 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
const extraOrigins = typeof tf.sameOrigin === 'object' ? (tf.sameOrigin.origins ?? []) : []
|
||||
const guards = {
|
||||
...(limitVerify ? { limitVerify: (req: PayloadRequest) => limitVerify(req) } : {}),
|
||||
...(tf.sameOrigin === false ? {} : { ownOrigin: (req: PayloadRequest) => requestFromOwnOrigin(req as never, extraOrigins) }),
|
||||
...(tf.sameOrigin === false
|
||||
? {}
|
||||
: {
|
||||
ownOrigin: (req: PayloadRequest) => {
|
||||
if (requestFromOwnOrigin(req as never, extraOrigins)) {return true}
|
||||
reportRefusedOrigin(req as never, extraOrigins) // never in silence: once per origin, with the ways to allow it
|
||||
return false
|
||||
},
|
||||
}),
|
||||
onSetupClosed: (req: PayloadRequest) =>
|
||||
Response.json({ message: serverText(req.i18n as never, 'twoFactorSetupClosed'), ok: false }, { status: 403 }),
|
||||
}
|
||||
@@ -562,8 +585,22 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
const staff = [...new Set([options.access.authCollection, ...(options.access.staffCollections ?? [])])]
|
||||
config.custom = { ...config.custom, ipal: { ...config.custom?.ipal, staffCollections: staff } }
|
||||
// Account rules (accounts.*): the lowest role stays out of the panel.
|
||||
const panelRole = accounts ? resolvePanelRole(accounts.panelRole) : null
|
||||
let panelRole = accounts ? resolvePanelRole(accounts.panelRole) : null
|
||||
const rolesSlug = options.access.authCollection
|
||||
// With firstUserAdmin: false the first account gets the default role. Below the panel
|
||||
// role, a fresh site would have nobody who can open the panel — and nobody to raise a role.
|
||||
const firstRole = options.access.defaultRole ?? 'user'
|
||||
if (panelRole && options.access.firstUserAdmin === false && ROLE_HIERARCHY.indexOf(firstRole) < ROLE_HIERARCHY.indexOf(panelRole)) {
|
||||
if (accounts?.panelRole !== undefined) {
|
||||
throw new Error(
|
||||
`[ipal] access.firstUserAdmin: false with accounts.panelRole: '${panelRole}' leaves a fresh site with nobody who can open the panel: ` +
|
||||
`the first account gets the role '${firstRole}', which is below the panel role. Set access.defaultRole to '${panelRole}' or higher, ` +
|
||||
"or accounts: { panelRole: false }, or drop access.firstUserAdmin: false (docs/access.md \"Account rules\").",
|
||||
)
|
||||
}
|
||||
panelRoleSkipped = `access.firstUserAdmin is false and the first account gets the role '${firstRole}'`
|
||||
panelRole = null
|
||||
}
|
||||
// the project's own access.admin (or access.authAccess.admin) wins
|
||||
if (panelRole && !(config.collections ?? []).find((c) => c.slug === rolesSlug)?.access?.admin) {
|
||||
config = applyPanelRole(config, rolesSlug, panelRole)
|
||||
@@ -574,7 +611,6 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
if (accounts) {
|
||||
const panelSlug = config.admin?.user ?? (config.collections ?? []).find((c) => c.auth)?.slug
|
||||
const staffSlugs = [...new Set([panelSlug, options.access?.authCollection, ...(options.access?.staffCollections ?? [])].filter((s): s is string => Boolean(s)))]
|
||||
if (accounts.adminOnlyCreate !== false) {config = applyAdminOnlyCreate(config, staffSlugs)}
|
||||
config = applyFirstUserRoute(config, accounts.firstUserRoute)
|
||||
const passwordRule = resolvePasswordRule(accounts.password)
|
||||
if (passwordRule) {config = applyPasswordRule(config, staffSlugs, passwordRule)}
|
||||
@@ -645,7 +681,11 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
: { searchFields: typeof searchSettings === 'function' ? searchSettings(searchSettingsFields) : searchSettingsFields }),
|
||||
systemPageFields,
|
||||
}),
|
||||
buildSiteIntegrations({ additionalFields: options.integrationsFields, writeOnlySecrets: options.secrets?.writeOnly !== false }),
|
||||
buildSiteIntegrations({
|
||||
additionalFields: options.integrationsFields,
|
||||
reenterSecretOnChange: options.secrets?.reenterOnChange !== false,
|
||||
writeOnlySecrets: options.secrets?.writeOnly !== false,
|
||||
}),
|
||||
withFillLocales('global', buildCookieSettings(), fillLocales['cookie-settings']),
|
||||
buildNotifications({ lightbox: options.lightbox === true }),
|
||||
]
|
||||
@@ -864,6 +904,12 @@ export const ipalKit = (options: IpalOptions): Plugin => {
|
||||
)
|
||||
}
|
||||
}
|
||||
if (panelRoleSkipped) {
|
||||
payload.logger.warn(
|
||||
`[ipal] The panel role (accounts.panelRole, 'editor' by default) is NOT applied: ${panelRoleSkipped}, so nobody could open the panel on a fresh site. ` +
|
||||
'Every account of the login collection can open the panel. To keep the lowest role out, set access.defaultRole to \'editor\' or drop access.firstUserAdmin: false (docs/access.md "Account rules").',
|
||||
)
|
||||
}
|
||||
// The panel role: tell a site how many of its accounts the rule keeps out of the panel.
|
||||
if (panelRoleFor) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user