Skip to main content

Incident · Mid

Cloudflare: a regex exhausts the CPU

A WAF rule with backtracking hit the entire network at once. What the rollout was missing.

11 min read · Incident on 2019-07-02, lasted ~30 min · Source: Cloudflare · Content reviewed on October 23, 2026

Short answer

A WAF rule with backtracking hit the entire network at once. What the rollout was missing. In its official post-mortem, Cloudflare says it deployed a new rule in the WAF Managed Rules, the web application firewall that inspects HTTP requests.

01 · CONTEXT

A new WAF rule, shipped worldwide

In its official post-mortem, Cloudflare says it deployed a new rule in the WAF Managed Rules, the web application firewall that inspects HTTP requests. The rule contained a regular expression that caused enormous backtracking and exhausted the CPU used to serve HTTP and HTTPS. The effect was that the CPU of the network's servers neared its limit everywhere, and customers (and their customers) saw a 502 error page when visiting any of the company's domains.

  1. In normal operation, each request reaches an edge server and goes through the WAF before moving on.

    Architecture diagram: Edge request with WAF
    CLVisitantes
    EDGEdge server
    NWWAF
  2. With the new rule, the WAF starts consuming too much CPU on each edge server, and requests end in errors.

    Architecture diagram: Edge request with WAF
    CLVisitantes
    EDGEdge servererror to the client
    NWWAFCPU exhausted

02 · THE REGEX

Backtracking: when matching text costs too much time

The post describes the cause as a poorly written regular expression that created excessive backtracking. The critical part cited is a fragment that greedily combines zero or more characters followed by another zero or more characters and an equals sign. Greedy means matching as much as possible. This is a classic example of a performance antipattern: the cost of a seemingly simple operation depends on the shape of the input.

  1. Each request is compared against the rules, including the new regular expression.

    Architecture diagram: Regex evaluation on the server
    CLRequest
    CPRegex engine
    CPServer CPU
  2. The regex engine tries many combinations before deciding, and the work falls on the server's CPU.

    Architecture diagram: Regex evaluation on the server
    CLRequest
    CPRegex engineretrocesso
    CPServer CPU
  3. The CPU becomes saturated and there is no capacity left to serve legitimate traffic.

    Architecture diagram: Regex evaluation on the server
    CLRequest
    CPRegex engine
    CPServer CPUsaturada

03 · RELEASE

A change path that skipped staged rollout

The bad regex only became a global incident because of how it was released. The standard procedure for a rule change allowed, according to the post, for it to be pushed globally, and let a non-emergency change reach production worldwide without staged rollout. The WAF does not use the staged process by design, due to the need to respond quickly to threats. In addition, the test suite had no way to identify excessive CPU consumption, and the rule passed through it with no sign of a problem. What was missing here was a very common availability patterns practice: limiting the blast radius of a change before it reaches the whole fleet.

AspectoThe company's regular softwareWAF rules
ReleaseStaged, according to the postGlobal and immediate, per the procedure at the time
MotivationLimit the impact of defectsRespond quickly to threats
  1. The engineer publishes the rule and the distribution mechanism sends it to the entire server fleet at once.

    Architecture diagram: Global rule publication
    CLEngenheiro
    QRule distributionglobal
    EDGEdge fleet
  2. With no intermediate stage to observe the effect, all servers receive the rule at the same time.

    Architecture diagram: Global rule publication
    CLEngenheiro
    QRule distribution
    EDGEdge fleetentire fleet

04 · RECOVERY

Turning the component off instead of fixing it

According to the post, the change was made at 13:42, and the first PagerDuty alert indicating a WAF failure went out three minutes later. In the first moments there was speculation about an attack of a kind never seen, which shows how a saturated-CPU symptom can be mistaken for external aggression. The way out was an existing mechanism for disabling a single component worldwide: a team member executed the global WAF shutdown at 14:07, and by 14:09 traffic and CPU were normal everywhere. The company sums up the episode as 27 minutes of downtime. This kind of emergency switch is a form of monitoring and observability put into action: the alert points to the suspect component, and the shutdown limits the damage.

  1. The alert points to a WAF failure and the team starts investigating, even considering an attack.

    Architecture diagram: Detection and global shutdown
    NWAlertaalerta
    CLOn-call team
    NWWAF kill switch
    EDGEdge fleet
  2. The team triggers the global switch that disables the WAF across the whole network.

    Architecture diagram: Detection and global shutdown
    NWAlerta
    CLOn-call team
    NWWAF kill switchWAF off
    EDGEdge fleet
  3. With the WAF no longer consuming CPU, the fleet returns to expected behavior.

    Architecture diagram: Detection and global shutdown
    NWAlerta
    CLOn-call team
    NWWAF kill switch
    EDGEdge fleetnormalizada

05 · LESSONS

What to take to your project

Among the remediation actions listed in the post are reintroducing the protection against excessive CPU use that had been removed, including performance profiling of all rules in the test suite, and changing the procedure so rules go through staged rollout, like the rest of the company's software. From the angle of chaos engineering, it is worth asking which failures of your own release path you have rehearsed.

Frequently asked questions

What is Cloudflare: a regex exhausts the CPU?

A WAF rule with backtracking hit the entire network at once. What the rollout was missing.

What does the Cloudflare: a regex exhausts the CPU design cover?

It is organized in these sections: A new WAF rule, shipped worldwide, Backtracking: when matching text costs too much time, A change path that skipped staged rollout, Turning the component off instead of fixing it, and What to take to your project.

How long is Cloudflare: a regex exhausts the CPU and what level is it?

It takes about 11 minutes to read and is rated Mid level.

Now design it yourself

Run this case as an interview in the System Design school: you make the decisions, the tutor challenges them and you see how your design scores.