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:
co-authored by
Claude Fable 5.2
parent
75a6f5209e
commit
01e3813723
@@ -414,6 +414,13 @@ describe('ipalKit and the 2FA plugin', () => {
|
||||
expect(() => resolveRequireSetup({ windowHours: windowHours as never })).toThrow(/windowHours/)
|
||||
})
|
||||
|
||||
test('requireSetup: null is the default, like leaving it out', async () => {
|
||||
const config = await ipalKit({ i18n, twoFactor: { issuer: 'A', plugin: fakeTotp as never, requireSetup: null as never } })({ collections: [], secret: 'x' } as unknown as Config)
|
||||
expect((config.custom as { ipal: { twoFactor: Record<string, unknown> } }).ipal.twoFactor).toMatchObject({ requireSetup: true, setupWindowMs: 72 * 3_600_000 })
|
||||
expect(JSON.stringify(config.admin?.components?.beforeDashboard)).toContain('TwoFactorAlert')
|
||||
expect(resolveRequireSetup(null as never)).toEqual({ requireSetup: true, setupWindowMs: 72 * 3_600_000 })
|
||||
})
|
||||
|
||||
test('windowHours: a number, 0 or false still work', () => {
|
||||
expect(resolveRequireSetup({ windowHours: 1.5 }).setupWindowMs).toBe(1.5 * 3_600_000)
|
||||
expect(resolveRequireSetup({ windowHours: 0 }).setupWindowMs).toBe(0)
|
||||
@@ -483,10 +490,13 @@ describe('ipalKit and the 2FA plugin', () => {
|
||||
const sqlite = fake('sqlite', 'no such column: totp_setup_from')
|
||||
await backfillSetupFrom(sqlite.payload as never, 'users')
|
||||
expect(sqlite.logger.error).toHaveBeenCalledTimes(1)
|
||||
const mongo = fake('mongoose', 'connection lost')
|
||||
await backfillSetupFrom(mongo.payload as never, 'users')
|
||||
expect(mongo.logger.error).not.toHaveBeenCalled()
|
||||
expect(mongo.logger.warn).toHaveBeenCalledTimes(1)
|
||||
// any other failure — also on a SQL adapter — is not "the column is missing"
|
||||
for (const other of [fake('mongoose', 'connection lost'), fake('postgres', 'connect ECONNREFUSED 127.0.0.1:5432'), fake('sqlite', 'database is locked'), fake('postgres', 'relation "users" does not exist')]) {
|
||||
await backfillSetupFrom(other.payload as never, 'users')
|
||||
expect(other.logger.error).not.toHaveBeenCalled()
|
||||
expect(other.logger.warn).toHaveBeenCalledTimes(1)
|
||||
}
|
||||
expect(String(pg.logger.error.mock.calls[0]?.[0])).toMatch(/prodMigrations.*not in a pre-deployment command/s)
|
||||
})
|
||||
|
||||
// The reset removes a second factor: by default only a session that entered its own TOTP code may do it.
|
||||
|
||||
Reference in New Issue
Block a user