feat(security): login anomaly detection & suspicious activity dashboard#677
Open
chengyixu wants to merge 1 commit intorohitdash08:mainfrom
Open
feat(security): login anomaly detection & suspicious activity dashboard#677chengyixu wants to merge 1 commit intorohitdash08:mainfrom
chengyixu wants to merge 1 commit intorohitdash08:mainfrom
Conversation
Implements login event tracking with anomaly scoring for issue rohitdash08#124. - Add LoginEvent model and schema migration for login_events table - Add login anomaly detection service (IP/device fingerprinting, brute-force detection, unusual hour detection, anomaly score 0.0-1.0) - Capture IP + user-agent on every login attempt via auth routes - Add /security API blueprint: login-history, anomalies, login-stats endpoints - Add Security page (React) with stats cards and color-coded risk table - Add /security route to App.tsx and Navbar navigation - Add 19 pytest tests covering anomaly scoring and security API routes - Fix pre-existing os.getenv fallback to use (os.environ.get() or default) pattern Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
|
Hi @rohitdash08! Could you please approve the CI workflows to run? As a first-time contributor, GitHub requires repo owner approval before CI can execute on fork PRs for security reasons. The workflows (CI, CodeQL, Frontend Tests) are queued at runs #23691858138, #23691858142, and #23691858148 - they just need your approval to run. Thank you! |
Author
|
Hi @rohitdash08! This PR implements the login anomaly detection feature (#124) with a full-stack solution: LoginEvent model, anomaly detection service, /security API blueprint, React Security page, and 19 pytest tests. Ready for review! |
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
Implements login anomaly detection with a full-stack security dashboard for issue #124.
Backend (
packages/backend/)New model —
LoginEventinapp/models.py:New service —
app/services/login_anomaly.py:compute_anomaly_score(): detects 4 anomaly signalsrecord_login(): persists aLoginEventwith computed scoreModified —
app/routes/auth.py:X-Forwarded-For/remote_addrandUser-Agenton every login attemptrecord_login()for both successful and failed loginsNew blueprint —
app/routes/security.py:GET /security/login-history— paginated login events (JWT protected)GET /security/anomalies— events with anomaly_score > 0 (JWT protected)GET /security/login-stats— aggregate stats: total logins, unique IPs, unique devices, suspicious count (JWT protected)Schema —
app/db/schema.sql+_ensure_schema_compatibility()inapp/__init__.py:login_eventstable with proper indexes onuser_id,created_at, and(user_id, anomaly_score)partial indexFrontend (
app/src/)New API client —
src/api/security.ts:getLoginHistory(),getAnomalies(),getLoginStats()TypeScript functionsNew page —
src/pages/Security.tsx:Wired up —
App.tsxroute/security(ProtectedRoute) +Navbar.tsxnav itemTests (
packages/backend/tests/test_login_anomaly.py)19 pytest tests:
compute_anomaly_score(baseline, new IP, new device, brute-force, unusual hour, combined signals)record_loginpersistence/security/endpoints (unauthenticated 401, authenticated responses, empty state, data population)/claim #124
Closes #124