Rate limit: no IP shares a capped bucket; optional Turnstile hostname check

A request without a usable client IP used to skip every limiter. It now
counts against one shared 'unknown-ip' bucket at 20x the limit. submitForm,
createSubmitAction and verifyTurnstile accept turnstileHostnames/hostnames
to reject tokens solved on another domain.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-22 16:59:51 +02:00
co-authored by Claude Opus 5.5
parent 10da62ea4c
commit 8e10232765
8 changed files with 86 additions and 14 deletions
+12
View File
@@ -19,6 +19,13 @@ type IntegrationsWithTurnstile = {
}
type VerifyTurnstileArgs = {
/**
* Hostnames the token must have been solved on (siteverify's `hostname`), e.g.
* ['www.example.com', 'example.com']. Unset = not checked. Guards against a
* token solved on another site that shares the widget (a sitekey allowing any
* hostname). Cloudflare's test keys report 'example.com' — leave unset in dev.
*/
hostnames?: string[]
/** Client IP. Sent to Cloudflare only with `sendRemoteIp: true`. */
ip?: string
/**
@@ -73,6 +80,7 @@ const PLUGIN_ERRORS: Record<string, string> = {
* SiteIntegrations is updated (throttled) so the panel shows failures.
*/
export async function checkTurnstile({
hostnames,
ip,
payload,
sendRemoteIp = false,
@@ -112,6 +120,10 @@ export async function checkTurnstile({
if (typeof data?.success !== 'boolean') {return degraded('bad-response')}
if (data.success) {
if (hostnames?.length && !hostnames.some((h) => h.toLowerCase() === data.hostname?.toLowerCase())) {
console.warn(`[ipal] Turnstile rejected: token solved on "${data.hostname ?? '?'}", expected ${hostnames.join(', ')}`)
return { code: 'hostname-mismatch', outcome: 'reject' }
}
await recordIntegrationStatus(payload, STATUS_FIELD, previous, { state: 'ok' })
return { outcome: 'pass' }
}