Fixed turnstile

This commit is contained in:
2026-10-15 15:27:43 +02:00
parent 7ef7927e38
commit 3bab8a0697
58 changed files with 1182 additions and 322 deletions
+7 -1
View File
@@ -18,6 +18,12 @@ export type SubmitFormArgs = {
*/
maxPerMinute?: number;
payload: BasePayload;
/**
* Turnstile can't be verified because of OUR side (missing/wrong secret,
* Cloudflare unreachable): 'allow' (default) accepts the submission and shows
* the problem in the panel; 'reject' refuses it.
*/
turnstileOnConfigError?: 'allow' | 'reject';
/** Turnstile token; when present it is verified, when absent it is skipped. */
turnstileToken?: string;
};
@@ -80,4 +86,4 @@ export type SubmitFormResult = {
*
* server-only: touches the Turnstile secret.
*/
export declare function submitForm({ consentFieldName, data, formId, ip, maxPerMinute, payload, turnstileToken, }: SubmitFormArgs): Promise<SubmitFormResult>;
export declare function submitForm({ consentFieldName, data, formId, ip, maxPerMinute, payload, turnstileOnConfigError, turnstileToken, }: SubmitFormArgs): Promise<SubmitFormResult>;
+2 -1
View File
@@ -14,7 +14,7 @@ import { validateSubmission } from './validateSubmission.js';
* which goes out over the configured email adapter (mailAdapter). Storing the submission is enough.
*
* server-only: touches the Turnstile secret.
*/ export async function submitForm({ consentFieldName, data, formId, ip, maxPerMinute = 5, payload, turnstileToken }) {
*/ export async function submitForm({ consentFieldName, data, formId, ip, maxPerMinute = 5, payload, turnstileOnConfigError = 'allow', turnstileToken }) {
// 1. Rate limit — cheapest gate, drops a flood before any real work.
if (maxPerMinute > 0 && ip) {
if (!checkRateLimit({
@@ -31,6 +31,7 @@ import { validateSubmission } from './validateSubmission.js';
if (turnstileToken !== undefined) {
const ok = await verifyTurnstile({
ip,
onConfigError: turnstileOnConfigError,
payload,
token: turnstileToken
});
File diff suppressed because one or more lines are too long