minor change
A modular, real-time behavioral continuous authentication system with:
- Browser SDK (
sdk/tracker.js) for behavior capture - Flask backend for data collection and scoring
- Feature extraction and profile building pipeline
- Comparative anomaly detection (Gaussian + Isolation Forest)
- Decision engine and evaluation utilities
- SQL schema for users, sessions, events, features, and results
- Supabase-backed storage using PostgreSQL tables
EDI_2/
├── app/
│ ├── __init__.py
│ ├── config.py
│ ├── extensions.py
│ ├── models.py
│ ├── api/
│ │ ├── __init__.py
│ │ └── routes.py
│ └── services/
│ ├── __init__.py
│ ├── data_acquisition.py
│ ├── feature_extraction.py
│ ├── profile_builder.py
│ ├── anomaly_detection.py
│ ├── decision_engine.py
│ ├── evaluation.py
│ └── logging_service.py
├── sdk/
│ └── tracker.js
├── sql/
│ └── schema.sql
├── examples/
│ └── api_usage.md
├── logs/
├── .env.example
├── .gitignore
├── requirements.txt
└── run.py
Frontend SDK -> Backend -> Feature Extraction -> Profile -> Model -> Decision -> Response
- Data Acquisition Module:
app/services/data_acquisition.py- Validates and stores raw mouse, click, keyboard, and timing events.
- Feature Extraction Module:
app/services/feature_extraction.py- Cleans data and derives required mouse, keyboard, and interaction features.
- Produces structured feature vectors and normalization through L2 vector normalization.
- Behavioral Profile Builder:
app/services/profile_builder.py- Builds user baseline with mean and variance over historical feature vectors.
- Anomaly Detection Engine:
app/services/anomaly_detection.py- Model 1: Gaussian distance-based anomaly score.
- Model 2: Isolation Forest anomaly score.
- Decision Engine:
app/services/decision_engine.py- Converts combined anomaly score to
LegitimateorSuspicioususing threshold.
- Evaluation and Logging:
app/services/evaluation.pycomputes FAR, FRR, AUC.app/services/logging_service.pylogs session activity, predictions, and anomalies.
POST /start-sessionPOST /end-sessionPOST /collectGET /auth-score?session_id=<SESSION_ID>
SQL schema is defined in sql/schema.sql and intended for Supabase PostgreSQL.
Tables:
userssessionsraw_behavior_datafeaturesuser_profilesresults
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txtCopy environment file and set Supabase credentials:
copy .env.example .envRun the statements in sql/schema.sql inside your Supabase SQL editor before starting the backend.
Run backend:
python run.pyBackend starts on http://localhost:5000.
Include sdk/tracker.js in your web app and initialize:
<script src="/sdk/tracker.js"></script>
<script>
const tracker = BehaviorAuthTracker.init({
apiBaseUrl: "http://localhost:5000",
userId: "user_001",
flushIntervalMs: 2000,
maxBufferSize: 100
});
tracker.start();
// const result = await tracker.getAuthScore();
// await tracker.stop();
</script>Use app/services/evaluation.py:
from app.services.evaluation import compute_far_frr_auc
metrics = compute_far_frr_auc(
y_true=[0, 0, 1, 1],
y_pred=[0, 1, 1, 1],
y_scores=[0.10, 0.70, 0.80, 0.95],
)
print(metrics)
# {'far': ..., 'frr': ..., 'auc': ...}See examples/api_usage.md for complete curl and SDK examples.