Most API security checklists read like compliance posters: “validate input,” “use authentication,” “enable rate limiting.” Every engineer nods, ticks the box, and still ships a server that buffers 266 MiB from unauthenticated strangers or lets one tenant read another tenant’s rows.
When we ran an independent outside security review across our first five Rust services (Colophon CMS, Service Monitor, Durable Runner, jsrt, and MiniBTC), that review found 151 gaps (50 High)—and follow-up reviews caught fresh bugs inside the security fixes themselves (the fixes landed, and the reviews found bugs in the fixes).
Below is the API security checklist we actually run before exposing a service to the internet—paired with the concrete attack test that proves each control works.
1. Authentication & session boundaries
| Control | What breaks if you skip it | Concrete test that proves it holds |
|---|---|---|
| Authenticate headers before reading bodies | 256 unauthenticated 1 MB uploads spiked our collector from 6.4 MiB to 266.0 MiB (AI Ops Layer) | Flood an authenticated endpoint with 1 MB bodies and an invalid token; assert 401 immediately and flat memory |
| Hash stored tokens & secrets | A read-only DB leak turns into full account takeover (Railway & PingCAP lessons) | Inspect the DB row for an API key or session token; assert only a one-way hash (Argon2id or SHA-256) is stored |
Strict OAuth 2.1 + PKCE (S256) | Intercepted authorization codes get replayed by another client (OAuth PKCE explained) | Replay a used authorization code or send a mismatched code_verifier; assert 400/401 and token revocation |
| No token resurrection across async caches | An in-flight cache fill across .await re-inserts a token revoked milliseconds earlier (async cache race) | Race a slow cache-miss read against a revocation call; assert the revoked token stays rejected |
| Per-account / per-client login throttles | One global login bucket let noise lock out 19 of 20 legitimate logins in Service Monitor | Hammer wrong passwords for User A; assert User B on another IP still logs in cleanly |
2. Authorization & multi-tenant isolation
-
Default-deny every route and tool. Require explicit permission declarations; unknown routes, methods, or MCP tool names return
403/404. -
Enforce tenant boundaries in the database, not just
WHEREclauses. Use PostgreSQL Row-Level Security (RLS) and least-privilege DB roles so even a buggy query cannot return another tenant’s rows or unpublished drafts. - Check object ownership on every read, update, and delete (BOLA / IDOR).
- Separate public cache from authenticated reads. Member-gated or role-gated responses must bypass shared CDN and in-memory caches completely so a gated row is never served to a stranger.
Attack test: Create Tenant A and Tenant B in the same database. Call every read, list, update, delete, search, and export endpoint with Tenant B’s token using Tenant A’s record IDs. Every single call must fail with 403 or 404—and the test must turn red when you disable the RLS policy.
3. Input bounds, parsers, and resource ceilings
- Hard request body ceiling enforced at the HTTP layer (e.g., 64 KiB for JSON APIs, separate streaming ceiling for media uploads).
- Query/AST depth and complexity caps on GraphQL, filter expressions, or recursive JSON—and fuzz the cap itself (our first GraphQL limit in Colophon introduced a parser crash reachable by any signed-in user).
-
Strict Content-Type and UTF-8 / NUL-byte validation. Reject or isolate
\0bytes before they poison a whole PostgreSQL batch. -
Explicit timeouts on headers, bodies, and write stalls. Align upstream timeouts with your reverse proxy so idle keep-alive sockets aren’t killed mid-request (hyper
header_read_timeouttrap), and close connections that stop reading after a write-stall deadline (e.g., 10 seconds). -
Reserved slug / route collision tests. Prevent user-created slugs like
admin,media, oroauthfrom shadowing application routes (reserved slugs CI test).
4. Rate limiting & abuse protection
-
Key on real client IP only from an explicit
TrustedProxieslist. Never trustX-Forwarded-FororCF-Connecting-IPfrom arbitrary peers (why every rate limiter behind Caddy saw 127.0.0.1). -
Bound the rate-limiter map and aggregate IPv6 by
/64+/48. Unbounded IP maps OOM under spray attacks; keying IPv6 by/128hands an attacker 2^64 fresh buckets (API rate limiting implementation). - Separate connection limits for normal peers vs. reverse proxies.
- Require idempotency keys on payment, webhook, and state-creating mutations so retries never double-charge or duplicate records.
5. Outbound calls, webhooks, and SSRF
- Block SSRF inside the DNS resolver, not before the HTTP call. Checking a URL before dialing fails against DNS rebinding, multi-record DNS answers, redirects, and IPv4-mapped IPv6 literals (preventing webhook SSRF and DNS rebinding).
- Sign outgoing webhooks and verify incoming ones using HMAC-SHA256, constant-time comparison, and a tight replay timestamp window (webhook security best practices).
- Restrict outbound redirects (disable on webhooks, or re-validate every hop against the same IP/scheme blocklist).
6. Secrets, headers, and auditability
-
Redact secrets before logs, traces, or LLM context. Test redaction against escaped JSON, URL-encoded tokens, camelCase keys, and raw
Authorizationheaders—not just a naive regex. -
Strip sensitive fields from error responses. Return structured error codes (
unauthorized,conflict,rate_limited) without stack traces, SQL errors, or internal hostnames. -
Set strict response headers:
Strict-Transport-Security,X-Content-Type-Options: nosniff,Content-Security-Policy, andReferrer-Policy. - Isolate audit logs onto their own DB pool so an error flood or denial burst cannot starve security logging or token revocation.
- Automate dependency vulnerability audits in CI daily (not only on push—new CVEs land even when your code doesn’t change).
7. Watch every security test fail once
The most common failure in API security testing isn’t missing tests—it’s tests that always pass even when the guard is broken. Before trusting any item on this checklist:
- Temporarily disable the auth check, RLS policy, rate limiter, or SSRF guard.
- Run the attack test and confirm it turns red.
- Restore the guard and confirm it turns green (how we proved our security attack tests actually fail).
Frequently asked questions
What is the fastest way to audit an existing REST API for security gaps?
Start with the four highest-impact checks: (1) cross-tenant IDOR tests with two real accounts, (2) sending an invalid token with a large body to confirm auth runs before buffering, (3) testing rate limits behind your actual reverse proxy so you verify real client IP propagation, and (4) hitting every URL-accepting endpoint with http://127.0.0.1/ and http://169.254.169.254/.
Should API rate limiting live at the reverse proxy/gateway or inside the application? Use both. Put coarse DDoS and connection ceilings at the edge (Cloudflare / Caddy / API Gateway), and put tenant-aware, user-aware, and expensive-endpoint budgets inside your application where identity and domain cost are known.
Does using HTTPS and JWTs cover API security? No. TLS protects transport and JWTs carry claims, but neither stops BOLA/IDOR cross-tenant reads, SSRF, unbounded body memory exhaustion, token revocation races, or missing idempotency on retries.