2FA reset endpoint: only from the site's own origin (twoFactor.sameOrigin)

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]>
This commit is contained in:
Radosław Smoliński
2026-11-26 20:18:57 +01:00
co-authored by Claude Opus 5.5
parent 91770ec17f
commit 6ca0730c08
9 changed files with 122 additions and 5 deletions
+15
View File
@@ -0,0 +1,15 @@
/** twoFactor.sameOrigin: false leaves the origin check of the 2FA reset endpoint out (twoFactorResetOriginSuite.ts). */
import { describe, expect, test, vi } from 'vitest'
import { 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 with sameOrigin: false', () => {
test('a request from a sibling subdomain is taken, as before 1.17.1', async () => {
const { reset, secretOf } = await site(false)
expect((await reset(SIBLING)).status).toBe(200)
expect(await secretOf()).toBeNull()
})
})