Skip to content

ProneilS/secure-access

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

30 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” SecureAccess

Intelligent Authentication System with AI-Based Anomaly Detection

πŸš€ Interactive Demo (Recommended): https://secure-access-ui.vercel.app
πŸ“Š Admin Dashboard: https://secure-access-ashy.vercel.app
βš™οΈ Backend API: https://secure-access-v2ta.onrender.com


🧠 Overview

SecureAccess is a production-deployed authentication system that goes beyond JWT-based login by integrating real-time behavioral anomaly detection.

Instead of trusting every successful login, the system evaluates user behavior (IP, device, time) using a machine learning microservice and flags suspicious activity instantly.

This project simulates how modern identity systems detect compromised accounts β€” not just authenticate users.


⚑ Try it in 30 seconds

  1. Open the interactive demo
  2. Click any scenario (e.g. 3AM login or Foreign IP)
  3. Watch the system flag anomalies in real time
  4. Open the admin dashboard to see logged events

⚠️ First request may take ~30-60s (Render free tier cold start)


πŸ”₯ What Makes This Different

  • πŸ” JWT Authentication (Access + Refresh Tokens)
  • πŸ›‘οΈ Role-Based Access Control (RBAC)
  • πŸ“Š Login Event Tracking & Session Management
  • 🧠 AI-Based Anomaly Detection (Isolation Forest)
  • ⚑ Non-blocking architecture β€” ML scoring never delays authentication
  • πŸ“ˆ Admin Dashboard with real-time monitoring
  • ☁️ Fully deployed multi-service architecture

πŸ—οΈ System Architecture

          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚   Frontend   β”‚  (React - Vercel)
          β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚  Node.js Backend β”‚  (Render)
        β”‚  Auth + Sessions β”‚
        β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
       β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚  PostgreSQL DB  β”‚  (Render)
       β”‚ Users / Events  β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
               β–Ό
      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β”‚ Python ML Service β”‚  (Flask - Render)
      β”‚  Isolation Forest β”‚
      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

This architecture ensures authentication remains fast while anomaly detection runs asynchronously β€” similar to production-grade systems.

πŸ”„ Authentication Flow

  1. User submits login credentials
  2. Backend validates and compares hashed password (bcrypt)
  3. JWT tokens are generated:
    • Access Token β€” 15 min lifetime
    • Refresh Token β€” 7 day lifetime
  4. Login event is stored in database
  5. Backend asynchronously sends data to ML service
  6. ML service evaluates anomaly score
  7. Suspicious logins are flagged in database
  8. Session stored β†’ tokens returned

⚑ Note: Anomaly detection is non-blocking to avoid login delays.


🧠 Anomaly Detection (ML Service)

Property Detail
Model Isolation Forest (Unsupervised)
Training Data Synthetic login behavior data
Features hour_of_day, ip_changed, new_device, login_frequency_today

Why Isolation Forest?

  • No labeled attack data required
  • Efficient for anomaly detection
  • Works well for behavioral deviations

The model learns normal login behavior patterns and flags deviations without requiring labeled attack data.

πŸ—„οΈ Database Design

Tables: users Β· sessions Β· login_events

Key Design Decisions:

  • ON DELETE CASCADE β†’ prevents orphan records
  • flagged column β†’ marks anomalous logins
  • Session storage β†’ enables refresh token revocation

πŸ–₯️ Admin Dashboard

  • πŸ“Š Total users, logins, and flagged events
  • 🚨 Highlighted suspicious logins
  • 🧾 Active session tracking
  • πŸ” Admin-only access

βš™οΈ Tech Stack

Layer Technology
Backend Node.js, Express
Database PostgreSQL
Auth JWT, bcrypt
ML Service Python, Flask, scikit-learn
Frontend React
Deployment Render, Vercel

πŸš€ Deployment

Service Platform
Frontend Vercel
Backend + Python Service Render
Database Render PostgreSQL

⚠️ Render free tier may sleep after inactivity (30–60s cold start on first request).


πŸ§ͺ Testing

  • βœ… Authentication flows (valid/invalid credentials)
  • βœ… RBAC protection
  • βœ… Admin endpoints
  • βœ… Anomaly detection scenarios
  • βœ… Rapid login attempts
  • βœ… Deployment behavior (cold starts, logs)

🧯 Challenges & Fixes

1. Python Version Incompatibility

  • Issue: Python 3.14 broke dependencies
  • Fix: Pinned to python-3.11.9

2. Service Communication

  • Issue: http.request complexity
  • Fix: Switched to Axios for cleaner integration

3. Port Binding in Deployment

  • Issue: Flask not exposed correctly
  • Fix: Bound to 0.0.0.0 with dynamic PORT

4. Route Mismatch

  • Issue: /analyze vs /analyse inconsistency
  • Fix: Standardized endpoint naming

5. Missing Dependencies Crash

  • Issue: Axios not installed
  • Fix: Added to package.json

πŸ” Security Considerations

  • Same error message for invalid email/password β†’ prevents user enumeration
  • Short-lived access tokens β†’ reduces attack window
  • Refresh tokens stored server-side β†’ revocable
  • Role-based route protection

⚠️ Limitations

  • Uses synthetic training data
  • Global model (not per-user)
  • Basic IP/device detection heuristics

🚧 Future Improvements

  • OAuth (Google login)
  • Per-user anomaly models
  • Redis for behavioral tracking
  • Refresh token rotation
  • Real-world dataset integration

πŸ’¬ Why This Project?

Modern authentication systems don’t stop at login β€” they continuously evaluate user behavior.

This project was built to:

  • Understand real-world IAM systems
  • Explore security beyond JWT
  • Implement behavior-based anomaly detection
  • Experience production deployment challenges

πŸ“Œ Author

Proneil Sengupta β€” Backend & AI Systems Enthusiast


If you found this interesting, feel free to ⭐ the repo!

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors