Blog / One Bad Regex — Lessons From the July 2 Cloudflare Outage
cloudflare outages incidents deployment

One Bad Regex — Lessons From the July 2 Cloudflare Outage

A WAF rule with catastrophic backtracking pushed every Cloudflare edge CPU to 100% and served 502s worldwide. What the outage teaches every team.
The CompleteStatus Team · · 6 min read
One Bad Regex — Lessons From the July 2 Cloudflare Outage
Want this checked continuously?
CompleteStatus grades your headers, SSL and email security 24/7 — free, commercial use allowed.
Monitor your site free

Last Tuesday, July 2, a very large slice of the web disappeared behind a wall of 502 errors — all at once, everywhere. For roughly half an hour, sites fronted by Cloudflare returned "502 Bad Gateway" to their visitors while their own origin servers sat idle and healthy. The cause wasn't an attack, a fiber cut, or a datacenter fire. It was a single new rule in Cloudflare's Web Application Firewall containing a regular expression that, under backtracking, ate 100% of the CPU on effectively every machine in Cloudflare's global edge — simultaneously.

Two weeks ago it was a BGP route leak taking traffic hostage; this time the internet's weather came from a config deploy. Cloudflare, to their real credit, published a frank postmortem the same day naming the cause and their own process failures. Between their transparency and the sheer clarity of the failure mode, this incident is a free masterclass. Here are the lessons worth stealing.

What happened, briefly

Cloudflare regularly ships new WAF rules to respond to emerging threats — and the pipeline for those rules is deliberately fast, because blocking a fresh exploit is time-sensitive. On July 2, one new rule intended to improve inline-JavaScript detection contained a regex prone to catastrophic backtracking. Deployed to the entire fleet in one step, it sent CPU on every edge server to 100%, and the proxy layer that serves the actual traffic starved. Global 502s followed within minutes; a kill switch for the offending rules eventually brought things back, with full recovery in well under an hour.

Every ingredient deserves its own lesson.

Lesson 1 — regex is production code

The expression at the heart of the outage contained a pattern of the general shape that regex engines fear most — nested, overlapping quantifiers:

// The dangerous shape (simplified):
const rule = /.*.*=.*/;

// Benign on matching input. But give a backtracking engine a long
// string that ALMOST matches and it explores an explosive number of
// ways to split the string between those greedy quantifiers:
"x=x".match(rule);            // fine
"x".repeat(30000) + "…";      // CPU goes to 100% and stays there

Backtracking engines try one way to divide the input among the quantifiers, fail, back up, try another — and with overlapping wildcards the number of divisions grows explosively with input length. The regex doesn't crash; it just computes, forever, at full CPU. On one machine that's a slow request. On a WAF rule evaluated against traffic on every edge server on the planet, it's a global outage.

Takeaways that apply to any codebase:

  • Review regexes like code, because they are code — with worst-case inputs in mind, not just happy-path matches.
  • Prefer engines or configurations with execution guarantees where regexes meet untrusted input — RE2-style non-backtracking engines guarantee linear time, and timeouts bound the damage where they can't be used.
  • Budget CPU for pattern matching. Anything that evaluates patterns against user-controlled input is a denial-of-service surface — the input doesn't have to be malicious, just unlucky.

Lesson 2 — stage every rollout, including config

The regex was the spark; the deployment model was the fuel. Code changes at Cloudflare normally roll out gradually — canary machines, then a subset of locations, then the world. WAF rules traveled a faster path built for urgent threat response, and that path went everywhere at once.

The uncomfortable truth this exposes: at scale, there is no meaningful difference between deploying code and deploying configuration. A WAF rule, a feature flag, a routing weight, a JSON file — if it changes what production machines do, it can take production down, and it deserves the same protections:

  • Canary first. One machine, one datacenter, a small percentage of traffic — anything that lets a catastrophic change announce itself in a blast radius you can live with. Even a few minutes of soak time at 1% would have turned July 2 into a non-event.
  • Watch a health signal during rollout, automatically. A staged rollout only helps if something is checking the canaries. CPU saturation across a canary group within seconds of a rule push is about as loud as a signal gets.
  • Beware the "emergency lane" becoming the default lane. Fast-path deploys exist for good reasons. But every fast path is a bet that the change is safe — and rules written under time pressure are precisely the ones least likely to be.

Lesson 3 — kill switches you've actually rehearsed

What ultimately stopped the bleeding was a global switch disabling the WAF rules — but getting there cost precious minutes: identifying which of several simultaneous suspicions was right, reaching internal systems that were themselves degraded (the tools engineers needed lived behind the same choking edge), and executing an action of last resort under pressure.

  • Build the big red button before you need it — a way to disable any recently-shipped subsystem globally, fast.
  • Make sure the button works when production is on fire. Emergency tooling that depends on the broken system is decoration. Keep a management path that doesn't route through your own edge/proxy/auth stack.
  • Rehearse. An untested kill switch is a hypothesis. The middle of a global outage is a bad time to test hypotheses.

Lesson 4 — know the signature of a shared-dependency outage

Now the monitoring angle — because from the outside, July 2 had a fingerprint. If you ran ten sites behind Cloudflare, they didn't fail randomly over the afternoon; they all returned 502s within the same minute, from every check location at once. That pattern is diagnostic gold:

  • Everything down together, everywhere → a shared dependency (CDN, DNS provider, host) — go check their status page, not your servers.
  • One site down, others fine → your app or origin — start debugging.
  • Down from some locations, up from others → network path or routing — a different playbook again.

Teams with independent, multi-location monitoring knew within a minute or two that the problem was upstream, told their customers so, and waited calmly. Teams without it spent half an hour restarting healthy origin servers. Same outage, very different afternoons. It's also a reminder that monitoring through your CDN monitors the CDN too — which is what you want, as long as you know how to read the signature when it fires.

Credit where due — and a takeaway

Cloudflare's same-day postmortem named the root cause plainly, took responsibility, and committed to fixes: staged WAF rollouts, better protection against runaway regex execution, and emergency tooling that survives the emergency. That transparency is the industry standard everyone should be held to — most vendors' incident reports still say "a small subset of customers may have experienced elevated error rates" and hope you stop reading.

Your part of the bargain is knowing, immediately and independently, when a shared dependency takes you down. CompleteStatus checks your sites from multiple locations and alerts you the moment confirmed failures appear — so when every monitor fires at once, you recognize the signature and skip straight to the right response. See what it monitors, or create a free account and put an independent witness on everything you run. The next July 2 is a matter of when.

Stop checking by hand

CompleteStatus runs these exact checks around the clock — uptime, SSL, DNS, security headers and SPF/DKIM/DMARC — and alerts you the moment something changes. One dashboard, one bill.
Start free Run a free check
Uptime is table stakes. We watch the rest — security headers, email authentication, certs and DNS, with the fix attached.
Start free
Company
© 2026 CompleteStatus. All rights reserved. CompleteStatus — operated in the United States · support@completestatus.com