Security Architecture
Six dedicated security modules handle every aspect of data protection, access enforcement, and compliance automatically.
Authentication
Every API endpoint is protected by Bearer token authentication enforced at the FastAPI dependency layer. Tokens are bcrypt-hashed and stored with expiration and revocation timestamps.
- OAuth 2.0 via Google — no local password storage
- Bearer tokens with 24-hour expiry
- Immediate token revocation on logout or deletion
- Device session tracking across platforms
Role-Based Access Control
A four-tier role hierarchy (Owner → Admin → Manager → Member) is enforced on every write operation. Access is default-denied — roles must explicitly grant permissions.
- Permissions matrix cached at startup
- Least-privilege enforcement on all resources
- Role resolution: team → resource → default
- HTTP 403 + audit log on any denial
Encryption at Rest
Sensitive fields are encrypted with AES-256-GCM before storage. Each value uses a unique 12-byte nonce; GCM authentication tags detect any tampering. Keys are never hardcoded.
- AES-256-GCM with unique nonce per value
- HMAC-SHA256 for searchable encrypted fields
- Keys loaded from environment — never in code
- OAuth tokens, API keys, and credentials encrypted
Audit Logging
Every security-relevant event is written to an immutable audit_log table. Logs capture actor, action, resource, result, IP address, and user-agent. They cannot be modified.
- 30+ distinct event types logged
- Authentication events: login, logout, OAuth, QR
- Authorization denials automatically recorded
- 365-day minimum retention, then automated purge
Token Lifecycle
Tokens and sessions are actively managed throughout their lifecycle. Expired tokens are cleaned up daily. Any token can be revoked instantly, invalidating access across all devices.
- Expiration enforced at validation time
- Revocation stamps:
revoked_at+ reason - Daily automated cleanup of expired tokens
- "Revoke all sessions" for account takeover response
Data Retention & Deletion
All user data has documented retention periods. A nightly job runs at 3 AM UTC to soft-delete expired records and hard-delete data past its grace period. Users can request full deletion.
- Tiered policies: 90 / 180 / 365 days by data type
- 30-day grace period before permanent deletion
- Cascade delete across 16 tables on account removal
- User data export available on request
How Every Request Is Protected
Each API call passes through multiple security gates before any business logic executes.
TLS Termination
All traffic arrives over HTTPS (TLS 1.3). Plaintext connections are rejected at the load balancer. Milton does not expose any HTTP endpoints in production.
Bearer Token Validation
The Authorization: Bearer <token> header is extracted and verified against the bcrypt hash stored in api_tokens. Expired or revoked tokens are rejected with HTTP 401.
Rate Limiting
Sensitive endpoints enforce per-user rate limits (e.g., 20 delegations/hour, 60 chat messages/minute) via slowapi. Abuse attempts return HTTP 429 before reaching business logic.
RBAC Permission Check
Every write operation verifies the authenticated user holds the required role for the target resource. Failures raise HTTP 403 and are immediately written to the audit log.
Business Logic & Audit
The operation executes. On success, an audit log entry records the actor, action, resource, result, IP address, and timestamp. The audit log is write-only — entries cannot be modified or deleted within their retention window.
NIST 800-53 Control Matrix
Implementation status across all applicable control families for the NIST 800-53 Rev 5 Moderate baseline.
| Control ID | Title | Status | Implementation |
|---|---|---|---|
| AC-1 | Access Control Policy | Implemented | Formal policy document; annual review cycle |
| AC-2 | Account Management | Implemented | OAuth-based creation; 30-day deletion grace; cascade removal |
| AC-3 | Access Enforcement | Implemented | permission_service.py; 23+ RBAC checks across all routes |
| AC-6 | Least Privilege | Implemented | Default-deny; role hierarchy: owner → admin → manager → member |
| AC-11 | Device Lock / Session Timeout | Implemented | 24-hour token expiry; revocation on demand |
| AC-12 | Session Termination | Implemented | token_service.revoke_all_user_sessions(); immediate invalidation |
| AU-2 | Event Logging | Implemented | audit_service.py; 30+ event types; auth, CRUD, delegation, OAuth |
| AU-3 | Content of Audit Records | Implemented | actor_id, action, resource, result, detail, IP, user-agent, timestamp |
| AU-6 | Audit Review & Analysis | Implemented | audit_query() and audit_security_summary() for reviews |
| AU-9 | Protection of Audit Information | Implemented | Write-only log; 365-day retention; encrypted at rest |
| CM-2 | Baseline Configuration | Implemented | Git version control; Render.com immutable deployments |
| CM-7 | Least Functionality | Implemented | No debug mode in production; minimal exposed services |
| IA-2 | Identification & Authentication | Implemented | OAuth 2.0 (Google); Bearer token enforced on all protected endpoints |
| IA-4 | Identifier Management | Implemented | UUID user_id; never recycled; unique per account |
| IA-5 | Authenticator Management | Implemented | bcrypt hashing; expiry; revocation; no plaintext storage |
| SC-7 | Boundary Protection | Implemented | HTTPS-only; CORS restricted to miltonspeaks.com; DDoS mitigation |
| SC-8 | Transmission Confidentiality | Implemented | TLS 1.3 enforced end-to-end; no plaintext APIs in production |
| SC-13 | Cryptographic Protection | Implemented | AES-256-GCM; HMAC-SHA256; bcrypt; TLS 1.3 |
| SC-28 | Protection of Information at Rest | Implemented | AES-256-GCM for sensitive fields; encrypted DB backups |
| SI-2 | Flaw Remediation | Implemented | Dependabot alerts; security advisory tracking; patching SLA |
| SI-4 | System Monitoring | Implemented | Application logs; failed auth tracking; Render.com metrics |
| SI-12 | Information Management & Retention | Implemented | retention_service.py; automated nightly job at 3 AM UTC |
| IR-4 | Incident Handling | Implemented | Documented incident response plan; contact procedures defined |
| IR-6 | Incident Reporting | Implemented | Security incident notification within 72 hours |
Data Retention Policy
All data types have documented retention periods. A nightly automated job soft-deletes expired records, and permanently removes data after its grace period expires.
Infrastructure & Transmission Security
Data in transit is protected by TLS 1.3. Production infrastructure is hosted on Render.com with automated certificate management.
TLS 1.3
- TLS 1.3 enforced for all connections
- Let's Encrypt certificates, auto-renewed
- HTTP connections rejected at load balancer
- HSTS headers enforced
Production Hosting
- Render.com managed infrastructure
- Immutable deployments from Git
- PostgreSQL with encrypted backups
- No secrets committed to version control
API Boundary Protection
- CORS restricted to miltonspeaks.com
- Rate limiting on all sensitive endpoints
- DDoS mitigation via Render.com
- Parameterized SQL — no injection vectors