How danosaurus-rex24/segura works
Purpose and System Shape
Segura is an enterprise email-security prototype for detecting business email compromise (BEC) in Gmail. It is split into three decoupled runtimes: a browser-extension sensor, a FastAPI aggregation API, and a React/Vite executive dashboard. The extension evaluates messages locally, surfaces risk in Gmail, and reports flagged events to the backend.
Browser Extension Sensor
The extension is defined by manifest.json and injects Gmail-facing logic from src/content/content-script.js. This content script is the operational entry point in the browser: it observes/extracts email context from Gmail’s SPA DOM, invokes detection, adds an in-email risk banner, and sends threat events outward.
Key boundaries:
• Gmail DOM and user session remain inside the content-script environment.
• Detection is intentionally local and dependency-free.
• Only flagged-event data crosses to the backend API.
Paths: manifest.json, src/content/content-script.js.
Detection and Explanation Pipeline
The heuristic engine evaluates approximately 11 weighted fraud indicators, accumulates a score, and maps it into low, moderate, or high risk tiers. Signal definitions and scoring logic are centralized in src/detection/signals.js; user-facing reasoning is produced by src/detection/explain.js.
Control flow: extracted sender/body/metadata → signal evaluation → weighted score and triggered-signal set → risk tier → plain-English explanations → Gmail banner and API event payload.
Paths: src/detection/signals.js, src/detection/explain.js, src/content/content-script.js.
Backend Aggregator and Reporting API
The FastAPI application entry point is segura-backend/main.py. It exposes REST endpoints for event ingestion, organizational posture/statistics, flagged-email listing and drill-down, and monthly reporting. The backend is the boundary between individual browser detections and centralized dashboard reporting.
Supporting scripts indicate a seeded/demo-oriented data lifecycle and post-processing of stored explanations/snippets:
segura-backend/seed_data.py, segura-backend/regenerate_explanations.py, segura-backend/fix_snippets.py.
Paths: segura-backend/main.py, segura-backend/seed_data.py, segura-backend/regenerate_explanations.py.
Dashboard Application
The dashboard is a React 19 single-page application bootstrapped at segura-dashboard/src/main.jsx and composed from segura-dashboard/src/App.jsx. It presents backend-derived security posture for executive and analyst workflows, including overview, flagged-email review, individual incident detail, and monthly reporting.
Primary views:
• Operational posture and detection terminal: segura-dashboard/src/pages/Overview.jsx
• Filterable flag queue: segura-dashboard/src/pages/FlaggedEmails.jsx
• Threat drill-down: segura-dashboard/src/pages/EmailDetail.jsx
• Trend/report presentation and print export: segura-dashboard/src/pages/MonthlyReport.jsx
Presentation Shell and Design Boundary
Shared navigation/page composition resides in segura-dashboard/src/components/Layout.jsx; global visual and print styling are rooted in segura-dashboard/src/App.css and segura-dashboard/src/index.css. The dashboard is a presentation consumer of API data rather than a detection engine; risk calculation belongs to the extension/backend event model.
Paths: segura-dashboard/src/components/Layout.jsx, segura-dashboard/src/App.css, segura-dashboard/src/index.css.
Runtime and Integration Boundaries
Material runtimes are Chrome extension JavaScript, Python 3.10+ FastAPI/Uvicorn, and Node 18+/React/Vite. The extension communicates with the FastAPI service on its REST endpoints (development API on port 8000); the dashboard runs independently through Vite (typically port 5173/5174) and reads API-backed metrics. Gmail is the external source system, while browser DOM injection is the mechanism for sensor deployment.
Main entry points: main.py FastAPI Application · Layout.jsx Shared Layout · content-script.js Gmail Content Script · App.jsx Dashboard App
Components 16
Chrome Extension
Local Gmail sensor runtime.
- Extension Manifest · Declares Gmail injection.
manifest.json - Gmail Content Script · Extracts messages, renders banners, and reports flags.
src/content/content-script.js - Fraud Signals · Evaluates weighted BEC indicators.
src/detection/signals.js - Risk Explanations · Produces user-facing reasons for triggered signals.
src/detection/explain.js
FastAPI Backend
Central event and reporting API.
- FastAPI Application · Ingests events and serves posture, incidents, and reports.
segura-backend/main.py - Demo Data Seeder · Seeds demonstration reporting data.
segura-backend/seed_data.py - Explanation Regenerator · Post-processes stored explanations.
segura-backend/regenerate_explanations.py
React Dashboard
Independent reporting SPA.
- Dashboard Bootstrap
segura-dashboard/src/main.jsx - Dashboard App · Composes API-backed executive and analyst workflows.
segura-dashboard/src/App.jsx - Shared Layout · Provides shared navigation and page composition.
segura-dashboard/src/components/Layout.jsx - Overview · Shows operational posture and detection terminal.
segura-dashboard/src/pages/Overview.jsx - Flagged Email Queue · Provides filterable flagged-email review.
segura-dashboard/src/pages/FlaggedEmails.jsx - Incident Detail · Shows individual threat details.
segura-dashboard/src/pages/EmailDetail.jsx - Monthly Report · Presents trends and print export.
segura-dashboard/src/pages/MonthlyReport.jsx - Global & Print Styles · Defines dashboard visual and print styling.
segura-dashboard/src/App.css
Other components
- Gmail · Source email context and host DOM.
Connections 19
- Extension Manifest → Gmail Content Script: injects into Gmail
- Gmail → Gmail Content Script: email DOM context
- Gmail Content Script → Fraud Signals: sender, body, metadata
- Fraud Signals → Risk Explanations: score, tier, triggered signals
- Risk Explanations → Gmail Content Script: banner reasoning
- Gmail Content Script → FastAPI Application: flagged threat events
- Demo Data Seeder → FastAPI Application: seeds demo data
- Explanation Regenerator → FastAPI Application: updates stored explanations
- Dashboard Bootstrap → Dashboard App: boots
- Dashboard App → Shared Layout: composes shell
- Shared Layout → Overview: hosts
- Shared Layout → Flagged Email Queue: hosts
- Shared Layout → Incident Detail: hosts
- Shared Layout → Monthly Report: hosts
- Global & Print Styles → Dashboard App: global styling
- FastAPI Application → Overview: posture metrics
- FastAPI Application → Flagged Email Queue: flagged-email list
- FastAPI Application → Incident Detail: incident data
- FastAPI Application → Monthly Report: monthly reporting data