F5 iRules vs Cloudflare WAF: Why Hand Written iRules Fall Short
Hand written iRules fall short because they are custom scripts, not a maintained WAF. They lack managed threat rules, automatic updates for new vulnerabilities, behavioural detection, and central reporting. Your team must write, test, and patch every signature itself, while Cloudflare WAF delivers continuously updated protection at the edge with far less engineering effort.
F5 iRules vs Cloudflare WAF: Why Hand Written iRules Fall ShortAndrew Baker's Technology Blog Posts, 04/Dec/2026
https://andrewbaker.ninja/2026/12/04/f5-irules-vs-cloudflare-waf-why-hand-written-irules-fall-short/
Every few years I sit in an architecture review where someone proposes that we do not need a Web Application Firewall (WAF) because “we already have F5, and we can just write some iRules”. It sounds pragmatic, it sounds cheap, and it usually comes from a smart engineer who has seen iRules do genuinely clever things. It is also the wrong answer, and the reasons it is wrong say a lot about what a WAF actually is. This post walks through why a library of hand written iRules on an F5 BIG-IP Local Traffic Manager (LTM) is a useful sharp tool but a poor substitute for a WAF, and then compares the three options an architecture review actually has in front of it: custom iRules, F5’s own WAF product, and a managed edge WAF such as Cloudflare.
To be fair to F5 from the start: F5 itself does not claim that iRules are a WAF. It sells BIG-IP Advanced WAF (the product formerly known as Application Security Manager, or ASM) precisely because a scripting hook on a load balancer is not a security product. The argument here is not “F5 is bad”; it is that a hand written iRule estate is the wrong shape of solution for the problem a WAF solves.
1. What iRules actually are
iRules are event driven scripts written in Tool Command Language (Tcl) that run inside the Traffic Management Microkernel (TMM), the data plane process on a BIG-IP. You attach them to a virtual server and they fire on events such as CLIENT_ACCEPTED, HTTP_REQUEST and HTTP_REQUEST_DATA. Inside those events you can read and rewrite headers, inspect the URI, pick a pool, send a response directly, store state in session tables and log to a remote syslog. For traffic engineering this is superb: header rewriting, smart routing, canary releases, maintenance pages, protocol fixes for broken clients and stopgap mitigations for a specific known problem are all things iRules do brilliantly, and I have used them for all of those.
What iRules give you is a programmable hook into the request path. What a WAF gives you is a detection engine: a parser that understands many content types, a normalisation pipeline that turns hostile encodings into a canonical form, thousands of maintained signatures, a scoring model, a tuning workflow for false positives, analytics, and a team of researchers who update all of it when the next critical Common Vulnerabilities and Exposures (CVE) entry lands at two in the morning. The hook is necessary for a WAF, but it is a small part of one, and everything else is what you would have to build and run yourself in Tcl. That is where the idea falls apart.
2. The normalisation problem
The biggest reason iRules struggle as a WAF is normalisation. An attacker does not send union select; they send whatever byte sequence the backend will eventually interpret as union select while looking as little like it as possible to anything in between. A real WAF spends a large part of its effort turning input into a canonical form before matching, and it has to do this for every location in the request: path, query string, headers, cookies and body.
F5 does give you some help here, and it is worth being accurate about how much. Since BIG-IP v12.1.0, HTTP::uri -normalized returns the URI after normalisation rather than as sent: it removes unneeded directory traversal sequences, converts Microsoft style %uXXXX encodings to standard %XX form, percent encodes bytes that are not allowed in a URI, and decodes percent encoded bytes that did not need encoding. That is a genuinely useful URI canonicaliser. It is not an attack payload decoder, though: by design it leaves alone characters that must stay encoded, it does nothing for headers, cookies or bodies, and it knows nothing about SQL comments, HTML entities or backend specific parsing. Everything beyond the URI path and query is still yours to write.
Consider the naive rule that tends to appear in these conversations. It lowercases the raw URI and looks for two strings.
cat > naive_sqli_block.tcl << 'EOF'
when HTTP_REQUEST {
set uri [string tolower [HTTP::uri]]
if { ($uri contains "union select") || ($uri contains "<script") } {
HTTP::respond 403 content "Blocked"
}
}
EOF
chmod 644 naive_sqli_block.tclHTTP::uri without options returns the raw URI as it arrived, so this rule does not even catch union%20select, which is the most basic form an attacker or a browser would send. So the engineer adds decoding, and because attackers double encode, they loop the decode with a bound of five passes. Then they add a regular expression to cope with arbitrary whitespace and parentheses, and they strip SQL comments because union/**/select gets through. The next version does all of that, in that order, and logs what it blocks.
cat > less_naive_sqli_block.tcl << 'EOF'
when HTTP_REQUEST {
set prev ""
set cur [HTTP::uri]
set i 0
while { ($cur ne $prev) && ($i < 5) } {
set prev $cur
set cur [URI::decode $cur]
incr i
}
set cur [string tolower $cur]
regsub -all {/\*.*?\*/} $cur " " cur
if { [regexp {union[\s\(]+(all[\s\(]+)?select} $cur] } {
log local0. "Blocked possible SQLi from [IP::client_addr]: $cur"
HTTP::respond 403 content "Blocked"
}
}
EOF
chmod 644 less_naive_sqli_block.tclThis is already slower and more fragile, and it is still easy to bypass. MySQL treats /*!50000UNION*/ as executable code rather than a comment, so the comment stripping step actually removes the keyword the rule was looking for, which is a nice example of a normalisation step making detection worse. Whitespace characters that some databases accept may or may not fall in the \s class, overlong UTF‑8 sequences and HTML entity encoding for cross site scripting (XSS) each need their own handling, and the payload can simply move into the body, a cookie or a header that this rule never looks at. Then the same exercise needs repeating for every attack class: SQL injection (SQLi), XSS, remote code execution (RCE), path traversal, server side template injection, deserialisation, XML external entities and so on. Each of those is a separate family of transformations and signatures, and each one is now Tcl code that someone in your team owns.
The deeper issue is that the right normalisation depends on the backend. ASP.NET joins duplicate query parameters with a comma, PHP takes the last one, and some Java frameworks take the first, so ?id=1&id=union select is a different request depending on who parses it. This class of problem, a parser differential between the inspecting device and the application, is the root of HTTP parameter pollution and request smuggling attacks. WAF engines, whether F5’s or Cloudflare’s, carry years of accumulated handling for these differentials. An iRule sees whatever TMM hands it and whatever your own Tcl decides it means.
3. Request bodies are where the attacks live
Most interesting attacks against modern applications are in the request body: JSON APIs, GraphQL queries, XML payloads, multipart file uploads and serialised objects. iRules do not inspect bodies by default. To see one you call HTTP::collect, wait for HTTP_REQUEST_DATA, and then read HTTP::payload.
F5’s own documentation is candid about the hazards. The command reference warns that collecting large payloads can make TMM run out of memory quickly, and the iRules API documentation states that when multiple iRules on the same virtual server call HTTP::collect, the last call wins and the earlier one is ignored, and that spreading collects across multiple iRules is not a supported pattern. In practice that means body inspection logic has to be centralised in one iRule and coordinated with anything else that touches the payload. Chunked transfer encoding complicates the length you can know in advance, and the traditional workaround of forcing HTTP/1.0 to get a Content-Length header is itself a change to the protocol behaviour of your application.
Assume you get past that. You now have a blob of bytes, and to inspect it properly you need a JSON parser that handles UNION style escapes, nested structures and duplicate keys the same way your backend does; a multipart parser that copes with boundary tricks and filename encoding; and an XML parser that does not itself become an XML external entity vulnerability. You are writing that security logic per content type, in Tcl, on the same CPU that is load balancing every other application on the box.
4. Signatures need an owner who never sleeps
A WAF is not a static rule set. It is a subscription to a research team. The value is in how quickly coverage appears after a new vulnerability is disclosed, and in how well those rules are tested against real traffic so they do not break legitimate users.
Cloudflare’s public record makes this concrete. For the SharePoint vulnerability CVE-2025-53770, Cloudflare’s team began researching the exploit on the evening of 20 July 2025 and shipped emergency managed rules on 21 July, protecting every customer using the Cloudflare Managed Ruleset automatically. In December 2025, for the React Server Components RCE (CVE-2025-55182), Cloudflare pushed protection into both its Free Managed Ruleset and the paid Cloudflare Managed Ruleset, so even free plan customers proxying React traffic through the WAF were covered. Through October 2025 alone its changelog shows emergency releases for Oracle E‑Business Suite, Cisco Adaptive Security Appliance, Windows Server Update Services and Adobe Commerce.
F5 Advanced WAF sits in between. You get vendor maintained attack signatures and threat campaign intelligence, and F5 offers virtual patching that integrates with web application scanning, but the policy runs on your devices, so your team still schedules signature updates, reviews them and pushes policy changes through your own change control.
Now ask who does that work in an iRule estate. Someone in your team has to read the advisory, understand the exploit well enough to write a signature, express it safely in Tcl without catastrophic regular expression backtracking (a Regular expression Denial of Service, or ReDoS, on your own load balancer is an unpleasant way to learn this), test it against production traffic, push it through change control to a device that fronts every application you own, and then do it again next week. For one or two critical issues a year, a good team can manage that as a virtual patch. For the continuous stream of disclosures that a WAF vendor handles, it is not a realistic operating model.
5. Signatures alone are not enough any more
Even a well maintained signature set has a gap: the time between a new bypass being found and a rule being written, plus all the variants that are close to a known attack but not an exact match. Both commercial options now pair signatures with learned behaviour. F5 describes Advanced WAF as combining machine learning (ML), threat intelligence and learning that separates normal from malicious behaviour to reduce false positives.
Cloudflare’s version is the WAF attack score. The numeric score runs from 1 to 99, where 1 means a request is almost certainly malicious and 99 means it is likely clean; a value of 100 means the request reached the scoring system but was deliberately left unscored, and the dashboard shows it as “Unscored”. It is plan dependent: Enterprise customers get the numeric scores, while Business customers get only the attack score class field (attack, likely_attack, likely_clean or clean). Cloudflare positions it explicitly as a way to catch variants of attacks that the managed rules do not match, and its model was trained on hundreds of millions of requests labelled by the managed rules, some blended with fuzzing techniques so that it generalises to similar patterns.
In 2026 Cloudflare also introduced Attack Signature Detection, which runs the same signature catalogue as the managed rules but separates detection from mitigation, so every request is evaluated and annotated before you decide whether a rule should log or block. It is in Early Access, and Cloudflare still recommends Managed Rules as the baseline, so I would treat it as a direction of travel rather than the core of a design today. The relevant point for this comparison is that both vendors are investing in detection that learns from traffic at scale. An iRule cannot follow them there, because it only knows what you wrote into it.
6. False positives, tuning and visibility
The part of running a WAF that nobody budgets for is tuning. Every real application has a field that legitimately contains something that looks like SQL, a rich text editor that posts HTML, or a parameter that carries Base64 that happens to match a signature. Both F5 Advanced WAF and Cloudflare give you per rule actions, exceptions scoped to paths and parameters, log only or staging modes, request logs and dashboards showing which rules fire and on what.
With iRules, every one of those capabilities is something you build. Exceptions become data groups and nested if statements. Logging becomes high speed logging to a syslog collector that you then have to parse and visualise. A “log only” mode becomes a variable you remember to flip. And because the logic lives on the same TMM that handles all of your production traffic, an error in an iRule does not just let an attack through; a Tcl runtime error in an event handler can reset connections on that virtual server.
7. Performance and blast radius
iRules execute on the data plane for every request on the virtual servers they are attached to. Simple header logic is cheap; repeated URI decoding, regular expressions across the full query string, body collection and string scanning are not, and that cost lands on hardware that was sized for load balancing. F5 Advanced WAF also consumes BIG-IP resources, but it is an engineered module that F5 sizes and optimises rather than Tcl you wrote under pressure.
An edge WAF moves inspection onto the provider’s network before the request reaches your data centre, and the provider has a strong incentive to optimise it: in July 2024 Cloudflare reported cutting its WAF ML execution time by roughly 82 percent, from 1519 to 275 microseconds.
Blast radius cuts the other way, though, and it deserves a fair hearing. A shared edge platform means a provider side mistake can hit many customers at once. On 5 December 2025, while rolling out WAF changes to mitigate the React vulnerability, Cloudflare pushed a configuration change through its global configuration system that triggered a bug in its older FL1 proxy and returned HTTP 500 errors. It lasted about 25 minutes and affected roughly 28 percent of all HTTP traffic Cloudflare serves, limited to customers on that older proxy who also had the Cloudflare Managed Ruleset deployed. A broken iRule takes down your virtual server; a broken edge change can take down a slice of the internet, including you, with nothing you can roll back yourself.
8. Cloudflare is not magic either
The edge WAF has other limits worth being precise about, because specialists will raise them.
Every WAF inspects a bounded window of the request. The same React response involved raising the WAF request body buffer from 128 KB to 1 MB. Cloudflare’s own general updates note that an automatic rollout of the 1 MB limit to all customers proved impractical because it caused a surge in false positives; paid zones can now ask support for 1 MB, while free zones already have it. So a large body can still carry content past the inspected window, and you should know what your limit is.
An edge WAF is also only useful if attackers cannot go around it. If your origin accepts traffic from anywhere, an attacker who discovers the origin address bypasses Cloudflare entirely. Here precision matters. An IP allow list of Cloudflare ranges, and Authenticated Origin Pulls (AOP) using Cloudflare’s global certificate, both prove only that a request came from the Cloudflare network. The global certificate is shared by all accounts, so it does not prove the request came from your account, and an attacker with their own Cloudflare zone pointed at your origin would pass both checks. For account specific assurance, use zone level or per hostname AOP with your own uploaded certificate, which Cloudflare recommends for exactly this case, or a tunnel. And signatures plus ML still will not catch business logic abuse, broken object level authorisation in your API, or credential stuffing on their own; those need bot management, rate limiting, API schema validation and, ultimately, secure code.
9. Where iRules genuinely fit
The right answer for most organisations that already own F5 is not to throw it away but to give it the job it is good at. Let a WAF do detection, and let iRules do enforcement and hygiene behind it. A simple and valuable example is making the BIG-IP refuse connections that did not arrive from Cloudflare’s address ranges, and restoring the real client address from the CF-Connecting-IP header for the application. The rule below expects an address data group named cloudflare_ips containing Cloudflare’s published IPv4 and IPv6 ranges, kept current by automation.
cat > allow_only_cloudflare.tcl << 'EOF'
when CLIENT_ACCEPTED {
if { ![class match [IP::client_addr] equals cloudflare_ips] } {
log local0. "Rejected direct origin connection from [IP::client_addr]"
reject
}
}
when HTTP_REQUEST {
if { [HTTP::header exists "CF-Connecting-IP"] } {
HTTP::header replace "X-Forwarded-For" [HTTP::header "CF-Connecting-IP"]
}
}
EOF
chmod 644 allow_only_cloudflare.tclAs section 8 explains, this only establishes Cloudflare network provenance, not that the traffic belongs to your account. Treat it as a cheap outer layer: enforce the same allow list on the network firewall, and terminate mutual Transport Layer Security (mTLS) on the BIG-IP using zone level or per hostname AOP with your own certificate as the real control. Other good uses of iRules in this design include enforcing allowed HTTP methods per application, stripping internal headers, routing, and short lived virtual patches for a single known endpoint while the application team ships a fix.
%%{init: {'theme':'base','themeVariables':{'lineColor':'#9ec5ff','fontSize':'14px'}}}%%
flowchart LR
A[Client] --> B[Cloudflare edge<br/>Managed Rules and OWASP CRS: paid plans<br/>Attack Score class: Business<br/>Numeric Attack Score: Enterprise]
B -->|mTLS with your own AOP certificate| C[F5 BIG-IP LTM<br/>iRules: Cloudflare ranges only,<br/>routing, header hygiene]
C --> D[Application]
X[Attacker hitting origin directly] -.->|rejected| C
classDef client fill:#2b2b2b,stroke:#ffffff,color:#ffffff
classDef edge fill:#f38020,stroke:#ffffff,color:#000000
classDef adc fill:#1e3a5f,stroke:#9ec5ff,color:#ffffff
classDef app fill:#1f5c2e,stroke:#9effb0,color:#ffffff
classDef bad fill:#7a1f1f,stroke:#ffb3b3,color:#ffffff
class A client
class B edge
class C adc
class D app
class X badIn that diagram OWASP CRS is the Open Worldwide Application Security Project Core Rule Set, which Cloudflare offers as a managed ruleset alongside its own. Free plans get the smaller Free Managed Ruleset rather than the full Cloudflare Managed Ruleset.
10. Side by side
| Capability | Hand written iRules | F5 Advanced WAF | Cloudflare WAF |
|---|---|---|---|
| Input normalisation | HTTP::uri -normalized for the URI; everything else written by you in Tcl | Built into the WAF engine | Built into the WAF engine |
| Body parsing (JSON, XML, multipart) | Manual HTTP::collect, one collect per virtual server, memory hazards documented by F5 | Native JSON, XML, GraphQL and REST profiles | Native, within a documented inspection limit (up to 1 MB on request for paid zones) |
| Signature coverage | Whatever your team has written and tested | Vendor signatures and threat campaigns | Cloudflare Managed Ruleset and OWASP CRS (paid plans); Free Managed Ruleset on free |
| Response to new CVEs | Your team, your change window | Vendor signatures, applied through your change process | Emergency managed rule releases, often within a day |
| Variant and bypass detection | Only your own regular expressions | ML and behavioural learning | Attack score (class on Business, numeric on Enterprise) |
| False positive tuning | Data groups and nested conditions | Learning, staging and policy exceptions | Per rule actions, exceptions, log modes and analytics |
| Performance cost | Shared TMM CPU and memory | BIG-IP resources, vendor optimised | Absorbed at the edge |
| Failure blast radius | A Tcl error can reset connections on that virtual server | Policy or upgrade errors stay on your devices | Provider changes can hit many customers at once (5 December 2025: about 25 minutes, roughly 28 percent of Cloudflare HTTP traffic) |
| Who operates it | You, entirely | You, with vendor content | The provider, with your policy on top |
11. The takeaway
The question is not whether iRules are powerful; they are. The question is whether a WAF is a piece of code or a service, and it is a service. A WAF is a parser, a normalisation pipeline, a constantly updated signature catalogue, a detection model, a tuning workflow and a research team. iRules give you a place to put code in the request path, which is necessary but nowhere near sufficient, and every hour your engineers spend reimplementing a WAF in Tcl is an hour not spent on the parts of security that only you can do, such as fixing authorisation flaws in your own APIs.
The real decision in the architecture review is between F5 Advanced WAF, which keeps control and blast radius on your own devices at the cost of operating it yourself, and a managed edge WAF such as Cloudflare, which gives you faster coverage and network scale detection at the cost of sharing a platform with everyone else. Either is a defensible choice. A folder of hand written iRules is not, and if you already run F5, the best place for those iRules is enforcement, routing and hygiene behind whichever WAF you pick.
References
- F5: HTTP::uri iRule reference, including
-normalized - F5: HTTP::collect API documentation
- F5: HTTP::collect command reference
- F5: BIG-IP Advanced WAF
- Cloudflare: WAF attack score documentation
- Cloudflare: Attack score for Business plan, model training
- Cloudflare: Making WAF ML models faster (July 2024)
- Cloudflare: Always on detections and Attack Signature Detection
- Cloudflare: SharePoint CVE-2025-53770 emergency rules
- Cloudflare: React vulnerability protection
- Cloudflare: 5 December 2025 outage report
- Cloudflare: WAF general updates, payload limit change
- Cloudflare: Authenticated Origin Pulls




