📤 File Upload Test
Upload a PDF document below. The request goes through CloudFront where AWS WAF inspects the body. The AWSManagedRulesSQLiRuleSet will flag the PDF's binary content as a SQL injection attempt.
Drop a PDF here or click to browse
PDF files only, max 5MB
Apply the Fix
Toggle the scope-down statement on the WAF. When enabled, the SQLi rule skips inspection on the upload endpoint.
🔎 Problem Summary
When a PDF is uploaded via a multipart form POST, AWS WAF's AWSManagedRulesSQLiRuleSet inspects the request body and encounters:
- The multipart boundary string (
WebKitFormBoundary...) Content-Dispositionheaders- The PDF's raw binary content
Certain byte sequences in the PDF's internal streams and metadata coincidentally match SQL injection signatures, causing the WAF to flag the request as SQL_INJECTION in the BODY.
WAF Log Findings
| Field | Value |
|---|---|
| Terminating Rule | AWSManagedRulesSQLiRuleSet |
| Rule Inside Group | SQLi_BODY |
| Action | BLOCK |
| Matched Condition | SQL_INJECTION in BODY |
Why Optimizing the PDF Sometimes Helps
Reducing or restructuring the PDF removes or reorganizes internal binary streams and metadata that happen to match SQL injection byte patterns. However, this is not a reliable fix — different PDFs contain different byte sequences and may still trigger the rule.
🛠 Solution Overview
Add a scope-down statement to the AWSManagedRulesSQLiRuleSet rule group that excludes the file upload endpoint from SQLi body inspection.
Why Scope-Down Statement?
| Approach | Pros | Cons |
|---|---|---|
| Scope-Down Statement ✅ | Most targeted fix. SQLi rules still protect all other endpoints. | Slightly more complex to configure |
| Count Mode Override | Easy to set up | Reduces protection — SQLi_BODY won't block anywhere |
| Allow Rule for URI | Simple | Skips ALL WAF rules for that path, not just SQLi |
What the Scope-Down Statement Does
It tells WAF: "Apply the SQLi rules to all requests EXCEPT those matching the upload endpoint URI."
{
"ScopeDownStatement": {
"NotStatement": {
"Statement": {
"ByteMatchStatement": {
"SearchString": "/api/file-management",
"FieldToMatch": { "UriPath": {} },
"PositionalConstraint": "STARTS_WITH",
"TextTransformations": [
{ "Priority": 0, "Type": "NONE" }
]
}
}
}
}
}
📝 Step-by-Step: Adding the Scope-Down Statement
Prerequisites
- AWS Console access with WAF permissions
- Know your Web ACL name and region (for this demo:
waf-sqli-demo,CLOUDFRONT / us-east-1) - WAF logging enabled for post-change monitoring
Console Steps
waf-sqli-demoAWSManagedRulesSQLiRuleSet → Click Edit- If a request:
doesn't match the statement (NOT) - Inspect:
URI path - Match type:
Starts with string - String to match:
/api/file-management - Text transformation:
None
✅ Verification & Testing
Test 1: Upload a Previously Blocked PDF
Test 2: Verify SQLi Protection on Other Endpoints
https://waf-lab.rohan.aws-info.net/?id=1' OR '1'='1This should still be blocked by the WAF — confirming SQLi protection is active everywhere except the upload endpoint.
Test 3: Check WAF Logs
- Upload requests are now ALLOWED
- SQLi test payloads on other paths are still BLOCKED
⏪ Rollback Procedure
If something goes wrong, here's how to revert:
waf-sqli-demoAWSManagedRulesSQLiRuleSet → EditThis restores full SQLi inspection on all endpoints, including the upload path.
Tear Down the Entire Demo
aws s3 rm s3://waf-lab-uploads-rohan --recursive aws cloudformation delete-stack --stack-name waf-sqli-demo --region us-east-1