Skip to content

Beautiful Open-Source Form Builder

Enhance spam checking logic and logging in FormSpamService

Julien Nahum1e36a87a395d
diff --git a/api/app/Service/AI/Prompts/Form/CheckSpamFormPrompt.php b/api/app/Service/AI/Prompts/Form/CheckSpamFormPrompt.php
index 49968043e..1f81a7578 100644
--- a/api/app/Service/AI/Prompts/Form/CheckSpamFormPrompt.php
+++ b/api/app/Service/AI/Prompts/Form/CheckSpamFormPrompt.php
@@ -13,7 +13,7 @@ class CheckSpamFormPrompt extends Prompt
protected string $model = 'gpt-4.1-mini';
public const PROMPT_TEMPLATE = <<<'EOD'
- Analyze this form for spam/phishing. Be CONSERVATIVE - only block obvious threats.
+ Analyze this form for spam/phishing. Focus on CONTENT RISK, not user characteristics.
<formContent>
{formContent}
@@ -30,20 +30,29 @@ class CheckSpamFormPrompt extends Prompt
- Forms asking for existing passwords/credentials to "verify" accounts or for fake login
- Clear brand impersonation with sensitive data collection
- **FLAG FOR ADMIN REVIEW (needs_admin_review: true):**
- - New users with vague titles but no clear phishing intent
- - Basic info collection (email/phone) without passwords
- - Borderline suspicious but possibly legitimate testing
-
- **ALLOW (both false):**
+ **FLAG FOR ADMIN REVIEW (needs_admin_review: true) - RARE CASES ONLY:**
+ - Forms with suspicious brand impersonation but unclear intent
+ - Requests for highly sensitive data (SSN, banking details) without clear business purpose
+ - Forms that appear to be testing system vulnerabilities
+
+ **ALLOW (both false) - DEFAULT FOR MOST FORMS:**
+ - Business inquiry forms, contact forms, surveys
+ - Forms in any language (Arabic, Spanish, etc. are legitimate)
+ - Forms from new users (being new is NOT suspicious)
+ - Adult content related forms (unless clearly illegal)
+ - Vague or simple forms (common for legitimate use cases)
- New account creation forms (password setup normal)
- Surveys, event codes, referral forms
- General contact/support forms
- **KEY RULES:**
+ **IMPORTANT GUIDELINES:**
+ - User age/registration date is NOT a spam indicator
+ - Non-English content is NOT suspicious
+ - Adult content is acceptable unless clearly illegal
+ - Vague titles are common and legitimate
- Login forms = phishing, Registration forms = often legitimate
- Subscribed users get benefit of doubt
- - When uncertain, prefer admin review over blocking
+ - When uncertain, prefer allowing over flagging
Classify as: SPAM (block), ADMIN REVIEW (flag), or LEGITIMATE (allow).
Respond with JSON: {"is_spam": boolean, "needs_admin_review": boolean, "reason": "explanation"}
diff --git a/api/app/Service/Forms/FormSpamService.php b/api/app/Service/Forms/FormSpamService.php
index 333c62e9c..974e6c0d5 100644
--- a/api/app/Service/Forms/FormSpamService.php
+++ b/api/app/Service/Forms/FormSpamService.php
@@ -6,6 +6,7 @@ use App\Models\Forms\Form;
use App\Models\User;
use App\Service\AI\Prompts\Form\CheckSpamFormPrompt;
use App\Service\UserActionService;
+use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
class FormSpamService
@@ -77,6 +78,20 @@ class FormSpamService
private function logAdminReview(Form $form, string $reason): void
{
+ $cacheKey = "form_admin_review_flagged_{$form->id}";
+
+ // Check if we've already flagged this form in the last 24 hours
+ if (Cache::has($cacheKey)) {
+ Log::info('Skipping duplicate admin review alert for form', [
+ 'form_id' => $form->id,
+ 'reason' => 'Already flagged within 24 hours',
+ ]);
+ return;
+ }
+
+ // Cache this form as flagged for 24 hours
+ Cache::put($cacheKey, true, now()->addDay());
+
Log::channel('slack_alerts')->info('🚨 Form flagged for admin review 🚨', [
'form_id' => $form->id,
'form_title' => $form->title,