Can I block large requests (e.g. above a certain size)?
Short answer
Yes. If WAF is enabled, in the RAW tab of the page type, the Raw Body Size restriction counts requests whose request body size declared in the Content-Length header exceeds the limit as violations and blocks them in Blocking Mode. If there is no WAF, the Content-Length header is compared with a byte threshold with Dynamic Condition using the Integer greater than operator, and the condition is bound to the Block action (Status code 413). The Request Size (bytes) condition measures only the first part of the request (the header block and the buffered part of the body); it is used against inflated headers, not for a file size limit.
Problem: Oversized Requests Strain the Backend Service
Very large file uploads and inflated request bodies consume the memory and bandwidth of the Backend Service; some attacks slow the service down this way. Requests above the size the application accepts are wanted to be stopped at TR7.
Solution: Four Methods
Methods 1 and 2 limit the body size and are alternatives to each other; Method 3 is used separately for the header block; Method 4 is the command-line equivalent of Method 2.
| Your situation | Suitable method |
|---|---|
| I have a WAF license; a body size limit | Method 1: WAF → Raw Body Size |
| No WAF; an exact byte limit for the body size | Method 2: Dynamic condition (Content-Length) + Block |
| Abnormally large header blocks | Method 3: Request Size (bytes) + Block |
| Setting up Method 2 from the command line | Method 4: WEB-CLI |
Method 1: WAF → Raw Body Size Recommended
- How it works The check compares the declared body size (
Content-Length) with the restriction on every request that carries a body, regardless of the content type, and before all body checks; a request that does not comply with the restriction is scored as a Raw Body Size violation in the Structure Limits category. Requests without a body do not enter this check. - Where it is opened Left Monitor Panel → WAF-Protected vServices → vService → WAF Management → Page Types → rule → RAW tab
- Requirement WAF license; a WAF-enabled HTTP vService
- vService type HTTP
Step-by-Step Configuration
If WAF is not on in the vService, the HTTP vService is edited, the WAF box under Details is checked, and the form is saved with Save; details: How do I attach WAF, L7 DDoS & Threat Protection and AGS to a vService?
In the WAF Management tab, the rule is opened from the Page Types list (Any paths for the whole site, the related path for a single upload endpoint); in the RAW tab, Add Common Rule for Raw (Edit common rule for Raw if the rule exists) is clicked.
In the Raw Body Size field, Less than or Equal to is selected and the byte value (e.g. 10485760 for 10 MB) is entered. For bodies that do not fit in the inspection buffer, Block Unparsed Contents can also be turned on.
The form is saved with Add.
In the WAF Management tab, WAF Mode = Blocking Mode is selected with the Edit button of the mode card and saved (WAF mode Edit screen). WAF starts in Learning mode; in Learning and Monitor modes, the request is not blocked, only recorded.
Verification
Command: curl -s -o /dev/null -w '%{http_code}' -X POST --data-binary @buyuk.bin https://www.example.com/upload
WAF blocking status code (default 418)The WAF-Protected vServices → vService → Event Logs screen is checked.
Raw Body Size violation, Attack blockedMethod 2: Dynamic Condition (Content-Length) + Block
- How it worksDynamic Condition reads the value in the
Content-Lengthheader of the request as a number and compares it with the byte threshold with Integer greater than; a request that exceeds the threshold receives a 413 response with Block and is not forwarded to the Backend Service. - Where it is openedLoad Balancer → Conditions → Dynamic Condition · Load Balancer → Actions → Block
- Requirement None
- vService type HTTP
Step-by-Step Configuration
The condition form is opened with Load Balancer → Conditions → Add (how to add).
Condition Name = buyuk-govde and Criteria = Dynamic Condition are selected; Condition Level = On Request and Condition Protocol = HTTP are left as they are (neither can be changed after saving). In the Query Key field, the Request HTTP header content variable is selected with fx with the Content-Length argument; Operator = Integer greater than and Integer to compare = 10485760 (10 MB) are entered.
The condition is saved with Add.
The action form is opened with Load Balancer → Actions → Add.
Action Name = buyuk-istek and Action Type = Block are selected; Execution Level is left at the default On request and Deny Type at the default Standard, and Status Code = 413 is selected (default 403).
buyuk-govde is selected in the Conditions field. If the limit is to be applied only to a specific upload path, a Path condition is added in the same group with and.
The action is saved with Add.
On the Load Balancer → Load Balancer vService List screen, the HTTP vService is selected and the edit form is opened with Edit.
buyuk-istek is selected in the Details → Actions field. The action does not work unless it is added to the vService.
The form is saved with Save. In a cluster, the change is transferred to the peer device automatically by default; if Manual Sync Mode is on, it is sent with Synchronize.
Verification
Command: head -c 11000000 /dev/zero > buyuk.bin; curl -s -o /dev/null -w '%{http_code}' -X POST --data-binary @buyuk.bin https://www.example.com/upload
413A file below the threshold is sent with the same command.
The normal response of the application (e.g. 200)Method 3: Request Size (bytes) + Block
- How it works The condition measures the byte length of the first part of the request that reaches TR7 (the header block and the part of the body buffered up to that moment). It does not see the total size of the body or the
Content-Lengthheader; for this reason, it is used against abnormally large header blocks. - Where it is openedLoad Balancer → Conditions → Request Size (bytes)
- Requirement None
- vService type HTTP
Step-by-Step Configuration
The condition form is opened with Load Balancer → Conditions → Add.
Condition Name = buyuk-baslik, Criteria = Request Size (bytes), Operator = Greater than (>) and the value 16384 are entered (Request Size (bytes) · Scenario 1: Blocking Abnormally Large Requests). Since the measured value is limited by the buffer size of the vService, thresholds at the megabyte level do not match in this condition.
The condition is saved with Add.
Steps 4–10 of Method 2 are applied; buyuk-baslik is selected in the Conditions field and Status Code = 413 is used.
Verification
Command: curl -s -o /dev/null -w '%{http_code}' -H "X-Test: $(head -c 20000 /dev/zero | tr '\0' a)" https://www.example.com/
413Method 4: WEB-CLI
- How it works The Dynamic condition and the Block action in Method 2 are created with
lb condition/lb action, and the action is added to the vService withlb service. - Where it is opened TR7 WEB-CLI →
lb condition·lb action·lb service - Requirement WEB-CLI access
- vService type HTTP
Step-by-Step Configuration
WEB-CLI runs each line as a separate command; commands are written on a single line.
smartCond = Dynamic condition, intGt = Integer greater than; %REQHEADER(Content-Length) = Request HTTP header content (Content-Length). The variable is written inside single quotes (dynamic conditions).
lb condition add criteria smartCond smartVar '%REQHEADER(Content-Length)' smartOperator intGt smartIntRefValue 10485760 --name buyuk-govdeThe --cond field of the action requires the ID of the condition, not its name. lb condition add gives no output when it succeeds; the ID is seen in the id column of the list below (it starts with lbConditions-).
lb condition listlb action add type deny name buyuk-istek --denyStatusCode 413 --cond <large-body-id>The rules.0, rules.1… lines show the actions bound to the vService.
lb service show <vService>The new action is written to the first empty index, that is, to the number of existing actions. In the example, since the vService has two actions (rules.0, rules.1), --rules.2 is used; writing to a filled index replaces the action there.
lb service update id <vService> --rules.2 buyuk-istekVerification
The curl test in Method 2 is repeated.
413Common Mistakes
- Trying to limit the upload size with Request size (bytes). This condition measures only the first part of the request; it does not see the total of the body.
- Mistaking Buffer size for an upper limit. The Buffer Size in vService Limits does not limit large files (What is Buffer size used for; when should I change it?).
- Forgetting requests that do not carry Content-Length. Bodies sent in parts (chunked) have no
Content-Lengthheader; the condition of Method 2 does not match these requests. - Leaving WAF in Learning or Monitor mode and expecting blocking. A Raw Body Size violation is blocked only in Blocking mode.
- Writing the condition name in the
--condfield. In WEB-CLI,--condexpects the condition ID; if the name is written, the action is bound to a condition that does not exist.
How it is done in the documentation
