Turnstile docs: limit before asking Cloudflare; test and lint fixes
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6ca0730c08
commit
b2fed3bf90
+1
-1
@@ -262,5 +262,5 @@ full control or have an unusual case. The provider is a convenience layer over i
|
||||
- **Access to the keys:** Site integrations is admin-only (read and update); change it with
|
||||
`iapl({ globalOverrides: { 'site-integrations': { access: … } } })` — keep `read` restricted, the secret lives there.
|
||||
- **Look:** `theme` on `<Turnstile>` / `<TurnstileWidget theme>`, `turnstileTheme` in `RenderForm` / `BuilderForm`.
|
||||
- **Your own integration:** `checkTurnstile` (full `pass` / `reject` / `degraded` classification),
|
||||
- **Your own integration:** limit first, then ask Cloudflare — `consumeRateLimit({ key: clientIp(req), scope: 'signup' })` before `checkTurnstile`, so a flood of posts does not become a flood of requests to Cloudflare (the plugin's forms do it in this order: `passRateLimit`, then `passTurnstile`). `checkTurnstile` (full `pass` / `reject` / `degraded` classification),
|
||||
`verifyTurnstile`, `getTurnstileConfig`, `<Turnstile>`, `useTurnstile` / `useOptionalTurnstile`.
|
||||
|
||||
@@ -382,11 +382,6 @@ export type TotpEndpointGuards = {
|
||||
* it. Return a Response to refuse (too many attempts), null to let it through.
|
||||
*/
|
||||
limitVerify?: (req: never) => null | Promise<null | Response> | Response
|
||||
/**
|
||||
* Called after a verify attempt that `limitVerify` let through: `correct` is true when the package
|
||||
* answered `{ ok: true }`. The plugin's limit gives a right code's place back (buildVerifyLimit `settle`).
|
||||
*/
|
||||
settleVerify?: (req: never, correct: boolean) => Promise<void> | void
|
||||
/** The answer for an account whose setup window has passed (in the caller's language). Default: a plain 403. */
|
||||
onSetupClosed?: (req: never) => Response
|
||||
/**
|
||||
@@ -394,6 +389,11 @@ export type TotpEndpointGuards = {
|
||||
* (sameOrigin.ts). False = refused, and NOT counted against the verify limit.
|
||||
*/
|
||||
ownOrigin?: (req: never) => boolean
|
||||
/**
|
||||
* Called after a verify attempt that `limitVerify` let through: `correct` is true when the package
|
||||
* answered `{ ok: true }`. The plugin's limit gives a right code's place back (buildVerifyLimit `settle`).
|
||||
*/
|
||||
settleVerify?: (req: never, correct: boolean) => Promise<void> | void
|
||||
}
|
||||
|
||||
export function guardTotpEndpoint<T extends EndpointLike>(endpoint: T, collection: string, guards: TotpEndpointGuards = {}): T {
|
||||
|
||||
@@ -72,14 +72,14 @@ describe('exempt from 2FA setup: by an admin-only field, not by e-mail', () => {
|
||||
const rest = await call(`/users/${editorId}`, { body: JSON.stringify({ serviceAccount: true }), method: 'PATCH' })
|
||||
expect(rest.status).toBe(200)
|
||||
await call('/graphql', { body: JSON.stringify({ query: `mutation { updateUser(id: ${JSON.stringify(editorId)}, data: { serviceAccount: true }) { id } }` }), method: 'POST' })
|
||||
const stored = (await payload.findByID({ id: editorId, collection: 'users' as never, overrideAccess: true })) as { serviceAccount?: boolean }
|
||||
const stored = (await payload.findByID({ id: editorId, collection: 'users' as never, overrideAccess: true })) as unknown as { serviceAccount?: boolean }
|
||||
expect(stored.serviceAccount).toBe(false)
|
||||
})
|
||||
|
||||
test('…while the same editor can change its own e-mail to anything: an e-mail list is no boundary', async () => {
|
||||
const res = await call(`/users/${editorId}`, { body: JSON.stringify({ email: '[email protected]' }), method: 'PATCH' })
|
||||
expect(res.status).toBe(200)
|
||||
const stored = (await payload.findByID({ id: editorId, collection: 'users' as never, overrideAccess: true })) as { email: string }
|
||||
const stored = (await payload.findByID({ id: editorId, collection: 'users' as never, overrideAccess: true })) as unknown as { email: string }
|
||||
expect(stored.email).toBe('[email protected]')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -13,7 +13,6 @@ import { lexicalEditor } from '@payloadcms/richtext-lexical'
|
||||
import { getPayload } from 'payload'
|
||||
import { afterAll } from 'vitest'
|
||||
|
||||
import { clearReportedOrigins } from '../src/modules/security/totp/sameOrigin.js'
|
||||
import { iapl } from '../src/plugin.js'
|
||||
import { buildTestConfig } from './helpers.js'
|
||||
import { testDatabase } from './http/db.js'
|
||||
|
||||
Reference in New Issue
Block a user