Mark Ku's Blog

Background

I currently work at an e-commerce company whose products mainly serve the US, Germany, and Canada. A few days before Black Friday, we noticed that the site was constantly being hit by DDoS attacks. One day the site went down completely, which is when we started a deeper investigation.

I previously wrote an article on DDoS defense concepts. This post applies those defense rules in Cloudflare WAF.

Reviewing Cloudflare's security report, on the 12th we received roughly 20 million malicious requests targeting our site.

Cloudflare Firewall Events dashboard with DDoS traffic by country and time graph
Cloudflare WAF report detailing 21.44 million requests, 8.52 million

At the time many questions came to mind. Why would a single IP make such a huge volume of requests?

UI showing top IP addresses by malicious request count
UI showing top IP addresses by malicious request count

And why are there so many countries we don't even operate in sending heavy traffic to our site?

Cloudflare dashboard table of top threat countries and request counts
Cloudflare dashboard table of top threat countries and request counts

Although we use the Enterprise tier of Cloudflare, the default settings - while blocking most DDoS - still let some attacks slip through given the sheer volume. I spent a lot of time learning Cloudflare, reviewed every setting, discussed with my boss, and then put together a DDoS prevention plan using Web Application Firewall rules to protect our business during Black Friday, with our US boss's approval.

Cloudflare DDoS prevention rules for festival and last resort scenarios
Cloudflare DDoS prevention rules for festival and last resort scenarios

To avoid false positives that hurt the business, we only blocked single IPs making excessive requests. Below is the block screen.

Mobile display of Cloudflare Access denied error 1020 block page
Mobile display of Cloudflare Access denied error 1020 block page

To avoid false positives, before adding an IP to the blocklist we look it up and report it on abuseipdb.

AbuseIPDB report for IP 34.121.210.9
AbuseIPDB report for IP 34.121.210.9

For other rules, to avoid false positives that affect orders, we only enable human verification. Users must pass it before entering the site.

Mobile screen showing hCaptcha human verification security check
Mobile screen showing hCaptcha human verification security check
Mobile CAPTCHA challenge to select hot air balloons from a grid
Mobile CAPTCHA challenge to select hot air balloons from a grid

Now let's start creating WAF rules - Create Firewall rules

Go to Cloudflare admin > Security > WAF > Create firewall rule

Cloudflare WAF firewall rules page with Create firewall rule button emphasized
Cloudflare WAF firewall rules page with Create firewall rule button emphasized

Rule 1. Allowlist - White List

Cloudflare WAF rule editor showing allowlist for known and verified bots
Cloudflare WAF rule editor showing allowlist for known and verified bots

Rule 2. Blocklist - IP Block (attacker)

Cloudflare WAF editor showing IP Block attacker rule blocking source IPs
Cloudflare WAF editor showing IP Block attacker rule blocking source IPs

Rule 3. Country challenge

Cloudflare WAF rule challenging traffic from specific countries
Cloudflare WAF rule challenging traffic from specific countries

Rule 4. IP Challenge (suspicious)

Cloudflare WAF editing an IP Challenge rule for suspicious IPs
Cloudflare WAF editing an IP Challenge rule for suspicious IPs

Rule 99. Bot challenge - Automated (last resort)

Cloudflare WAF rule editor configuring bot score and country conditions
Cloudflare WAF rule editor configuring bot score and country conditions

Rule 99. Likely automated challenge (last resort)

Cloudflare WAF editing a Likely automated firewall rule
Cloudflare WAF editing a Likely automated firewall rule

Rule 99. Request rate limit (last resort)

Cloudflare WAF editing rate limiting rule for DDoS defense
Cloudflare WAF editing rate limiting rule for DDoS defense

Rule 100. Only allow operating countries - Non-operating country

Cloudflare WAF rule blocking traffic not from Canada, Germany, US
Cloudflare WAF rule blocking traffic not from Canada, Germany, US

You can also tune DDoS sensitivity (Security > Settings > DDoS > Configure > Security Level > Medium)

Cloudflare dashboard showing DDoS L7 ruleset configuration with medium sensitivi
Cloudflare dashboard showing DDoS L7 ruleset configuration with medium sensitivi

If nothing else holds, you can turn on "I'm Under Attack" mode. All users wait five seconds before entering the site. Remember to switch it back when done. Security > Settings > DDoS > Configure > Security Level > Enable I'm Under Attack mode

Cloudflare security settings with I'm Under Attack mode enabled
Cloudflare security settings with I'm Under Attack mode enabled

Effectiveness

Across Thanksgiving and Black Friday (three days), we faced 7 DDoS attacks totaling more than 13 million malicious requests, with the highest single burst hitting 3 million requests at once. After the fifth attack the site stalled for about 30 seconds. The reports showed the attack pattern shift from concentrated IPs and countries to small, dispersed traffic. We finally decided to leverage Cloudflare's machine-learning-based rules. Without hurting the business, only single IPs sending massive request volumes were outright blocked, while everything else was sent to human verification. We made it through this year's Black Friday smoothly. It was a pretty intense Black Friday - many external services also experienced anomalies.

A total of 13.63 million requests received

Cloudflare dashboard showing Black Friday firewall events and DDoS defense
Cloudflare dashboard showing Black Friday firewall events and DDoS defense

WAF helped block over 5 million requests

Cloudflare WAF rules table showing activity and challenges
Cloudflare WAF rules table showing activity and challenges

Bot analytics report

Security bot analytics dashboard showing requests by score over time
Security bot analytics dashboard showing requests by score over time

Author

Mark Ku

擁有 10+ 年經驗的資深軟體工程師,現為 AI 應用 Builder,專注於大型平台架構與簡化複雜系統設計,從電商系統到訂閱與收費平台,結合 AI Agent、AI 整合與自動化開發,打造高效率且可持續演進的產品技術基礎。Read More

Found this useful?

The author's free tools, daily podcasts and newsletter are all here.

Mark Ku · This article is licensed under CC BY 4.0. Credit the author and link back to the original when reusing it.

Comments

Subscribe to Newsletter

Subscribe to get new posts delivered instantly — never miss a tech share.

By submitting, you agree to receive emails. You can anytime.

Popular Posts

View all
Mark Ku
··602

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution
Mark Ku
··490

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.
Mark Ku
··333

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki
Mark Ku
··264

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning
Mark Ku
··221

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1
Mark Ku
··215

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Readers also read