Security Model

This document describes the threat model, security boundaries, encryption mechanisms, and compliance direction for the Hippocortex platform.

Security Principles

  1. Deny by default: All access requires explicit authentication and authorization
  2. Least privilege: Users and agents receive the minimum permissions necessary
  3. Defense in depth: Multiple security layers (network, auth, RBAC, encryption)
  4. Auditability: Security-relevant actions are logged with actor identity and timestamp
  5. Data isolation: Tenant data is strictly isolated at the query layer
  6. No trust in input: All API input is validated and sanitized

Threat Model

Threat Actors

ActorCapabilityMotivation
External attackerNetwork access, public API endpointsData theft, service disruption
Compromised agentValid API key, scoped accessData exfiltration beyond allowed scope
Malicious insiderValid user credentials, org membershipUnauthorized data access
Compromised dependencyCode execution in build/runtimeSupply chain attack
Cloud providerInfrastructure accessData access (mitigated by encryption)

Attack Surface

+----------------------------------------------------------+
|  EXTERNAL ATTACK SURFACE                                  |
|                                                          |
|  [HTTPS endpoints]                                       |
|    api.hippocortex.dev                                   |
|    dashboard.hippocortex.dev                             |
|    docs.hippocortex.dev                                  |
|                                                          |
|  [Authentication]                                        |
|    Clerk (OAuth/SSO), JWT, API Keys                      |
|                                                          |
|  [API Input]                                             |
|    JSON request bodies, query parameters, headers        |
+----------------------------------------------------------+

+----------------------------------------------------------+
|  INTERNAL ATTACK SURFACE                                  |
|                                                          |
|  [Container-to-container]                                |
|    Docker bridge network (no public exposure)            |
|                                                          |
|  [Data stores]                                           |
|    PostgreSQL (encrypted at rest via disk encryption)    |
|    Redis (in-memory, persistence to disk)                |
|                                                          |
|  [Environment variables]                                 |
|    VAULT_MASTER_KEY, API keys, database credentials      |
+----------------------------------------------------------+

Threat Scenarios and Mitigations

#ThreatImpactLikelihoodMitigation
T1Stolen API keyUnauthorized memory accessMediumKey rotation, scope restrictions, rate limiting
T2JWT forgeryIdentity spoofingLowRSA/EC signature verification, short expiry
T3SQL injectionData breachLowParameterized queries only, no raw SQL
T4XSS in dashboardSession hijackLowCSP headers, input sanitization, HttpOnly cookies
T5SSRF via captureInternal network scanMediumInput URL validation, no server-side fetching of user URLs
T6Credential leak in memorySecret exposureHighAutomatic secret detection and vault redaction
T7Cross-tenant data accessData breachLowRow-level tenant filtering, no cross-tenant queries
T8Brute force authAccount takeoverMediumRate limiting, Clerk lockout policies
T9Database backup theftData breachLowEncrypted backups, restricted backup access
T10DDoSService unavailabilityMediumRate limiting, Traefik configuration, Hetzner DDoS protection

Security Boundaries

Network Boundaries

Public Internet
       |
       | TLS 1.2+ only
       v
+------------------+
|     Traefik      |  <-- Boundary 1: TLS termination
|  (reverse proxy) |      HTTP to HTTPS redirect
+--------+---------+      CORS enforcement
         |
         | HTTP (internal)
         v
+------------------+
|   API Server     |  <-- Boundary 2: Authentication
|   (Hono)         |      RBAC enforcement
+--------+---------+      Input validation
         |
         | Authenticated queries
         v
+------------------+
|   Data Layer     |  <-- Boundary 3: Data isolation
|  (PostgreSQL)    |      Row-level tenant filtering
|  (Redis)         |      Encrypted vault items
+------------------+

Authentication Boundary

All API endpoints (except health checks) require authentication:

Endpoint CategoryAuth RequiredMethod
Health checks (/health, /ready)NoNone
Public API (/v1/*)YesJWT, API Key, or Clerk token
Admin API (/admin/*)YesX-Admin-Key header
Dashboard APIYesClerk session token
Metrics (/metrics)NoInternal network only

Authorization Boundary

After authentication, the RBAC layer enforces permissions:

  1. Organization membership: User must be a member of the organization
  2. Role-based permissions: User's org role must include the required permission
  3. Namespace scoping: Memory operations are restricted to accessible namespaces
  4. Agent scoping: Agent access is restricted to configured allowedScopes
  5. Vault permissions: Vault access requires explicit permission grants

Encryption

In Transit

ConnectionEncryption
Client to TraefikTLS 1.2+ (Let's Encrypt certificates)
Traefik to APIHTTP (internal Docker network, no public exposure)
API to PostgreSQLOptional TLS (configured via POSTGRES_SSL)
API to RedisOptional TLS (configured via REDIS_TLS)

At Rest

DataEncryption
Vault itemsAES-256-GCM with per-item random IV
Vault notesAES-256-GCM (same key, separate IV)
DatabaseDisk-level encryption (Hetzner server encryption)
Backupspgdump with server-side encryption
Redis persistenceDisk-level encryption

Key Management

KeyStorageRotation
VAULT_MASTER_KEYEnvironment variableManual (re-encrypt all items)
API keys (hx_live_*)Hashed in PostgreSQLUser-initiated
JWT signing keyClerk-managedClerk rotation policy
TLS certificatesLet's Encrypt (auto-renewed)90-day auto-rotation

Input Validation

API Input

All API input is validated using Zod schemas:

  • Request body JSON is parsed and validated against typed schemas
  • Query parameters are type-checked and range-validated
  • Path parameters are validated (UUID format, slug format)
  • Headers are validated (Authorization format, content types)

Content Limits

LimitValuePurpose
Request body size1 MBPrevent memory exhaustion
Capture text length100,000 charsReasonable memory size
Query string length10,000 charsPrevent oversized queries
Tags per item50Prevent tag abuse
Tag length100 charsReasonable tag size

Secret Detection in Input

The secret detection engine scans all captured text for credentials before storage. Detected secrets are:

  1. Extracted and stored in the vault
  2. Replaced with vault references in the stored memory
  3. Never stored in plaintext in the memory tables

Rate Limiting

TierRate LimitScope
Free100 req/minPer API key
Pro1,000 req/minPer API key
EnterpriseCustomPer API key or per organization

Rate limiting is enforced at the API middleware layer using Redis-backed sliding window counters.

Responses include rate limit headers:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 847
X-RateLimit-Reset: 1710460800

Audit Logging

What Is Logged

CategoryEvents
AuthenticationLogin, logout, failed login, token refresh
AuthorizationPermission granted, permission denied
Data accessMemory read, memory write, memory delete
VaultSecret created, revealed, updated, deleted
AdminTenant management, user management, queue operations
ConfigurationPolicy changes, namespace changes, role changes

Audit Log Properties

  • Immutable: Audit entries cannot be modified or deleted through the API
  • Timestamped: UTC timestamps with millisecond precision
  • Actor-attributed: Every entry includes the authenticated actor's identity
  • Retention: Enterprise plan audit logs are retained indefinitely

Compliance Direction

Hippocortex is designed with compliance frameworks in mind, though formal certifications are not yet obtained:

FrameworkStatusRelevant Controls
SOC 2 Type IIPlannedAccess controls, encryption, audit logging
GDPRPartialData isolation, retention policies, deletion support
HIPAAPlannedEncryption at rest, audit trail, access controls
ISO 27001PlannedSecurity boundaries, risk assessment, incident response

Data Residency

Current deployment: Single-region (Hetzner, Germany/EU). All data resides in the EU.

Future: Multi-region deployment with data residency controls per tenant.

Data Deletion

Hippocortex supports data deletion for compliance:

  • Memory deletion: Individual memories can be deleted via API
  • Namespace deletion: All memories in a namespace can be deleted
  • Tenant deletion: All tenant data can be purged (admin action)
  • Retention policies: Automatic deletion after configurable retention periods

Incident Response

The incident response procedure covers:

  • Security incident classification
  • Escalation procedures
  • Communication templates
  • Post-incident review process