From 963b8c127d2e06f326ae194550e2b7308e5bc0f1 Mon Sep 17 00:00:00 2001 From: Benno Tielen Date: Fri, 20 Feb 2026 10:37:45 +0100 Subject: [PATCH] fix: spam --- src/utils/actions.ts | 8 ++++---- src/utils/detectSpam.ts | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/utils/actions.ts b/src/utils/actions.ts index a6a0cf0..4035815 100644 --- a/src/utils/actions.ts +++ b/src/utils/actions.ts @@ -14,10 +14,10 @@ import { isSpam } from '@/utils/detectSpam' export async function send(toEmail: string, prevState: any, formData: FormData) { const schema = z.object({ - email: z.string().email(), - subject: z.string(), - name: z.string(), - message: z.string() + email: z.email().max(100), + subject: z.string().max(150), + name: z.string().max(100), + message: z.string().max(3000).min(30) }); const validatedFields = schema.safeParse({ diff --git a/src/utils/detectSpam.ts b/src/utils/detectSpam.ts index 26e7b35..d1c721c 100644 --- a/src/utils/detectSpam.ts +++ b/src/utils/detectSpam.ts @@ -15,18 +15,19 @@ const lngDetector = new LanguageDetect(); */ export const isSpam = (message: string): boolean => { + const trimmed = message.trim(); + if (trimmed.length < 10 || trimmed.split(/\s+/).length < 5) { + return true; + } + if (message.includes('dreikoenige.berlin')) { return true; } if (message.includes('https://') || message.includes('http://') || message.includes('$') || message.includes('www')) { - const language = lngDetector.detect(message)[0][0]; + const language = lngDetector.detect(message.substring(0, 400))[0][0]; return language !== 'german'; } - if (message.split(" ").length < 5) { - return true - } - return false; } \ No newline at end of file