Security¶
Security at the API edge is built on defense in depth — no single control is trusted to stop every attack. The layers that protect a request, in the order they apply:
- CDN / load balancer TLS termination (handled outside the backend)
- CORS —
cors.New(...)ininternal/wiring/router.go - SecurityHeaders (
middleware/security.go) —X-Content-Type-Options,X-Frame-Options,Referrer-Policy, HSTS in production - IPBlocker.BlockMiddleware — rejects any IP on the block list (never internal addresses; probe endpoints sit ahead of the whole chain)
- IPBlocker.SuspiciousActivityMiddleware — pattern-match SQL injection / path traversal / excessively long requests
- RateLimiter — per-IP per-route counters in Redis (internal addresses exempt)
- JWTAuth (
middleware/auth.go) — bearer token validation, setsuser_id,account_type,roleon the context - Access policies (
internal/access):access.Authorizer.Requiregates every Backstage route on a capability of the caller's current role, read from the database; partner routes use membership gates - Handler-level validation — request binding, business rules, ownership checks
Beyond per-request defense:
- Bcrypt for password hashing (
golang.org/x/crypto/bcrypt) - JWT with HMAC-SHA256, server-side
JWT_SECRET - WebAuthn / Passkeys as the primary passwordless option
- Device fingerprint registration limits — 3 accounts per device per 30 days
- OTP for email verification, password reset, and email change
- GDPR delete path with full account purge
Explore¶
- Rate Limiting: implementation of the per-IP limiter
- IP Blocker: attack-pattern rejection, progressive blocks, signed Workers, client IP resolution
- Device Fingerprint — per-device registration ceiling
- Threat Model — categorised threats and their mitigations
For the public-facing contract of rate limits (what 429 means for a client), see API → Auth Endpoints. For the incident playbook, see Getting Started (app-side procedures) and the DevOps Runbook (cluster-side).