feat: Login anomaly detection & suspicious activity alerts (#124)#645
Open
DrGalio wants to merge 1 commit intorohitdash08:mainfrom
Open
feat: Login anomaly detection & suspicious activity alerts (#124)#645DrGalio wants to merge 1 commit intorohitdash08:mainfrom
DrGalio wants to merge 1 commit intorohitdash08:mainfrom
Conversation
Implements issue rohitdash08#124 - Login anomaly detection & suspicious activity alerts ## Changes ### Backend - Added model to track all login attempts (IP, user agent, timestamp, success/failure) - Added model for storing generated anomaly alerts - Created service with detection for: - **Brute force**: Rapid failed login attempts (5+ in 15 min window) - **New IP**: Login from previously unseen IP address - **New device**: Login from new user agent/device fingerprint - **Credential stuffing**: Successful login after multiple failures - Modified auth endpoint to record attempts and return security alerts in response - Added endpoints: list alerts, mark read, unread count - Added schema migrations for new tables with proper indexes - Added Redis-backed brute force detection for performance ### Frontend - Added API module for alert endpoints - Added component with: - Alert list with severity badges (high/medium/low) - Filter by all/unread - Mark individual or all as read - Relative time display - Alert type icons ### Tests - 17 new tests covering: - Login attempt recording - Brute force detection (below/at threshold) - New IP detection (first login, new IP, same IP) - New device detection - Credential stuffing pattern - Combined anomaly detection - Alert CRUD operations - Auth endpoint integration - Alerts endpoint auth requirements - All 17 tests passing ### Acceptance Criteria Met - [x] Production-ready implementation - [x] Includes tests (17 passing) - [x] Database schema with migrations
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.
Fixes #124 — Login anomaly detection & suspicious activity alerts
Bounty: $50
What's Implemented
Backend (Python/Flask)
/auth/loginto record attempts, run anomaly checks, and return security alerts in response/alerts/API: list (with unread filter), mark read, unread countFrontend (React/TypeScript)
Tests — 17 passing
Files Changed
packages/backend/app/models.py— Added LoginAttempt + LoginAlert modelspackages/backend/app/services/login_anomaly.py— Anomaly detection service (new)packages/backend/app/routes/auth.py— Integrated login tracking into auth flowpackages/backend/app/routes/alerts.py— Alert management endpoints (new)packages/backend/app/routes/__init__.py— Registered alerts blueprintpackages/backend/app/db/schema.sql— Added tables + indexespackages/backend/app/__init__.py— Schema compatibility patchespackages/backend/tests/test_login_anomaly.py— 17 comprehensive tests (new)app/src/api/alerts.ts— Frontend API module (new)app/src/components/SecurityAlerts.tsx— Security alerts UI component (new)How It Works