2FA setup required: review round 2 — no SVG from the icon endpoint, migrations at container start

R2-1: /api/ipal/admin-icon answers with bytes only for a bitmap recognised by its
first bytes (PNG, JPEG, GIF, WebP, ICO, AVIF). An SVG favicon keeps the redirect
to the media file: a site-wide CSP rule overrides a route's own sandbox header,
so the header alone protected nothing in a built site. buildUploadSecurityHeaders
also returns a rule for the icon path, as a second layer.
R2-2: the SQL migration runs when the new container starts (prodMigrations, or
the start command), never in Coolify's pre-deployment command; docs and the log
line say so and point to deployment.md 4.3.
R2-3: requireSetup: null is the default. R2-4: the missing-column log line only
for a column error. R2-5, R2-6: the resetAccess example keeps the code check;
with guard: false the reset endpoint does not exist.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-24 20:18:47 +01:00
co-authored by Claude Fable 5.2
parent 75a6f5209e
commit 01e3813723
20 changed files with 155 additions and 53 deletions
+16 -2
View File
@@ -157,11 +157,25 @@ export function buildSecurityHeaders(args: BuildSecurityHeadersArgs = {}): Secur
* ]
* }
*/
export function buildUploadSecurityHeaders({ collections = ['media'] }: { collections?: string[] } = {}): {
export function buildUploadSecurityHeaders({
adminIcon = '/api/ipal/admin-icon',
collections = ['media'],
}: {
/**
* Path of the plugin's panel icon endpoint, which answers with the favicon's bytes. It only ever
* answers with a bitmap; the rule is a second layer. Another API route: `'/cms-api/ipal/admin-icon'`;
* `false` = no rule.
*/
adminIcon?: false | string
collections?: string[]
} = {}): {
headers: SecurityHeader[]
source: string
}[] {
return collections.map((slug) => ({ headers: [...UPLOAD_SECURITY_HEADERS], source: `/api/${slug}/file/:path*` }))
return [
...collections.map((slug) => ({ headers: [...UPLOAD_SECURITY_HEADERS], source: `/api/${slug}/file/:path*` })),
...(adminIcon ? [{ headers: [...UPLOAD_SECURITY_HEADERS], source: adminIcon }] : []),
]
}
/**
+7 -6
View File
@@ -195,14 +195,15 @@ export async function backfillSetupFrom(payload: BasePayload, collection: string
return totalDocs
} catch (err) {
const reason = err instanceof Error ? err.message : String(err)
// On Postgres / SQLite this is the missing column — and then it is not only this step that fails:
// every query on the collection selects the column, so EVERY login answers 500 until it exists.
const adapter = (payload.db as { name?: unknown } | undefined)?.name
if (/postgres|sqlite/i.test(typeof adapter === 'string' ? adapter : '') || /column|no such/i.test(reason)) {
// On Postgres / SQLite without the migration the column is missing — and then it is not only this step
// that fails: every query on the collection selects the column, so EVERY login answers 500 until it exists.
// Only the missing column gets this message — a database that cannot be reached is another problem.
if (/column .+ does not exist|no such column|unknown column|has no column/i.test(reason)) {
payload.logger.error(
`[ipal] 2FA: the column for "${SETUP_FROM_FIELD}" is missing on "${collection}" (${reason}). NOBODY CAN LOG IN to the panel until the ` +
'migration that adds it has run — administrators with 2FA included. Run `pnpm payload migrate:create`, commit the migration and ' +
'run it (`pnpm payload migrate`) before this version serves requests (docs/security.md "Setup required" → Data).',
'migration that adds it has run — administrators with 2FA included. Run `pnpm payload migrate:create`, commit the migration, and ' +
'have it applied when the new container starts (`prodMigrations` in the database adapter, or `pnpm payload migrate && pnpm start`) — ' +
'not in a pre-deployment command, which runs in the old container (docs/deployment.md §4.3, docs/security.md "Setup required" → Data).',
)
} else {
payload.logger.warn(`[ipal] 2FA: could not start the setup window for existing accounts (${reason}).`)