Security Checklist
File paths below are relative to apps/api/internal/ unless noted.
Transport
| Item | Status | Notes |
|---|---|---|
| TLS termination | ✅ Caddy handles TLS | Certs auto-renewed via ACME |
| HSTS | ✅ Caddy sets Strict-Transport-Security | 1-year max-age |
| Redirect HTTP → HTTPS | ✅ Caddy global redirect |
Authentication
| Item | Status | Notes |
|---|---|---|
| Password hashing | ✅ bcrypt (cost 10 — bcrypt.DefaultCost) | golang.org/x/crypto/bcrypt |
| JWT expiry | ✅ 24 h access token | golang-jwt/jwt/v5 |
| 2FA (TOTP) | ✅ Setup + verify + disable endpoints | services/totp.go |
| API key validation | ✅ Bearer token fallback | middleware/auth.go |
| Login lockout | ✅ 6 attempts / 10 min per IP | middleware/ratelimit.go → AuthLimiter |
| Register lockout | ✅ Same as login | Same middleware |
| Lost-password lockout | ✅ Same as login | Same middleware |
| OAuth state | ✅ HMAC-SHA256 signed state with 10 min TTL, verified on callback | handlers/oauth.go → signOAuthState / verifyOAuthState |
| Session invalidation on password change | ✅ Password reset invalidates old API key | handlers/account.go |
Input Validation
| Item | Status | Notes |
|---|---|---|
| Open-redirect guard | ✅ Allows only http/https destinations | handlers/redirect.go → isSafeRedirectURL |
| Email validation | ✅ net/mail.ParseAddress | All auth endpoints |
| UTF-8 length limits | ✅ Name ≤ 64, password ≤ 64 | handlers/auth.go |
| SQL injection | ✅ Parameterised queries throughout | pgx/v5, no string interpolation in SQL |
| File upload MIME check | ✅ Byte-sniffed via http.DetectContentType and required to agree with the declared type | handlers/uploads.go → sniffMimeType, file_links.go, static_pages.go |
| SVG uploads | ✅ Rejected (SVG can carry script); /uploads/* also served with Content-Security-Policy: default-src 'none'; sandbox + nosniff | services/storage.go, cmd/server/main.go |
| JWT weak-secret guard | ✅ Boot refuses known-weak/example secrets (case-insensitive, substring); .env.example value is length-invalid | config/config.go → weakJWTSecrets |
CSRF
| Item | Status | Notes |
|---|---|---|
| X-Requested-With header guard | ✅ Applied globally | middleware/security.go → CSRFGuard |
| Frontend sends X-Requested-With | ✅ Set as default Axios header | apps/web/src/services/api.ts |
| Exempt paths | ✅ GET/HEAD/OPTIONS, /webhook/*, /api/v1/auth/oauth/* (matched via strings.HasPrefix) | Same middleware |
Security Headers
| Item | Status | Notes |
|---|---|---|
| X-Content-Type-Options: nosniff | ✅ | middleware/security.go → SecurityHeaders |
| X-Frame-Options: DENY | ✅ | Same |
| Referrer-Policy | ✅ strict-origin-when-cross-origin | Same |
| Content-Security-Policy | ✅ default-src 'self'; script-src 'self'; frame-ancestors 'none'; object-src 'none' | Same. Style-src allows 'unsafe-inline' (design-system inline styles / CSS custom properties); img-src allows https + data:. |
| CORS allow-list | ✅ Explicit origin allow-list | main.go CORS config |
| X-Requested-With in CORS exposed | ✅ | main.go |
| User HTML sanitization | ✅ Client-side allowlist sanitizer used by RichTextEditor + biolink custom_html block | apps/web/src/lib/sanitizeHtml.ts |
Rate Limiting
| Item | Status | Notes |
|---|---|---|
| Rate limits | ✅ 60 req/min per principal (API_RATE_LIMIT_PER_MINUTE) on authenticated /api/v1 and /admin-api/v1; 300 req/min per IP on all public routes (redirects, public biolinks, webhooks) | middleware/ratelimit.go, cmd/server/main.go |
| Auth endpoint lockout | ✅ 6 attempts/10 min per IP | middleware/ratelimit.go → AuthLimiter |
| AI quota | ✅ 50 AI generations/hour per user | middleware/ratelimit.go → AIQuotaLimiter |
Admin Security
| Item | Status | Notes |
|---|---|---|
| Admin role gate | ✅ RequireAdmin middleware | middleware/auth.go |
| Admin audit log | ✅ Every POST/PUT/PATCH/DELETE logged to admin_logs | middleware/admin_audit.go + migration 000017 |
| Admin bypass maintenance/blacklist | ✅ Admins exempt | middleware/maintenance.go |
Webhook Security
| Item | Status | Notes |
|---|---|---|
| HMAC-SHA256/512 verification | ✅ All gateways with secret support | services/gateway_*.go |
| Fail-closed on missing secret | ✅ In production, an enabled gateway with no webhook secret rejects events (dev skips); startup warns which secrets are unset | services/webhook_security.go, cmd/server/main.go |
| Amount verification | ✅ Webhook total asserted against the server-computed plan price before activating a plan | handlers/webhooks.go, handlers/checkout.go → PlanPriceForFrequency |
| Duplicate rejection | ✅ webhook_logs unique (gateway, external_id) | Migration 000014 |
| Replay window | ✅ Event processing is idempotent (secondary check on payments table) | handlers/webhooks.go |
Data Protection
| Item | Status | Notes |
|---|---|---|
| Blacklist (IP / country / domain) | ✅ Middleware reads from admin settings | middleware/maintenance.go → Blacklist |
| Maintenance mode | ✅ Admin-configurable 503 | middleware/maintenance.go → MaintenanceMode |
Observability
| Item | Status | Notes |
|---|---|---|
| Request ID on every log line | ✅ X-Request-ID header + context | middleware/logging.go |
| User ID on authenticated requests | ✅ | middleware/logging.go |
| /metrics endpoint | ✅ Prometheus text format | handlers/observability.go |
| /ready probe | ✅ DB ping | handlers/observability.go |
Outstanding / Deferred
| Item | Priority | Notes |
|---|---|---|
| Hashed / scoped / revocable tokens | ✅ | ADR-0002: api_tokens (migration 000024) stores a digest only; scopes are checked by middleware |
| Safe Browsing API check on new link URLs | P2 | Would reject known malware/phishing URLs at creation time |
| ✅ shipped v1.0.0 | middleware/security.go | |
| GDPR export | ✅ shipped v1.0.0 | GET /api/v1/account/export returns a full per-user data dump |
| Encrypted gateway secret storage | P3 | Gateway secrets currently in env vars — adequate for single-host deploy |
| SQLi sweep (automated) | P3 | No dynamic query building found in codebase audit; parameterised throughout |
Source: docs/SECURITY.md