Request Body Too Large for AWS WAF? Gzip and Split the Payload
When AWS WAF says a request body is too large, it does not say so: it returns a bare 403. A JSON request of 41 KB was blocked with a 403 by AWS WAF, because the managed rule SizeRestrictions_BODY rejects any request body over 8 KB. Gzip shrank it about 4 times, to 9.9 KB, which was still over the limit. What got it through was gzip plus splitting: each request now carries at most 40 records or 16 KB of JSON, lands at 5 KB or less on the wire, and the same 66-record upload goes out as 3 requests.
This post covers how we told a body-size block apart from a rate-limit block, the fix we shipped first that changed nothing, why compression alone only moves the ceiling, and how we cut a large submission into pieces that each pass. It also covers what the screen does when one piece fails after others have gone through. It follows our earlier post on the gzip compression fix for AWS WAF, which got larger requests through for a while.
The short version
- A 66-record upload of 41 KB of JSON was refused with a bare 403 by the WAF rule SizeRestrictions_BODY, which blocks request bodies over 8 KB.
- Gzip compressed that body about 4 times, to 9.9 KB, so compression alone could not carry it past an 8 KB limit.
- Splitting the submission into pieces of at most 40 records or 16 KB of JSON brings each gzipped request to 5 KB or less, and the 66 records go out in 3 requests.
- Our first fix, limiting background imports to 4 at a time, changed nothing, because we had guessed the rule from the status code instead of reading the WAF log.
What the upload does
Our content team plans community posts in a spreadsheet: one row per post, with its author, text, publish time, images and the first comments and likes. They drop the sheet into our internal operations console, which reads it in the browser, checks it with the server, and then schedules every row in one go. The posts go out to the Hoomanely community.
Each row becomes a JSON object in the request body. A typical row with a few comments is 500 to 700 bytes, so a sheet of a dozen posts stays small. The sheet that broke had 66 posts and 26 images linked from Google Drive, and its body came to 41 KB.
The console sits behind an Application Load Balancer protected by AWS WAF, with the AWS managed Core rule set and a per-IP rate rule. Both of those can answer with the same status code, which is where our trouble started.
Why doesn’t a bare 403 tell you which AWS WAF rule fired?
AWS WAF blocks a request with a 403 and, by default, an empty body. A rate-based rule, a SQL injection match and a body-size limit all look identical from the browser. The console showed the user “request failed (403)” and nothing else.
The only place the reason exists is the WAF log. Each blocked request is logged with a terminatingRuleId, which names the rule group, and a ruleGroupList that names the specific rule inside it. In CloudWatch Logs Insights, filtering the WAF log group on action = “BLOCK” and reading those two fields takes a couple of minutes. Our log showed AWS-AWSManagedRulesCommonRuleSet with the rule SizeRestrictions_BODY, on every blocked attempt.

That rule blocks any request body over 8 KB, and its threshold is part of the managed rule. Raising the web ACL’s body inspection size, which an Application Load Balancer allows up to 64 KB, lets other rules read more of the body but does not move this one. The only ways past it are to override the rule to count instead of block for these paths, which drops a protection, or to keep each request under 8 KB. We chose the second.
Your options when AWS WAF blocks a large request body:
- Raise the body inspection size: lets other rules read more of the body, but does not change SizeRestrictions_BODY’s 8 KB threshold.
- Override the rule to count for specific paths: gets large bodies through, but drops a protection on those paths.
- Gzip the body: the WAF measures compressed bytes, so this helps, but only by your compression ratio.
- Gzip and split the payload: keeps every request under 8 KB, whatever the total size. This is what we shipped.
The fix we shipped first, and why it changed nothing
We did not read the log first. The failing sheet was also the first one with dozens of Google Drive images, and each Drive import polls the server every few seconds while the file is fetched. Dozens of polls at once looked like a likely trip of the per-IP rate rule.
So the first fix capped Drive imports at 4 at a time, in a rolling pool. It was reviewed, merged and deployed. The same sheet failed the same way on staging and in production, because the request that was being blocked was the schedule request itself, not the polling around it.
The pool is still in place, since it keeps a large sheet from hammering the server. But it fixed a problem we did not have. The lesson we recorded: never guess the rule from the status code, read the terminating rule first.
Why does gzip only move the ceiling?
The console already supported gzip for large request bodies, as described in our earlier gzip fix. A screen can ask for compression, the console compresses any body over 1 KB with the browser’s built-in CompressionStream, sends Content-Encoding: gzip, and the API decompresses it before the handler runs. The WAF only sees the compressed bytes, so a body that is 41 KB as JSON counts as its gzipped size.
The planner had not switched compression on. When we did, the 66-post body went from 41 KB to 9.9 KB, about 4 times smaller. That is a large saving and still over 8 KB.
The ratio is the catch. Post text is varied prose, so it does not compress as well as repetitive JSON keys do, and the compressed size still grows with the number of posts. At a ratio near 4, an 8 KB limit holds roughly 32 KB of JSON, which is about 45 to 60 typical posts. Compression raised the ceiling; it did not remove it. A team that plans a month of posts in one sheet would hit it again.
How we split a request payload into pieces
The fix keeps gzip and splits the submission before it is sent. Pieces are cut greedily: add posts to the current piece until the next one would take it past 40 posts or 16 KB of JSON, then start a new piece. The 16 KB cap is set against the compression ratio we measured, so each piece lands at 4.5 to 5 KB gzipped, with room for posts that compress worse than average.
const POSTS_PER_REQUEST = 40;
const BYTES_PER_REQUEST = 16_000;
const utf8 = new TextEncoder();
function piecesOf(submission: PlanSubmission): PlanSubmission[] {
const out: PlanSubmission[] = [];
let posts: PlanPostIn[] = [];
let bytes = 0;
for (const post of submission.posts) {
const size = utf8.encode(JSON.stringify(post)).length;
if (posts.length && (posts.length >= POSTS_PER_REQUEST || bytes + size > BYTES_PER_REQUEST)) {
out.push({ ...submission, posts });
posts = [];
bytes = 0;
}
posts.push(post);
bytes += size;
}
if (posts.length) out.push({ ...submission, posts });
return out;
}The size is measured in UTF-8 bytes, not string length, because emoji and non-Latin text take more than one byte per character. The count cap exists alongside the byte cap so that one piece never holds so many short posts that the server’s per-request work becomes slow.
Both server calls use the same pieces. The dry run sends each piece to the check endpoint and merges the answers, so the user still sees one list of problems for the whole sheet. Scheduling sends each piece as its own batch, with progress shown as “Scheduling (2 of 3)”. The 66-post sheet went through as 3 batches, and the console reported 66 posts scheduled.
Bounding the whole sheet
Splitting removes the per-request limit, so something else has to bound the total. The server already refused submissions over 500 posts, and the console now checks that limit before it sends anything, with a message asking the user to split the sheet. At typical post size the 16 KB cap fills first, at about 25 posts a piece, so the largest allowed sheet goes out in about 20 requests, never fewer than 13.
What happens when one piece fails?
Sending in pieces gives up one thing a single request had: all or nothing. If the second of three pieces fails, the first is already scheduled. Rolling it back from the browser would be a second request that can also fail, so we chose to report the state exactly instead. We cover the wider pattern in reliable backend workflows on AWS: idempotency, retries and failure modes.
When a later piece fails, the console raises a distinct error that carries the batches that did go through and the sheet rows that did not. The screen refreshes the list of scheduled posts and tells the user which rows to send again. The dry run also flags any post whose media hashes match one already planned, so if the user re-sends the whole sheet, the rows that already went out show up as repeats before anything is scheduled.
Keeping the server honest about compressed bodies
Compression changes what the WAF can see. The Core rule set’s body inspections read the compressed bytes, which are opaque to its pattern matching. We accepted that trade for this path because three things hold:
- The routes are reachable only by authenticated staff.
- The server validates every field of every post against a strict schema.
- Decompression happens only on the console’s routes, which all go through one door to the backend.
The decompressing middleware also caps the decompressed size at 2 MiB and answers 413 above it, so a small gzipped body cannot expand into a memory problem. The one case splitting cannot fix is a single post that is over 8 KB even after gzip. With the current limits on post and comment length that is unlikely, but the console would report it as a failed piece rather than hang.
What this means for EverBowl
EverBowl™ learns how a dog eats, meal by meal, and the community in the Hoomanely app is where owners share what those records mean to them. A content team that can schedule a month of posts from one sheet keeps that community active between the moments owners post themselves. Splitting the upload means the size of the plan no longer decides whether it goes out.
The honest limit: this is plumbing for the people who run the community, not something EverBowl itself learns from, and a post is only as useful as what owners choose to read. EverBowl does not diagnose; the value is the record.
Conclusion
When a request fails with a bare 403 behind AWS WAF, read the terminating rule in the WAF log before changing any code. If it is SizeRestrictions_BODY, raising the inspection size will not move its 8 KB threshold, so the request has to get smaller. Gzip is the first step, but measure your compression ratio and work out where the limit returns. Then split the payload into pieces sized against that ratio, cap the total, and make a partial failure report exactly what went through. More of this work is in our software category.
FAQs
What is SizeRestrictions_BODY in AWS WAF?
SizeRestrictions_BODY is a rule in the AWS managed Core rule set (CRS) that blocks any request whose body is larger than 8 KB. It is part of the managed rule group, so its threshold cannot be changed; you can only override it to count instead of block, or keep request bodies under 8 KB.
Why does AWS WAF return 403 for a large request body?
The AWS managed Core rule set includes SizeRestrictions_BODY, which blocks request bodies over 8 KB. The block is a 403 with an empty body by default, so the client cannot tell it from any other WAF rule. The WAF log names the rule that fired.
Can I raise the 8 KB body inspection limit?
You can raise the web ACL’s body inspection size, on an Application Load Balancer up to 64 KB, at extra cost for bodies above the default. That does not change SizeRestrictions_BODY, which still blocks bodies over 8 KB. To accept larger bodies you either override that rule to count for specific paths, or keep each request under 8 KB.
Does gzip get a request past the WAF size limit?
It helps, because the WAF measures the bytes as sent. For our posts gzip reduced the body about 4 times, so 41 KB became 9.9 KB, which was still too large. Gzip raises the ceiling by the compression ratio; it does not remove it.
How large should each piece be?
Size the pieces against the compression ratio you measure on real data, with room to spare. We cap each piece at 16 KB of JSON or 40 records, which lands at 4.5 to 5 KB gzipped against an 8 KB limit.
How do I find which WAF rule blocked a request?
Turn on WAF logging and query the log group in CloudWatch Logs Insights for entries where the action is BLOCK. Read terminatingRuleId, which names the rule group, and the ruleGroupList entry, which names the rule inside it. A block on a request you expected to pass usually shows up there within a minute.