Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 36 ยท Security: WAF and DDoS

Cloudflare WAF: Managed Rulesets, OWASP and Attack Scores

Learn how the Cloudflare Web Application Firewall blocks SQL injection, XSS and known exploits using managed rulesets, OWASP scoring, actions and exceptions.

A web application firewall (WAF) inspects HTTP requests for signs of attack and blocks or challenges the ones that look malicious. It works at the application layer: URLs, query strings, headers and bodies, not raw network packets. The Cloudflare WAF runs on every proxied request, at the edge, before your server sees anything.

What a WAF defends against

Typical attacks it recognizes:

  • SQL injection: ' OR 1=1 -- slipped into a parameter to manipulate a database query.
  • Cross-site scripting (XSS): <script> payloads meant to run in another user's browser.
  • Path traversal and local file inclusion: ../../etc/passwd.
  • Remote code execution attempts against known vulnerable software (CMS plugins, frameworks, appliances), often within hours of a vulnerability becoming public.
  • Scanners and exploit kits probing for /wp-login.php, .env, .git/config.

A WAF is a safety net, not a substitute for secure code: parameterized queries, output escaping and updates remain your first line of defense.

Managed rulesets

Cloudflare writes and maintains detection rules for you, grouped into managed rulesets that you switch on in Security > WAF > Managed rules:

Ruleset What it does
Cloudflare Managed Ruleset Rules written by Cloudflare's team for known vulnerabilities and common attack types; updated continuously, even before public patches. A free subset covers high-impact issues on every plan.
Cloudflare OWASP Core Ruleset A port of the open OWASP ModSecurity Core Rule Set that gives each request an anomaly score and acts when the score passes a threshold (paid plans).
Exposed credentials check Flags logins using username and password pairs known from breaches.
Leaked credentials and other add-ons Extra signals on higher plans.

Each rule inside a ruleset has an action and you can override the action per rule or per ruleset. Typical actions are:

  • Block: return 403, stop processing.
  • Managed Challenge: let Cloudflare choose a gentle check (often an invisible test, sometimes an interactive widget) to tell humans from bots.
  • JS Challenge and Interactive Challenge: specific kinds of tests.
  • Log: let the request through but record the match, perfect for testing.
  • Skip: exempt the request from rules.

Start any new rule or ruleset in Log mode, look at events for a few days, then move to Block or Challenge once you are sure that legitimate traffic is not matched.

OWASP anomaly scoring

The OWASP Core Ruleset does not block on a single match. Each matching rule adds points (a critical rule adds more, a minor one less), and the total score is compared with a threshold you choose. Raising the paranoia level switches on stricter rules, which catch more attacks and also produce more false positives. The threshold labels (low, medium, high) express how much score is tolerated before an action fires.

flowchart LR
  R["Request"] --> A["Rule 1: SQL keyword +3"]
  A --> B["Rule 2: suspicious header +2"]
  B --> C["Total score 5"]
  C --> T{"Score above threshold?"}
  T -- "yes" --> X["Action: block or challenge"]
  T -- "no" --> OK["Allowed"]

Scoring reduces false positives: one weak signal alone does not block anyone.

JS Stand-in: anomaly scoring WAF

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Compare the two thresholds. With the lower one more requests are blocked, including borderline ones, which is the false-positive trade-off in action. The harmless phrase "union select a gift" scores points but should stay below a sensible threshold.

Exceptions and tuning

False positives happen, for example a CMS editor posting HTML, or an API that legitimately sends SQL-like text. Do not turn the WAF off. Instead:

  • Find the event in Security > Events; note the rule ID and the matched field.
  • Create an exception: a custom rule with action Skip that skips the one managed rule (or the ruleset) for a precise path, such as /admin/editor with method POST.
  • Prefer narrow exceptions (rule + path) over broad ones (whole ruleset + whole zone).
  • Re-check events after changes.

Other WAF-family protections

  • Custom rules (next lesson) for logic that is specific to your site.
  • Rate limiting rules (after that) for floods and brute force.
  • Bot protection and DDoS (end of this chapter).
  • API Shield with schema validation and mutual TLS for APIs (higher plans).
  • Page Shield monitors the scripts your pages load, to spot skimming attacks.
  • Security Events and Security Analytics show what was matched, with filters by rule, country, IP and path.

Reading Security Events

Each event lists time, action taken, the source (WAF managed rules, custom rule, rate limit, DDoS), the rule ID or description, the path and IP, and the Ray ID. The Ray ID matches the cf-ray header, so a visitor who sees a block page can give you the ID and you find the exact event in seconds.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. At which layer does a WAF inspect traffic?

    It looks at URLs, headers and bodies of HTTP requests.
  2. 2. Why start a new rule with the Log action?

    Log mode reveals false positives safely.
  3. 3. How does the OWASP ruleset decide to act?

    Each matching rule adds points; acting on the total reduces false positives.
  4. 4. What is the best way to handle a false positive?

    Keep protection on and exempt only what is necessary.

Summary

  • A WAF blocks application-layer attacks such as SQL injection, XSS and known exploits; it complements, not replaces, secure code.
  • Managed rulesets (Cloudflare Managed, OWASP, credentials checks) are maintained for you; actions include Block, Challenge, Log and Skip.
  • OWASP scoring combines weak signals; raise paranoia levels carefully.
  • Test in Log mode, tune with narrow exceptions, investigate with Security Events and Ray IDs.

Next: Custom rules and the expression language