Skip to content

Latest commit

 

History

History
288 lines (220 loc) · 9.42 KB

File metadata and controls

288 lines (220 loc) · 9.42 KB

Bot Detection System

Overview

The bot detection system is a comprehensive multi-layered approach to identify automated user behavior and suspicious activity patterns on the confession platform. It uses advanced algorithms to analyze user behavior and maintain platform integrity.

🎯 System Architecture

Core Components

  1. BotDetectionService (src/lib/bot-detection.ts)

    • Main service class with singleton pattern
    • Comprehensive bot detection algorithms
    • Risk level classification
    • Statistical analysis
  2. Database Integration (src/lib/db-utils.ts)

    • Enhanced reputation calculation with bot penalties
    • Real-time activity monitoring
    • Bot probability updates
    • Historical tracking
  3. Admin Dashboard (src/components/BotDetectionPanel.tsx)

    • Real-time bot detection statistics
    • Risk level visualization
    • Detection method explanations
    • User management interface

🔍 Detection Methods

1. Activity Pattern Analysis

  • Excessive Activity Detection: Monitors daily action counts (>50 actions = high risk)
  • Activity Burst Analysis: Identifies unnatural activity spikes
  • Consistent Pattern Recognition: Detects unnaturally regular behavior patterns

2. Content Analysis

  • Repetitive Content Detection: Analyzes content similarity (>70% similarity = high risk)
  • Generic/Bot-like Content: Identifies templated or automated content
  • Content Length Analysis: Detects suspicious length patterns

3. Timing Analysis

  • Regular Interval Detection: Identifies automated posting schedules
  • 24/7 Activity Monitoring: Detects continuous activity patterns
  • Timezone Inconsistency Checks: Identifies multi-timezone bot networks

4. Engagement Analysis

  • Low Engagement Despite High Activity: Detects bots that post but don't interact
  • One-sided Interaction Detection: Identifies bots that only post or only vote
  • Social Graph Analysis: Analyzes user interaction patterns

5. Device/IP Analysis

  • Multiple Account Detection: Identifies accounts from same source
  • Device Fingerprinting: Tracks device patterns (future implementation)
  • IP Address Analysis: Monitors IP-based patterns

6. Social Graph Analysis

  • Isolation Score: Measures social connection patterns
  • Artificial Social Patterns: Detects fake social interactions
  • Network Analysis: Identifies bot networks

📊 Risk Classification

Risk Levels

Level Probability Action Required Description
CRITICAL 80%+ Immediate suspension High confidence bot detection
HIGH 60-79% Enhanced monitoring Strong bot indicators
MEDIUM 30-59% Regular monitoring Moderate suspicion
LOW 0-29% Normal monitoring Normal activity patterns

Bot Probability Calculation

Total Score = Activity Score + Content Score + Timing Score + 
              Engagement Score + Device Score + Social Score

Bot Probability = (Total Score / Max Score) * 100

🛠️ Implementation Details

Database Schema Updates

model User {
  // Bot detection fields
  botProbability     Int @default(0) // 0-100, higher = more likely bot
  isFlagged          Boolean @default(false)
  verificationLevel   String @default("NEW_USER")
  
  // Activity tracking
  dailyConfessions   Int @default(0)
  dailyVotes         Int @default(0)
  dailyComments      Int @default(0)
  confessionsCreated Int @default(0)
  votesCast          Int @default(0)
  commentsCreated    Int @default(0)
}

model ReputationHistory {
  // Enhanced tracking
  botProbability     Int?
  botIndicators      String[] // Array of bot detection indicators
  riskLevel          String? // LOW, MEDIUM, HIGH, CRITICAL
}

API Endpoints

  1. GET /api/admin/bot-detection/stats

    • Returns bot detection statistics
    • Total users, suspicious users, critical users, average probability
  2. GET /api/admin/bot-detection/[userId]

    • Returns detailed bot detection info for specific user
    • Probability, indicators, risk level, recommendations

Integration Points

  1. User Activity Monitoring

    // Called on every user action
    await monitorUserActivity(userId, 'confession' | 'vote' | 'comment');
  2. Reputation Calculation

    // Bot penalty applied to reputation
    const botPenalty = botProbability > 50 ? (botProbability - 50) * 0.5 : 0;
    const reputationScore = activityScore + qualityScore + trustScore - botPenalty;
  3. Real-time Flagging

    // Automatic flagging for critical risk
    if (botDetectionResult.riskLevel === 'CRITICAL') {
      await flagUser(userId);
    }

📈 Monitoring & Analytics

Key Metrics

  1. Bot Detection Rate: Percentage of users flagged as suspicious
  2. Critical Risk Users: Number of users with 80%+ bot probability
  3. Average Bot Probability: Mean bot probability across all users
  4. Detection Accuracy: False positive/negative rates

Dashboard Features

  • Real-time Statistics: Live updates of bot detection metrics
  • Risk Level Visualization: Color-coded risk indicators
  • Detection Method Breakdown: Explanation of detection algorithms
  • User Management: Flag/unflag users with detailed reasoning

🔧 Configuration

Detection Thresholds

const DETECTION_THRESHOLDS = {
  EXCESSIVE_ACTIVITY: 50,        // Daily actions
  HIGH_ACTIVITY: 30,             // Daily actions
  REPETITIVE_CONTENT: 0.7,       // Similarity threshold
  GENERIC_CONTENT: 0.6,          // Generic content threshold
  REGULAR_INTERVALS: 0.8,        // Timing regularity
  CONTINUOUS_ACTIVITY: true,     // 24/7 activity flag
  LOW_ENGAGEMENT_RATIO: 0.1,     // Engagement threshold
  ONE_SIDED_INTERACTIONS: 0.8,   // Interaction pattern threshold
};

Risk Level Thresholds

const RISK_THRESHOLDS = {
  CRITICAL: 80,  // 80%+ bot probability
  HIGH: 60,      // 60-79% bot probability
  MEDIUM: 30,    // 30-59% bot probability
  LOW: 0,        // 0-29% bot probability
};

🚀 Usage Examples

Basic Bot Detection

import { botDetectionService } from '@/lib/bot-detection';

// Detect bot for a user
const result = await botDetectionService.detectBot(userId);
console.log(`Bot probability: ${result.probability}%`);
console.log(`Risk level: ${result.riskLevel}`);
console.log(`Indicators: ${result.indicators.join(', ')}`);

Admin Dashboard Integration

import { BotDetectionPanel } from '@/components/BotDetectionPanel';

// Add to admin page
<BotDetectionPanel />

Real-time Monitoring

// Monitor user activity
await monitorUserActivity(userId, 'confession');

// Get bot detection stats
const stats = await getBotDetectionStats();
console.log(`Critical users: ${stats.criticalUsers}`);

🔒 Security Considerations

Privacy Protection

  • Bot detection data is stored securely
  • Personal information is not exposed in bot analysis
  • Detection algorithms focus on behavior patterns, not personal data

False Positive Mitigation

  • Multiple detection methods reduce false positives
  • Manual review process for flagged users
  • Appeal system for incorrectly flagged accounts

Performance Optimization

  • Efficient database queries for large user bases
  • Caching of detection results
  • Asynchronous processing for real-time monitoring

📋 Future Enhancements

Planned Features

  1. Machine Learning Integration: Advanced ML models for pattern recognition
  2. Behavioral Biometrics: Mouse movement and typing pattern analysis
  3. Network Analysis: Detection of coordinated bot networks
  4. Real-time Alerts: Instant notifications for critical detections
  5. Automated Actions: Automatic suspension for confirmed bots

Advanced Detection Methods

  1. Natural Language Processing: Content sentiment and style analysis
  2. Image Analysis: Profile picture and content image analysis
  3. Geographic Analysis: Location-based pattern detection
  4. Temporal Analysis: Time-based behavior pattern recognition

🎯 Benefits

For Platform Integrity

  • Reduced Spam: Automated detection prevents spam content
  • Quality Control: Maintains high-quality user interactions
  • Trust Building: Creates a safer environment for users
  • Resource Protection: Prevents abuse of platform resources

For User Experience

  • Cleaner Feed: Less spam and automated content
  • Better Engagement: Higher quality interactions
  • Fair Competition: Prevents bot-driven unfair advantages
  • Community Health: Maintains authentic community interactions

For Administrators

  • Automated Monitoring: Reduces manual review workload
  • Detailed Analytics: Comprehensive bot detection statistics
  • Proactive Management: Early detection of suspicious activity
  • Scalable Solution: Handles large user bases efficiently

🔄 Maintenance

Regular Updates

  • Monitor detection accuracy rates
  • Adjust thresholds based on false positive/negative rates
  • Update detection algorithms based on new bot patterns
  • Review and refine risk classification system

Performance Monitoring

  • Track detection processing times
  • Monitor database query performance
  • Optimize algorithms for large-scale deployment
  • Scale infrastructure as user base grows

This bot detection system provides comprehensive protection against automated abuse while maintaining user privacy and platform performance.