Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
🔒️ Better ai moderation (#2194)
Luke Vella8b1121bf7ccb
diff --git a/apps/web/package.json b/apps/web/package.jsonindex 5075b05bc..01272794e 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -17,7 +17,7 @@"better-auth:generate": "pnpx @better-auth/cli@latest generate --config ./src/lib/auth.ts --output ../../packages/database/prisma/models/user.prisma"},"dependencies": {- "@ai-sdk/openai": "^2.0.28",+ "@ai-sdk/openai": "^3.0.29","@auth/prisma-adapter": "^2.7.4","@aws-sdk/client-s3": "^3.645.0","@aws-sdk/s3-request-presigner": "^3.645.0",@@ -61,7 +61,7 @@"@upstash/ratelimit": "^1.2.1","@vercel/functions": "^3.3.6","@vercel/kv": "^3.0.0",- "ai": "^5.0.41",+ "ai": "^6.0.87","arctic": "^3.7.0","better-auth": "^1.4.7","calendar-link": "^2.6.0",diff --git a/apps/web/src/features/moderation/libs/ai-moderation.ts b/apps/web/src/features/moderation/libs/ai-moderation.tsindex 0a0d327c3..f5cdca63e 100644--- a/apps/web/src/features/moderation/libs/ai-moderation.ts+++ b/apps/web/src/features/moderation/libs/ai-moderation.ts@@ -12,12 +12,22 @@ const logger = createLogger("moderation/ai");export async function moderateContentWithAI(text: string) {try {const result = await generateText({- model: openai("gpt-4-turbo"),+ model: openai("gpt-4.1-nano"),messages: [{role: "system",- content:- "You are a content moderator. Analyze the following text and determine if it is attempting to misuse the app to advertise illegal drugs, prostitution, or promote illegal gambling and other illicit activities. Respond with 'FLAGGED' if detected, otherwise 'SAFE'.",+ content: `You are a content moderator for a meeting scheduling app where users create polls to find the best time to meet. Analyze the following text (which is the title and/or description of a poll) and determine if it is legitimate scheduling content or an abuse attempt.++Flag the content as inappropriate if it matches ANY of these categories:+- Phishing or scams: fake account notifications, impersonation of brands (e.g. Binance, Coinbase, PayPal), "your balance/funds/account" language, urgency tactics to click links+- Spam relay abuse: content that is clearly not a scheduling poll but instead a message designed to be sent to participants via notification emails+- Financial fraud: fake crypto mining, investment scams, unclaimed funds, lottery winnings+- Illegal activities: drugs, prostitution, illegal gambling+- Malicious links: content whose primary purpose is to get readers to click an external link unrelated to scheduling++Legitimate polls typically have short titles like "Team lunch", "Q3 planning", or "Meeting next week" and may include a location or brief context. They do NOT contain financial claims, cryptocurrency amounts, account notifications, or urgent calls to action.++Respond with 'FLAGGED' if the content is inappropriate, otherwise 'SAFE'.`,},{ role: "user", content: text },],diff --git a/apps/web/src/features/moderation/libs/pattern-moderation.ts b/apps/web/src/features/moderation/libs/pattern-moderation.tsindex 00fb198c4..12495406e 100644--- a/apps/web/src/features/moderation/libs/pattern-moderation.ts+++ b/apps/web/src/features/moderation/libs/pattern-moderation.ts@@ -11,7 +11,8 @@ export function containsSuspiciousPatterns(text: string) {const allCapsPattern = /[A-Z]{5,}/;const excessiveSpecialCharsPattern =/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]{4,}/;- const suspiciousUrlPattern = /(bit\.ly|tinyurl|goo\.gl|t\.co|is\.gd)/i;+ const suspiciousUrlPattern =+ /(bit\.ly|tinyurl|goo\.gl|t\.co|is\.gd|telegra\.ph)/i;// Email address patternconst emailPattern = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/i;@@ -27,6 +28,17 @@ export function containsSuspiciousPatterns(text: string) {// Simple leet speak pattern that detects number-letter-number patternsconst leetSpeakPattern = /[a-z0-9]*[0-9][a-z][0-9][a-z0-9]*/i;+ // Crypto/financial scam patterns+ const cryptoScamPattern =+ /(\d+\.\d+\s*BTC|cloud mining|your balance|was mined|unclaimed funds)/i;++ // Raw HTTP(S) URLs — but exclude common meeting/location domains+ const rawUrlPattern = /https?:\/\/[^\s]+/i;+ const safeUrlPattern =+ /https?:\/\/([\w-]+\.)?(zoom\.us|meet\.google\.com|teams\.microsoft\.com|maps\.(google|apple)\.com|calendar\.google\.com|docs\.google\.com|whereby\.com|cal\.com|calendly\.com)[^\s]*/i;++ const hasUnsafeUrl = rawUrlPattern.test(text) && !safeUrlPattern.test(text);+return (// Simple pattern checks (least intensive)allCapsPattern.test(text) ||@@ -36,6 +48,8 @@ export function containsSuspiciousPatterns(text: string) {suspiciousUrlPattern.test(text) ||emailPattern.test(text) ||leetSpeakPattern.test(text) ||+ cryptoScamPattern.test(text) ||+ hasUnsafeUrl ||// More complex patternsphoneNumberPattern.test(text) ||// Most intensive pattern (Unicode handling)diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 5cffdd6af..d584f2c23 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -83,7 +83,7 @@ importers:version: 8.1.0([email protected])'@vercel/analytics':specifier: ^1.5.0- version: 1.6.1([email protected](@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])+ version: 1.6.1([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])dayjs:specifier: ^1.11.13version: 1.11.19@@ -122,7 +122,7 @@ importers:version: 6.0.0(@types/[email protected])([email protected])next-seo:specifier: ^6.1.0- version: 6.8.0([email protected](@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])+ version: 6.8.0([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])pg:specifier: ^8.17.1version: 8.18.0@@ -176,8 +176,8 @@ importers:apps/web:dependencies:'@ai-sdk/openai':- specifier: ^2.0.28- version: 2.0.89([email protected])+ specifier: ^3.0.29+ version: 3.0.29([email protected])'@auth/prisma-adapter':specifier: ^2.7.4version: 2.11.1(@prisma/[email protected]([email protected](@types/[email protected])([email protected]([email protected]))([email protected])([email protected]))([email protected]))@@ -308,8 +308,8 @@ importers:specifier: ^3.0.0version: 3.0.0ai:- specifier: ^5.0.41- version: 5.0.128([email protected])+ specifier: ^6.0.87+ version: 6.0.87([email protected])arctic:specifier: ^3.7.0version: 3.7.0@@ -890,26 +890,26 @@ packages:'@adobe/[email protected]':resolution: {integrity: sha512-Elp+iwUx5rN5+Y8xLt5/GRoG20WGoDCQ/1Fb+1LiGtvwbDavuSk0jhD/eZdckHAuzcDzccnkv+rEjyWfRx18gg==}- '@ai-sdk/[email protected]':- resolution: {integrity: sha512-+MZ/sY1i3MH/pB2W8DHZy9WOmlDdlR/FOJ/GwCVittVnbBCkMLIocIuR0sHuHawwFpTkFZziRW7Y98s/v+XMGA==}+ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-gGsUF42TKjnnKpyHNpk/J6Hw1HCg0XqfRS9QSeZ2nn+ccy+CUXIbnuIpeBMrGCHUOAiZCy5Ei/H9BW9VgV+vKg==}engines: {node: '>=18'}peerDependencies:zod: ^3.25.76 || ^4.1.8- '@ai-sdk/[email protected]':- resolution: {integrity: sha512-4+qWkBCbL9HPKbgrUO/F2uXZ8GqrYxHa8SWEYIzxEJ9zvWw3ISr3t1/27O1i8MGSym+PzEyHBT48EV4LAwWaEw==}+ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-ugVTIVpuSLKTjzSPe1F1DWiblJT/lwrrHx0OZEKjpMk/EYP6j6VD/F7SJqM1dsqOJryeBCJWFbUzLNqc99PrMA==}engines: {node: '>=18'}peerDependencies:zod: ^3.25.76 || ^4.1.8- '@ai-sdk/[email protected]':- resolution: {integrity: sha512-iXHVe0apM2zUEzauqJwqmpC37A5rihrStAih5Ks+JE32iTe4LZ58y17UGBjpQQTCRw9YxMeo2UFLxLpBluyvLQ==}+ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-8XiKWbemmCbvNN0CLR9u3PQiet4gtEVIrX4zzLxnCj06AwsEDJwJVBbKrEI4t6qE8XRSIvU2irka0dcpziKW6w==}engines: {node: '>=18'}peerDependencies:zod: ^3.25.76 || ^4.1.8- '@ai-sdk/[email protected]':- resolution: {integrity: sha512-KCUwswvsC5VsW2PWFqF8eJgSCu5Ysj7m1TxiHTVA6g7k360bk0RNQENT8KTMAYEs+8fWPD3Uu4dEmzGHc+jGng==}+ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-oGMAgGoQdBXbZqNG0Ze56CHjDZ1IDYOwGYxYjO5KLSlz5HiNQ9udIXsPZ61VWaHGZ5XW/jyjmr6t2xz2jGVwbQ==}engines: {node: '>=18'}'@alcalzone/[email protected]':@@ -5456,8 +5456,8 @@ packages:resolution: {integrity: sha512-0poP0T7el6Vq3rstR8Mn4V/IQrpBLO6POkUSrN7RhyY+GF/InCFShQzsQ39T25gkHhLgSLByyAz+Kjb+c2L98w==}engines: {node: '>=12'}- resolution: {integrity: sha512-861sVBlBBx4ZNHnSfSjtWFQFz2KbJ/uXxdYOkaLSRf3tkvCLrNo1hrFsgGFMMTzPT/X/iXW26OoFQiO3aSvoog==}+ resolution: {integrity: sha512-EHq2y9s1OGgN705mPJIII8qaL43Ko7rMUjMHiCWIpG8esnjBNvymlrcFLnwzPRnMD6OAC6PrRZyiD5nZwX3qFw==}engines: {node: '>=18'}peerDependencies:zod: ^3.25.76 || ^4.1.8@@ -10685,27 +10685,27 @@ snapshots:'@adobe/[email protected]': {}- '@ai-sdk/[email protected]([email protected])':+ '@ai-sdk/[email protected]([email protected])':dependencies:- '@ai-sdk/provider': 2.0.1- '@ai-sdk/provider-utils': 3.0.20([email protected])+ '@ai-sdk/provider': 3.0.8+ '@ai-sdk/provider-utils': 4.0.15([email protected])'@vercel/oidc': 3.1.0zod: 4.3.6- '@ai-sdk/[email protected]([email protected])':+ '@ai-sdk/[email protected]([email protected])':dependencies:- '@ai-sdk/provider': 2.0.1- '@ai-sdk/provider-utils': 3.0.20([email protected])+ '@ai-sdk/provider': 3.0.8+ '@ai-sdk/provider-utils': 4.0.15([email protected])zod: 4.3.6- '@ai-sdk/[email protected]([email protected])':+ '@ai-sdk/[email protected]([email protected])':dependencies:- '@ai-sdk/provider': 2.0.1+ '@ai-sdk/provider': 3.0.8'@standard-schema/spec': 1.1.0eventsource-parser: 3.0.6zod: 4.3.6- '@ai-sdk/[email protected]':+ '@ai-sdk/[email protected]':dependencies:json-schema: 0.4.0@@ -16010,7 +16010,7 @@ snapshots:dependencies:uncrypto: 0.1.3- '@vercel/[email protected]([email protected](@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])':+ '@vercel/[email protected]([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])':optionalDependencies:next: 16.1.6(@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected])react: 19.2.4@@ -16236,11 +16236,11 @@ snapshots:clean-stack: 4.2.0indent-string: 5.0.0dependencies:- '@ai-sdk/gateway': 2.0.34([email protected])- '@ai-sdk/provider': 2.0.1- '@ai-sdk/provider-utils': 3.0.20([email protected])+ '@ai-sdk/gateway': 3.0.47([email protected])+ '@ai-sdk/provider': 3.0.8+ '@ai-sdk/provider-utils': 4.0.15([email protected])'@opentelemetry/api': 1.9.0zod: 4.3.6@@ -19742,7 +19742,7 @@ snapshots:react: 19.2.4react-dom: 19.2.4([email protected])- [email protected]([email protected](@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected]):+ [email protected]([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected]):dependencies:next: 16.1.6(@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected])react: 19.2.4