API Gateways, Traffic Management & the Edge›09 · Edge security

Lesson 09 of 13 · Designing the edge

Edge security

Layer the defences in front of your APIs: DDoS protection for floods, a WAF for known attack patterns (and how to roll it out without blocking real users), bot management, TLS policy and security headers, request limits, CORS, IP rules, origin protection so attackers can't go around the edge, and the API-specific risks a WAF can't see.

Intermediate → Advanced
Key wordsedge securityWAFweb application firewallOWASP Core Rule Setfalse positivesdetection modeblocking modebot managementcredential stuffingDDoSvolumetric attackL3/L4L7 floodorigin protectionTLS policyTLS 1.3HSTSsecurity headersCORSIP allow listsrequest size limitsOWASP API Security Top 10

Defence in layers

No single control stops every attack. Each layer stops what it's good at, as early and as cheaply as possible:

internet
  │  DDoS protection     floods: network (L3/L4) and HTTP (L7)
  │  WAF                 known attack patterns in requests
  │  bot management      automated abuse: scraping, credential stuffing
  ▼
edge / CDN  ── TLS policy, security headers, size limits
  │  origin protection   only the edge may reach the origin
  ▼
API gateway ── authentication, per-client rate limits, timeouts (lessons 5 to 7)
  ▼
services   ── authorization on every object, input validation, safe queries

A castle has a moat (stops armies: DDoS protection), guards at the gate who know what weapons look like (WAF), watchers who notice someone trying every door (bot management), and a locked side door nobody can use (origin protection). Inside, each room still has its own lock (authorization in services), because a guest who got in legally may still try the wrong door.

DDoS protection

Type Example Defence
Volumetric (L3/L4) Huge UDP or SYN floods Provider edge networks absorb them (cloud DDoS services, CDN capacity); you can't fight this in your cluster
Protocol Slow connections, malformed packets Edge proxies, connection timeouts, SYN cookies
Application (L7) Many valid-looking HTTP requests to an expensive endpoint Rate rules at the WAF or edge, per-client limits at the gateway, caching, challenges

Plan for it: know your provider's DDoS service and response team, and have a runbook (lower rate rules, enable challenges, block regions temporarily).

The WAF

A web application firewall inspects requests for known attack patterns: SQL injection, cross-site scripting, path traversal, command injection, protocol violations. Most use managed rule sets, commonly based on the OWASP Core Rule Set, plus your own rules.

Roll it out carefully:

  1. Enable in detection (count) mode; let real traffic flow for days.
  2. Review what would have been blocked; add exclusions for false positives (for example, a field that legitimately contains SQL-like text or HTML).
  3. Switch to blocking, one rule group at a time, starting with the most reliable.
  4. Keep dashboards of blocked requests, and a fast way to disable a rule that's hurting users.

Generic rules have higher paranoia levels that catch more attacks and more false positives; most APIs start at the lowest level.

Bots and abuse

  • Credential stuffing: login attempts with leaked passwords from other sites. Defences: rate limits per account and per IP, bot detection, MFA, breached-password checks.
  • Scraping and inventory hoarding: per-client limits, behaviour analysis, challenges for suspicious clients.
  • Allow good bots (search engines, uptime monitors, partner integrations) by verified identity, not by user-agent string.

TLS policy and security headers

  • TLS 1.2 minimum, TLS 1.3 preferred; modern cipher suites only; automatic certificate renewal (see the security basics course).
  • HSTS (Strict-Transport-Security: max-age=31536000; includeSubDomains) so browsers never fall back to HTTP.
  • For browser-facing responses: Content-Security-Policy, X-Content-Type-Options: nosniff, Referrer-Policy, frame-ancestors (in CSP) against clickjacking.
  • CORS: allow only the browser origins that need your API; never * with credentials. Envoy Gateway's SecurityPolicy has a cors section.

Request limits

  • Maximum request body size (and per-endpoint exceptions for uploads).
  • Maximum header size and count, URL length.
  • Timeouts for slow clients (slowloris-style attacks hold connections open).
  • Allowed methods per route (an API that only reads should reject DELETE at the gateway).

Origin protection: no way around the edge

All of the above is useless if attackers can reach your origin directly. Options, strongest first:

  1. Private connectivity from the edge to the origin (private link or similar), with no public origin address.
  2. mTLS between edge and origin: the origin accepts only the edge's client certificate.
  3. Provider IP ranges plus a secret header that the edge adds and the origin checks (rotate the secret).

Then test it: try to reach the origin directly from the internet; it must fail.

What the WAF can't see: API risks

The most common API breaches use valid-looking requests. The OWASP API Security Top 10 lists them; the top items are about authorization and business logic:

Risk Example Where to fix
Broken object-level authorization Change /orders/42 to /orders/43 and see someone else's order The service: check ownership of every object
Broken authentication Tokens that never expire, weak password reset Identity provider, gateway JWT checks (lesson 5)
Excessive data exposure Response includes fields the client shouldn't see The service: explicit response schemas
Lack of resource limits One request asks for 1,000,000 records Pagination limits, rate limits (lesson 6)
Broken function-level authorization A normal user calls an admin endpoint Route-level rules at the gateway plus checks in the service

Try it

  1. List every way to reach your origin (load balancer address, node ports, other DNS names) and how each is blocked.
  2. Check a site you run with an SSL test service and a security-header scanner; fix the top two findings.
  3. Write WAF rollout steps for your API: which rule groups first, how long in count mode, who reviews false positives, how to roll back a rule.
  4. In the lab cluster, add a SecurityPolicy with cors that allows only https://app.example.test, and check the Access-Control-Allow-Origin header for allowed and other origins.

Going deeper

  • Put WAF rules in code (Terraform, policy files) and roll them out through environments like any change; a bad WAF rule is an outage.
  • Use separate rule sets for browser traffic and machine-to-machine APIs: they look very different.
  • Feed blocked-request logs into your security monitoring, with the request ID that follows the request through every hop.

Recap

  • Layer defences: DDoS protection, WAF, bot management, TLS policy and headers, request limits, gateway authentication and rate limits.
  • Roll out WAF rules in detection mode first; tune false positives; then block.
  • Protect the origin so nobody can bypass the edge, and test it.
  • The biggest API risks are authorization and business-logic flaws that only services can stop.

This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.