How i was able to bypass Cloudflare WAF for SQLi payload
The author found that Cloudflare WAF blocked common SQL injection characters and keywords, but by using non-standard double URL encoding and multi-line comments they could bypass the filter and inject a boolean-based SQL injection payload.
Momen Ali (Cyber Guy)
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
This is a write-up about getting a boolean-based SQL injection payload past Cloudflare's web application firewall (WAF). The author describes hunting on a target where Cloudflare was in front of the application and was blocking most or all of the SQL injection payloads they tried. The report does not name the target, the application, the parameter or the endpoint that was being tested, and it does not give the Cloudflare plan or any version numbers. What it does give is the full reasoning and the exact payload fragments that eventually got through.

The goal was a boolean-based SQL injection: a payload whose truth value changes the response, so that the attacker can ask the database yes/no questions one at a time.
Setup
The report does not describe any accounts, roles, tooling or versions. The only precondition it states is that the target sat behind Cloudflare and that the WAF was rejecting the payloads the author tried. Everything below is about the payload construction itself, not about a particular request format.
Finding it
The author calls the stage where you detect the blocked characters the most important part of a WAF bypass. After trying a lot of payloads, they found that Cloudflare blocked the following:
- spaces
OR/ANDin all cases-- comment# comment;=
That list is the whole problem statement. A boolean injection normally needs a space to separate tokens, a boolean operator to combine conditions, a comparison operator to produce a true or false result, and a way to terminate or comment out the rest of the original query. Each of those was filtered, so the bypass had to be built one blocked character at a time.
Exploitation
Step 1: replacing spaces
The first attempt was URL encoding: sending %20 in place of a space. That did not work. The second attempt was + in place of a space, which also did not work.
The successful idea was to use a multi-line comment in place of the space:
The reasoning is that the WAF sees /**/ as an ordinary string and lets it through, but when the request reaches the back-end DBMS the same sequence is parsed as a comment, so it acts as a token separator. The author illustrates this with an ordinary SELECT statement in which the multi-line comment stands in for the space, and then with a live example.

Step 2: getting past the boolean operator filter
The WAF blocked all boolean operators, in upper case and in lower case. The author's usual technique at this point is mixed case, for example:
In this case the WAF blocked those as well. The next attempt was standard URL encoding, encoding the operator like this:
oR -> %6fR
That was blocked too. The author then moved to non-standard encoding, which they say in most cases is not caught by WAFs, and this got through:
oR -> %256fR
Step 3: getting past the = filter
With the operator problem solved, the = character was still blocked. By now the author had identified what they call the weakness point of this WAF: it does not handle non-standard encoding. So = was encoded the same way:
= -> %253d
This alone was not enough. If any value is placed after the non-standard encoded =, the request is blocked again. The author's reasoning at this point is worth following closely:
- The aim is to reach the True datatype in a boolean-based injection, and the firewall blocks anything that follows the non-standard encoded
=. - So instead of producing true through an equality test, produce it through an inequality. If the payload says
50!=22, that surely returns a True value, because50does not equal 22.
That led to non-standard encoding of !=:
!= -> %2521%253D
Step 4: ending the payload
The last blocked items were the end-of-payload characters: # and --, which start a comment, and ;, which ends the query. Since the weakness was already known to be non-standard encoding, the same technique was applied:
;# -> %253B%2523
Final payload
The complete payload, assembled from the pieces above, is shown in the final screenshot.

Root cause
The report frames the weakness as the WAF's handling of non-standard (double) URL encoding. The blocked tokens are caught when they appear literally or under standard percent-encoding, but once a percent sign is itself encoded, the filter no longer recognises the token. The back-end then decodes the value again and the DBMS sees the original operator, comment or terminator.
Impact
The impact is that a boolean-based SQL injection which the WAF was meant to stop becomes deliverable. The author does not state what data was reachable, which database or privileges were involved, or what the application returned, so the practical impact beyond "the injection gets through" is not established in the report. The technique relies on the WAF not recognising the double-encoded token while the back-end still interprets it.
Fix
The implied fix is on the WAF side: normalise and repeatedly decode input before applying signature rules, so that double-encoded tokens are matched the same way the back-end will interpret them. Parameterised queries at the application layer would remove the injection regardless of what the WAF lets through.
Variants to test
- Double-encoded boolean operators. Send
%256fRor%2561Ndin a parameter that is known to be injectable and watch for a change in the true/false response. A positive result is a response that differs between a true and a false condition where the plain and single-encoded forms were blocked. - Double-encoded comparison operators. Try
%253dand%2521%253Din place of=and!=. A positive result is a boolean condition that evaluates and changes the page, where the literal operator was rejected. - Comment-as-space. Replace spaces with
/**/in an otherwise blocked payload. A positive result is a query that parses on the back-end while the WAF sees no space token. - Double-encoded terminators. Try
%253B%2523for;#at the end of a payload. A positive result is the trailing part of the original query being commented out or terminated without the WAF rejecting the request. - Mixed-case operators. Try
oRandaNdfirst, since some WAFs only match a single case. A positive result is the operator reaching the DBMS where the uniform-case form was blocked.
What happened, in plain words
A security researcher was testing a website for a common and serious bug called SQL injection. The website sat behind Cloudflare, a service that acts as a protective shield in front of a site and inspects incoming traffic, blocking anything that looks dangerous. Cloudflare was blocking most or all of the SQL injection payloads the researcher tried. The researcher then worked out, character by character, how to write the same attack in a form Cloudflare did not recognise, while the database behind the site still understood it. This article walks through that reasoning from the beginning, assuming you have never done security testing before.

The bug being hunted: SQL injection
Most websites store their data in a database. When you type something into a search box or a login form, the site usually builds a small instruction (a query) in a language called SQL and sends it to the database. For example, a query might say "find the user whose name is Alice".
SQL injection happens when the site pastes what you typed straight into that instruction without cleaning it. If you type something clever instead of a normal name, you can change the instruction itself. It is like a form that asks for your name, and you write "Alice, and also please show me everyone's salary" and the clerk reads the whole thing out as an order.
There are several flavours of SQL injection. The one in this report is boolean-based. Boolean means true or false. The attacker sends a condition that the database evaluates, and the page behaves differently depending on whether the answer is true or false. By asking many yes/no questions ("is the first letter of the admin password greater than 'm'?"), the attacker can slowly extract data one bit at a time. It is slow but reliable, like guessing a password by asking "is it longer than five characters?" over and over.
The shield: a WAF
A WAF (Web Application Firewall) is a filter that sits in front of a website and inspects every request before it reaches the site. It has a list of patterns that look like attacks, and if a request matches one, it is blocked. Think of it as a bouncer at a club with a list of banned outfits: if you turn up in one, you do not get in.
Cloudflare is a large company that provides this kind of protection, among other services, to many websites. The report does not name the target site, the specific page, or the parameter being tested, and it does not say which Cloudflare plan or version was in use. What it does give is the full reasoning and the exact pieces of payload that eventually got through.
Setup
The report does not describe any accounts, tools, software versions or special access. The only precondition it states is simple: the target website was behind Cloudflare, and the WAF was rejecting the attack payloads the researcher tried. Everything that follows is about how the payload itself was built, not about a particular request format or a particular page.
Finding it
Step 0: work out what the filter hates
The researcher calls the most important stage of any WAF bypass finding out which characters the firewall refuses. It is like testing a door lock by trying one key at a time rather than guessing the whole key at once.
After trying a lot of payloads, the researcher found that Cloudflare blocked the following:
- spaces
OR/ANDin all cases-- comment# comment;=
That list is the whole problem. A normal boolean injection needs each of those pieces:
- a space to separate words in the SQL instruction, the way spaces separate words in English;
- a boolean operator such as
ORorANDto combine conditions ("this OR that"); - a comparison operator such as
=to produce a true or false answer ("is this equal to that?"); - a comment marker such as
--or#, or a semicolon;, to end the payload cleanly and stop the rest of the original query from interfering.
With every one of those filtered, the attack had to be rebuilt one blocked character at a time.
Exploitation
Step 1: replacing spaces
The first idea was to hide the space using URL encoding. URLs cannot contain literal spaces, so browsers and servers have a convention: a space can be written as %20. The researcher tried sending %20 in place of a space. It did not work.
The second idea was to use + instead of a space, another common URL convention. That did not work either.
The successful idea was to use a multi-line comment in place of the space:
In SQL, anything between /* and */ is a comment: the database ignores it. But it still counts as a separator between words, just like a space. So the WAF sees a harmless-looking string of punctuation and lets it through, while the database, when it finally reads the request, treats /**/ as a gap between two words. The researcher illustrates this with an ordinary SELECT statement in which the multi-line comment stands in for the space, and then with a live example.

Step 2: getting past the boolean operator filter
The WAF blocked all boolean operators, whether written in upper case (OR, AND) or lower case (or, and). The researcher's usual trick at this point is mixed case, for example:
The idea is that some filters only check for one exact spelling, so oR slips past a filter looking for OR and or. In this case the WAF blocked those as well.
The next attempt was standard URL encoding, encoding the operator like this:
oR -> %6fR
Here %6f is the URL encoding of the letter o. That was blocked too.
The researcher then moved to non-standard encoding, which they say in most cases is not caught by WAFs, and this got through:
oR -> %256fR
What is happening here? %25 is the URL encoding of the percent sign % itself. So %256fR means "a percent sign, followed by 6fR". When the WAF decodes the request once, it sees %6fR, which is not the word oR, so it does not match its rule. But the back-end application decodes the value a second time, turning %6fR into oR, and the database sees the operator it expected. This double decoding is the gap the researcher exploits.
Step 3: getting past the = filter
With the operator problem solved, the = character was still blocked. By now the researcher had identified what they call the weakness point of this WAF: it does not handle non-standard encoding. So = was encoded the same way:
= -> %253d
Again, %25 is an encoded percent sign, and 3d is the encoding of =. The WAF decodes once and sees %3d, which is not =, so it lets it through; the back-end decodes again and gets =.
This alone was not enough. If any value is placed after the non-standard encoded =, the request is blocked again. The researcher's reasoning at this point is worth following closely:
- The aim is to reach the True datatype in a boolean-based injection, and the firewall blocks anything that follows the non-standard encoded
=. - So instead of producing true through an equality test, produce it through an inequality. If the payload says
50!=22, that surely returns a True value, because50does not equal 22.
In other words, instead of asking "is this equal to that?", the payload asks "is this not equal to that?", which is always true when the two values differ. That led to non-standard encoding of !=:
!= -> %2521%253D
Here %2521 is a double-encoded ! and %253D is a double-encoded =. The WAF sees %21%3D, which is not !=, so it does not block; the back-end decodes again and gets !=.
Step 4: ending the payload
The last blocked items were the end-of-payload characters: # and --, which start a comment, and ;, which ends the query. A comment is useful because it tells the database to ignore whatever comes after the payload, so the rest of the original query does not break the attack. The semicolon is useful because it marks the end of one SQL statement.
Since the weakness was already known to be non-standard encoding, the same technique was applied:
;# -> %253B%2523
%253B is a double-encoded ; and %2523 is a double-encoded #. The WAF decodes once and sees %3B%23, which is not ;#, so it lets it through; the back-end decodes again and gets ;#.
Final payload
The complete payload, assembled from the pieces above, is shown in the final screenshot.

Root cause
The report frames the weakness as the WAF's handling of non-standard (double) URL encoding. The blocked tokens are caught when they appear literally or under standard percent-encoding, but once a percent sign is itself encoded, the filter no longer recognises the token. The back-end then decodes the value again and the database sees the original operator, comment or terminator.
Impact
The impact is that a boolean-based SQL injection which the WAF was meant to stop becomes deliverable. The technique relies on the WAF not recognising the double-encoded token while the back-end still interprets it.
Fix
The implied fix is on the WAF side: normalise and repeatedly decode input before applying signature rules, so that double-encoded tokens are matched the same way the back-end will interpret them. Parameterised queries at the application layer would remove the injection regardless of what the WAF lets through. A parameterised query is one where the user's input is passed as data, never as part of the SQL instruction, so no amount of clever encoding can change the instruction itself.
Variants to test
- Double-encoded boolean operators. Send
%256fRor%2561Ndin a parameter that is known to be injectable and watch for a change in the true/false response. A positive result is a response that differs between a true and a false condition where the plain and single-encoded forms were blocked. - Double-encoded comparison operators. Try
%253dand%2521%253Din place of=and!=. A positive result is a boolean condition that evaluates and changes the page, where the literal operator was rejected. - Comment-as-space. Replace spaces with
/**/in an otherwise blocked payload. A positive result is a query that parses on the back-end while the WAF sees no space token. - Double-encoded terminators. Try
%253B%2523for;#at the end of a payload. A positive result is the trailing part of the original query being commented out or terminated without the WAF rejecting the request. - Mixed-case operators. Try
oRandaNdfirst, since some WAFs only match a single case. A positive result is the operator reaching the database where the uniform-case form was blocked.
Glossary
- SQL: the language used to talk to most databases, for example to look up, add or change records.
- SQL injection: a bug where user input is pasted into a SQL instruction without cleaning, so the input can change the instruction itself.
- Boolean-based SQL injection: an injection where the attacker sends true/false conditions and reads the answer from how the page responds, extracting data one yes/no question at a time.
- WAF (Web Application Firewall): a filter in front of a website that inspects incoming requests and blocks ones that look like attacks.
- Cloudflare: a company that provides a protective layer in front of many websites, including WAF services.
- Payload: the piece of text an attacker sends to try to trigger a bug.
- URL encoding (percent-encoding): a convention for writing characters in a URL that cannot appear literally, such as a space written as
%20. - Non-standard (double) encoding: encoding a character that is already encoded, so a percent sign becomes
%25and the whole thing is decoded twice by the back-end. - DBMS (Database Management System): the software that stores and answers queries against a database.
- Query: an instruction sent to a database, for example to select or update records.
- SELECT statement: a SQL instruction that asks the database to return data.
- Comment (SQL): text the database ignores, written as
--,#or between/*and*/; useful for cutting off the rest of a query. - Multi-line comment: a comment written between
/*and*/, which can span several lines and can also act as a separator between words. - Boolean operator:
ORandAND, used to combine conditions in SQL. - Comparison operator: symbols such as
=,!=,<and>, used to compare values and produce a true or false result. - True / False datatype: the two possible results of a boolean condition.
- Parameterised query: a way of writing database queries where user input is passed as data, never as part of the instruction, which prevents SQL injection.
- Normalise: to convert input into a single standard form before checking it, so that different spellings of the same thing are treated the same.
- Signature rule: a pattern a WAF looks for in requests to decide whether to block them.