From 722d0461dc054622ed86fd892827f2953453cc25 Mon Sep 17 00:00:00 2001 From: Blake Ridgway Date: Sun, 30 Nov 2025 19:24:32 -0600 Subject: [PATCH] add more message validation --- internal/handlers/handlers.go | 236 +++++++++++++++++++++++++++++++++- 1 file changed, 232 insertions(+), 4 deletions(-) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 0b9857c..6aa696b 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -7,10 +7,12 @@ import ( "net/http" "os" "path/filepath" + "regexp" "strconv" "strings" "text/template" "time" + "unicode" "landing/internal/config" "landing/internal/database" @@ -362,6 +364,180 @@ func (h *Handler) contactHandler(w http.ResponseWriter, r *http.Request) { } } +// isEnglishText checks if text is primarily in English +func isEnglishText(text string) bool { + if len(text) == 0 { + return true + } + + englishCharCount := 0 + nonASCIICount := 0 + totalCharCount := 0 + + for _, r := range text { + // Count letters and numbers + if unicode.IsLetter(r) || unicode.IsNumber(r) || unicode.IsSpace(r) || unicode.IsPunct(r) { + totalCharCount++ + + // English ASCII range (a-z, A-Z, 0-9, common punctuation/spaces) + if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || + r == ' ' || r == '.' || r == ',' || r == '!' || r == '?' || r == '-' || r == '\'' || r == '"' || + r == ';' || r == ':' || r == '(' || r == ')' || r == '\n' || r == '\t' { + englishCharCount++ + } else if r > 127 { // Non-ASCII character + nonASCIICount++ + } + } + } + + if totalCharCount == 0 { + return true + } + + // Allow up to 10% non-ASCII characters (for names, etc) + // But require at least 70% English ASCII + englishPercentage := float64(englishCharCount) / float64(totalCharCount) + + return englishPercentage >= 0.7 +} + +// isSpamMessage checks if a message looks like spam +func isSpamMessage(message string) bool { + // Convert to lowercase for checks + lowerMsg := strings.ToLower(message) + + // Check for common spam patterns + spamPatterns := []string{ + "viagra", "cialis", "casino", "lottery", "prize", + "click here", "buy now", "limited time", + "congratulations", "you have won", "claim your", + "bitcoin", "crypto", "forex", "trading bot", + "free money", "make money fast", "work from home", + "nigerian", "inheritance", "transfer funds", + "