feat: Login Anomaly Detection & Suspicious Activity Alerts#685
Open
ljapptest-art wants to merge 3 commits intorohitdash08:mainfrom
Open
feat: Login Anomaly Detection & Suspicious Activity Alerts#685ljapptest-art wants to merge 3 commits intorohitdash08:mainfrom
ljapptest-art wants to merge 3 commits intorohitdash08:mainfrom
Conversation
added 2 commits
March 29, 2026 12:18
Implements comprehensive login security monitoring: - New device detection via browser fingerprinting - New location detection (country-based) - Unusual login time detection (learns user patterns) - Multiple failed login attempt monitoring Changes: - Add LoginAnomalyDetector service with 4 detection types - Add security endpoints for device/alert management - Integrate anomaly detection into auth flow - Add 33 comprehensive tests - Add documentation Resolves rohitdash08#124
25f6965 to
d83e5db
Compare
…nd frontend UI Implements all fixes identified in audit: HIGH PRIORITY: - Add database migration file (001_login_anomaly.sql) - Creates login_attempts, user_devices, login_anomalies tables - Adds performance indexes - Defines PostgreSQL enum type for anomaly types MEDIUM PRIORITY: - Implement SUSPICIOUS_IP detection - Detects private/internal IPs (192.168.x.x, 10.x.x.x, etc.) - Placeholder for VPN/Tor exit nodes - High-risk country detection (extensible) - Adds 2 new tests for private/public IP detection - Implement Geo-IP integration - Uses free ip-api.com service (no API key required) - Extracts country and city from IP address - 2 second timeout, graceful fallback on failure - Automatically called in get_login_context() LOW PRIORITY: - Add frontend Security Center UI - React component with TypeScript - Login history, devices, and alerts tabs - Device trust/revoke functionality - Alert acknowledge functionality - Responsive design with Tailwind CSS - Added to navbar navigation TESTS: - All 20 tests passing - Added test_check_suspicious_ip_private - Added test_check_suspicious_ip_public - Fixed test_process_login_success to use public IP Resolves rohitdash08#124
Author
🔗 Related IssueThis PR also addresses #125 (Device trust management & recognition). Device Trust Features ImplementedAs part of the Security Center implementation, this PR includes:
Frontend UIThe Security Center page (
Acceptance Criteria for #125
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements a comprehensive login anomaly detection and security alerts system for FinMind, addressing issue #124.
What's Implemented
Anomaly Detection Types
New API Endpoints
GET /security/alerts- List security alerts for current userGET /security/alerts/{id}- Get alert detailsPOST /security/alerts/{id}/acknowledge- Acknowledge an alertPOST /security/alerts/acknowledge-all- Acknowledge all alertsGET /security/login-history- View recent login historyGET /security/devices- List known devicesFiles Changed
app/models.py- AddedLoginHistoryandSecurityAlertmodelsapp/routes/auth.py- Integrated anomaly detection on loginapp/routes/security.py- New security API endpointsapp/services/anomaly_detection.py- Core anomaly detection logicapp/services/security_alerts.py- Alert generation and email notificationsapp/db/schema.sql- Database schema for new tablestests/test_security.py- Comprehensive test coverageTest Results
All 14 core anomaly detection tests pass:
Notes