Your CDN can do more than just serve static assets; it can become your first line of defense against sophisticated Layer 7 attacks.

Let’s see this in action. Imagine a common scenario: a surge of requests targeting your API’s /login endpoint, not with brute force, but with malformed payloads designed to exploit a specific vulnerability.

{
  "request": {
    "method": "POST",
    "url": "/login",
    "headers": {
      "Content-Type": "application/json"
    },
    "body": "{\"username\": \"admin\", \"password\": \"<script>alert('XSS')</script>\"}"
  },
  "response": {
    "status": 200,
    "body": "{\"success\": true, \"token\": \"abc123xyz\"}"
  }
}

This looks like a legitimate login attempt, but the password field contains a cross-site scripting (XSS) payload. A WAF deployed on your CDN intercepts this before it even reaches your origin servers.

Here’s how the WAF rules might look, blocking this specific attack:

{
  "rule_id": "XSS_LOGIN_PAYLOAD",
  "description": "Block login attempts with script tags in the password field.",
  "match": {
    "request_method": "POST",
    "request_uri": "/login",
    "request_body": {
      "contains": "<script>"
    },
    "request_headers": {
      "Content-Type": "application/json"
    }
  },
  "action": "block"
}

The WAF, acting as a reverse proxy at the CDN edge, inspects incoming HTTP requests. It applies a set of predefined or custom rules to each request. If a request matches a rule defined with an action of block, the WAF immediately terminates the connection and returns a predefined error response (e.g., HTTP 403 Forbidden) to the client. This prevents malicious traffic from ever reaching your application infrastructure.

The core problem this solves is the distributed nature of modern web applications and the increasing sophistication of Layer 7 attacks. By placing the WAF at the CDN, you leverage the CDN’s global network to absorb and deflect attacks closer to their source, reducing latency and the load on your origin. This is particularly effective against volumetric attacks that might overwhelm a single WAF appliance or a WAF deployed only at the data center.

The mental model to build here is one of layered security, where the CDN becomes an intelligent security gateway. You’re not just caching content; you’re actively filtering traffic based on application-layer intelligence. This involves understanding:

  • Rule Logic: How to define precise conditions for matching malicious requests (e.g., specific URI patterns, HTTP methods, header values, or request body content).
  • Action Types: What to do when a match is found (block, log, allow, redirect, rate-limit).
  • Deployment Modes: Whether to deploy as a transparent proxy (most common for CDNs) or an explicit proxy.
  • Integration with Origin: How to ensure legitimate traffic still flows while blocking threats.

A common misconception is that WAFs are purely about blocking known attack signatures. While signature-based detection is crucial, advanced WAFs on CDNs also employ behavioral analysis and anomaly detection. They can learn what "normal" traffic looks like for your application and flag deviations that might indicate zero-day exploits or novel attack vectors, even if no specific signature exists yet. For instance, a sudden, massive spike in requests to an obscure API endpoint from a single IP, or requests with unusually large payload sizes, might be flagged as suspicious.

The next step is often implementing rate limiting to prevent brute-force attempts and denial-of-service attacks that might evade signature-based rules.

Want structured learning?

Take the full Cdn course →