feat(chat): implement spam protection and profanity filter

Add comprehensive message validation with three protection mechanisms:

1. Rate Limiting: 10 messages per minute per user
2. Duplicate Detection: Prevents sending identical messages within 1 minute
3. Profanity Filter: Blocks inappropriate language (English + Polish)

Implementation:
- New messageValidation.js middleware with validateMessage() function
- Integrated into both event chat and match chat handlers
- Uses bad-words library (v2.0.0 for CommonJS compatibility)
- In-memory tracking with automatic cleanup every 5 minutes
- User-friendly error messages for each validation type

Technical details:
- Rate limit: 10 msg/min sliding window
- Duplicate check: Last 5 messages within 60s window
- Profanity: bad-words + 11 Polish words
- Memory management: Periodic cleanup of expired data
This commit is contained in:
Radosław Gierwiało
2025-12-02 23:59:16 +01:00
parent 4a91a10aff
commit ace33111a4
4 changed files with 228 additions and 23 deletions

View File

@@ -26,6 +26,7 @@
"dependencies": {
"@aws-sdk/client-ses": "^3.930.0",
"@prisma/client": "^5.8.0",
"bad-words": "^2.0.0",
"bcryptjs": "^2.4.3",
"cookie-parser": "^1.4.7",
"cors": "^2.8.5",
@@ -49,7 +50,9 @@
},
"jest": {
"testEnvironment": "node",
"setupFilesAfterEnv": ["<rootDir>/jest.setup.js"],
"setupFilesAfterEnv": [
"<rootDir>/jest.setup.js"
],
"coveragePathIgnorePatterns": [
"/node_modules/"
],