Security: mandatory Turnstile when configured, admin-only test email, roles on create, safer client IP
- Turnstile is on only when both keys are set (panel or env); then submitForm requires a valid token, so a bot can no longer skip the check by omitting it. Not configured -> no widget, no check. New getTurnstileConfig() for layouts. - /api/ipal/test-email now requires the admin role (403 for other users). - roles field: create access is admin-only, so open sign-up can't self-assign admin. - clientIp reads X-Forwarded-For from the right, accepts Headers, can be pinned via option or IPAL_IP_HEADER; exposed on search/MCP routes. - Pluggable shared rate-limit store (setRateLimitStore) for multi-instance setups. - Replace the template int.spec with real unit tests in test/ (44 tests). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
'use server'
|
||||
import { headers } from 'next/headers'
|
||||
import { submitForm } from '@intecion/ipal-kit/server'
|
||||
import { isHoneypotTripped, HONEYPOT_FIELD, getNotificationTexts, resolveFormMessage } from '@intecion/ipal-kit'
|
||||
import { clientIp, isHoneypotTripped, HONEYPOT_FIELD, getNotificationTexts, resolveFormMessage } from '@intecion/ipal-kit'
|
||||
import { getCachedPayload } from '@/lib/content'
|
||||
|
||||
export async function sendForm(
|
||||
@@ -15,8 +15,7 @@ export async function sendForm(
|
||||
const texts = (await getNotificationTexts({ payload, locale })).form
|
||||
if (isHoneypotTripped(values)) return { success: true, message: texts.success } // bot: fake success, nothing stored
|
||||
const { [HONEYPOT_FIELD]: _hp, ...data } = values
|
||||
const h = await headers() // fine in a server action — never in the page tree (breaks SSG)
|
||||
const ip = h.get('cf-connecting-ip') ?? h.get('x-forwarded-for')?.split(',')[0]?.trim() ?? undefined
|
||||
const ip = clientIp(await headers()) || undefined // headers(): fine in a server action — never in the page tree (breaks SSG)
|
||||
const result = await submitForm({ payload, formId, data, turnstileToken, ip })
|
||||
return { success: result.success, message: resolveFormMessage(result, texts) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user