POST /api/ipal/two-factor/reset reads a text/plain body, which another origin can send without a CORS preflight; a sibling subdomain is same-site, so the browser sends the admin's SameSite=Lax cookie, and Payload's csrf list is empty without serverURL. Such a page could reset any account's TOTP and end its sessions (reproduced on SQLite, Postgres, MongoDB). Now the endpoint takes the same origin rule as verify and setup, before it reads or changes anything; twoFactor.sameOrigin: false leaves it out, and buildTwoFactorResetEndpoint takes ownOrigin for own wiring. Co-Authored-By: Claude Opus 5.5 <[email protected]>
23 lines
1.1 KiB
TypeScript
23 lines
1.1 KiB
TypeScript
/** POST /api/ipal/two-factor/reset only from the own origin (1.17.1): twoFactorResetOriginSuite.ts. */
|
|
import { describe, expect, test, vi } from 'vitest'
|
|
|
|
import { clearReportedOrigins } from '../src/modules/security/totp/sameOrigin.js'
|
|
import { SECRET_VALUE, SIBLING, site } from './twoFactorResetOriginSuite.js'
|
|
|
|
vi.mock('server-only', () => ({}))
|
|
vi.mock('next/headers.js', async () => (await import('./http/server.js')).nextHeadersMock)
|
|
|
|
describe('the 2FA reset endpoint and the origin of the request', () => {
|
|
test('a page on a sibling subdomain is refused and nothing changes; the site itself still resets', async () => {
|
|
clearReportedOrigins()
|
|
const { reset, secretOf, server } = await site()
|
|
expect((await reset(SIBLING)).status).toBe(403)
|
|
expect(await secretOf()).toBe(SECRET_VALUE)
|
|
expect((await reset({ 'sec-fetch-site': 'cross-site' })).status).toBe(403)
|
|
expect(await secretOf()).toBe(SECRET_VALUE)
|
|
const own = await reset({ origin: server.url, 'sec-fetch-site': 'same-origin' })
|
|
expect([own.status, ((await own.json()) as { ok?: boolean }).ok]).toEqual([200, true])
|
|
expect(await secretOf()).toBeNull()
|
|
})
|
|
})
|