Modern web platforms increasingly isolate presentation onto fast static edges while keeping state, billing, and business mutations behind REST or GraphQL APIs. That separation dramatically shrinks the HTML attack surface, yet concentrates almost every critical data-protection obligation squarely onto your API endpoints.

Across real security reviews, API vulnerabilities rarely look like Hollywood cryptography breaks. Instead, attackers exploit predictable object identifiers, missing rate limits on OTP and login routes, overly broad ORM field binding, or weak webhook verification. Here is a defence-in-depth hardening checklist engineers can implement without re-architecting their stack.

1. Close Object-Level Authorization Gaps (BOLA / IDOR) at the Query Layer

Checking that a request carries a valid session cookie or JWT only proves authentication (who the caller is). It says nothing about authorization (whether that caller owns the target record). Under pressure to ship CRUD endpoints quickly, developers routinely write lookups using only the resource primary key:

-- Fragile: fetches any customer invoice if the ID is guessed or enumerated
SELECT * FROM invoices WHERE id = $1;

-- Hardened: enforces tenant ownership inside every query predicate
SELECT * FROM invoices WHERE id = $1 AND organization_id = $2;

Never trust an organization_id or user_id submitted inside the HTTP request body or query string when querying tenant resources. Derive the tenant context exclusively from the verified server-side session or cryptographically signed token claim, and bind it inside the repository or ORM helper so no developer can accidentally omit the scope.

2. Deploy Two-Tier Rate Limiting at the Edge & Reverse Proxy

Authentication routes (/login, /password-reset, /otp-verify), search endpoints, and export webhooks attract automated credential stuffing and scraping. Stopping volumetric abuse before requests reach your Node, Python, or Go worker pool keeps CPU predictable even during active probing.

With nginx in front of your upstream API, separate strict zones for sensitive auth paths from general API endpoints:

# /etc/nginx/conf.d/rate_limits.conf
limit_req_zone $binary_remote_addr zone=api_general:10m rate=20r/s;
limit_req_zone $binary_remote_addr zone=auth_strict:10m rate=3r/m;
limit_req_status 429;

server {
    location /api/v1/auth/ {
        limit_req zone=auth_strict burst=5 nodelay;
        proxy_pass http://api_upstream;
    }

    location /api/v1/ {
        limit_req zone=api_general burst=40 nodelay;
        proxy_pass http://api_upstream;
    }
}

Remember to pair proxy rate limits with HTTP 429 Too Many Requests and clear Retry-After headers so well-behaved client integrations back off gracefully rather than retrying in tight loops.

3. Reject Unknown Properties with Strict Schema Validation

Mass assignment (OWASP API3) occurs when an endpoint passes raw parsed JSON straight into an ORM model update. If a user updates their profile with {"name": "Ada", "role": "admin", "plan_tier": "enterprise"} and your handler forwards the entire object, an attacker silently escalates privileges.

API Security Boundary Checklist: Defense-in-Depth Layers
Layer Primary Threat Stopped Concrete Hardening Rule
TLS & Reverse ProxyEdge / nginx Credential stuffing & payload floodsSlowloris, huge multipart uploads, brute force TLS 1.2/1.3 + Body Size CapsSet client_max_body_size 2m; and strict limit_req_zone rules
Schema ParserZod / Pydantic / JSON Schema Mass assignment & type confusionInjecting internal status, balance, or role keys Strip Unknown Keys (Strict Mode)Explicitly whitelist fields accepted on every POST/PATCH handler
Token VerifierAuth middleware JWT algorithm confusion & stale tokensUnsigned tokens, replay after user offboarding Pin Allowed Algorithm & Short TTLPin algorithms=["EdDSA"] or ["HS256"]; enforce iss/aud/exp
Data Access LayerSQL / ORM helpers BOLA / IDOR & SQL injectionCross-tenant record reads and deletions Mandatory Tenant PredicatesRequire parameterized bindings + verified org_id on all queries

4. Verify Outbound & Inbound Webhooks Cryptographically

Payment processors, authentication providers, and CRM integrations rely on incoming HTTP webhooks to trigger order fulfillment or account provisioning. Never trust an inbound webhook simply because it hits an obscure URL or carries an expected JSON payload.

Enforce three mandatory checks on every webhook receiver:

  1. Verify the HMAC-SHA256 or Ed25519 signature over the raw unparsed byte payload using constant-time comparison (crypto.timingSafeEqual or hmac.compare_digest) to prevent timing side-channels.
  2. Reject event timestamps older than 5 minutes to prevent replay attacks from captured network logs.
  3. Track processed webhook event_id keys inside an idempotent table so duplicate retries never double-credit balances or trigger duplicate dispatches.

5. Lock Down Error Payloads and CORS Policies

Verbose stack traces, raw SQL constraint errors, and permissive CORS headers (Access-Control-Allow-Origin: * combined with credentials) expose internal database table names, dependency versions, and session cookies to automated scanners. Return stable, generic JSON error codes (such as {"error": "forbidden", "request_id": "req_91a8"}) to callers while logging rich diagnostic context exclusively inside your protected server logs.

Explicitly enumerate trusted frontend origins in CORS middleware, restrict allowed methods to the exact HTTP verbs implemented by the route, and strip X-Powered-By and verbose Server version banners cleanly across your reverse proxy layer.